Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equations muddled with list markup #33

Closed
hturner opened this issue Oct 3, 2024 · 3 comments
Closed

Equations muddled with list markup #33

hturner opened this issue Oct 3, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@hturner
Copy link

hturner commented Oct 3, 2024

Equations with line breaks before operators that are valid markup for list bullets are not rendered correctly.

An example:

---
title: "Equation Bug"
output: 
  litedown::html_format:
    options:
      js_math: "katex"
knit: litedown:::knit
---

## Example

Equation with various operators that are also valid markup for list bullets

```
$$a * b - c + d$$
```
$$a * b - c + d$$ 

## Bad line breaks

Break before `*`, no preceding space
```
$$a 
* b - c + d$$
```
$$a 
* b - c + d$$ 

Break before `-`, one preceding space
```
$$a * b
 - c + d$$ 
```
$$a * b
 - c + d$$ 
 
Break before `+`, two preceding spaces
```
$$a * b - c
  + d$$ 
```
$$a * b - c
  + d$$ 
  
## Maybe bad line break

Break before `+`, four preceding spaces (not sure if junk output is hangover 
from bad examples)
```
$$a * b - c
    + d$$ 
```
$$a * b - c
    + d$$ 
    
## Good line break
    
Break after `-`, two preceding spaces
```
$$a * b - 
  c + d$$
```
$$a * b - 
  c + d$$

Renders as

image

Notes:

  • I get the same results with KaTeX and MathJax.
  • All equations render correctly with rmarkdown::html_document.
@yihui yihui added the bug Something isn't working label Oct 3, 2024
@yihui
Copy link
Owner

yihui commented Oct 3, 2024

This is indeed a bug, and due to one of the two aspects that I dislike most about the commonmark spec (i.e., no requiring empty lines around block-level elements). The author of Pandoc also hates it: https://github.com/jgm/djot?tab=readme-ov-file#rationale (point 7). I think this is absolutely a design mistake, but I can't change the spec. I'll see if I can figure out a workaround. Thanks for the report!

@yihui yihui closed this as completed in c5d40d1 Oct 5, 2024
@yihui
Copy link
Owner

yihui commented Oct 5, 2024

Fixed now. However, please note that the current syntax for $$ $$ expressions requires that there are no trailing spaces after the closing $$. Your examples have spaces after d$$, which must be removed.

image

yihui added a commit to yihui/xfun that referenced this issue Oct 6, 2024
this was intended for yihui/litedown#33 but I no longer need it sinced I figured out another workaround
@hturner
Copy link
Author

hturner commented Oct 7, 2024

Brilliant, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants