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

Display math $$ delimiter showing up in rendered HTML output #1181

Open
6 tasks done
asmaier opened this issue Jun 19, 2022 · 8 comments
Open
6 tasks done

Display math $$ delimiter showing up in rendered HTML output #1181

asmaier opened this issue Jun 19, 2022 · 8 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@asmaier
Copy link

@asmaier asmaier commented Jun 19, 2022

Bug description

Here is a (pandoc) markdown test file test.qmd

# Test

$$\begin{equation}
1+2
\end{equation}$$
Some text
$$\begin{equation}
3+4
\end{equation}$$
more text
$$\begin{equation}
5+6
\end{equation}$$
even more text
$$\begin{equation}
7+8
\end{equation}$$
the end.

When rendering as html with pandoc

pandoc -t html5 --mathjax -s -o test-pandoc.html test.qmd

it renders correctly.
Bildschirmfoto 2022-06-19 um 23 04 07
However when rendering the file to html with quarto

quarto render test.qmd

$$ are showing up in the text of the html file
Bildschirmfoto 2022-06-19 um 23 04 23

This happens with quarto 0.9.592 and pandoc 2.18 on Mac OS X 10.15.7 .

Checklist

  • formatted your issue so it is easier for us to read?
  • included a minimal, self-contained, and reproducible example?
  • documented the quarto version you're running, by providing the output produced by quarto check in a terminal in your issue?
  • documented the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
  • documented which operating system you're running? If on Linux, please provide the specific distribution as well.
  • upgraded to the latest version, including your versions of R, the RStudio IDE, and relevant R packages?
@asmaier asmaier added the bug Something isn't working label Jun 19, 2022
@cscheid
Copy link
Collaborator

@cscheid cscheid commented Jun 20, 2022

Hi - in quarto, you need the $$ delimiters to be in a line by themselves, because they're used as block delimiters in other parts of the pipeline. The following works:

# Test

$$
\begin{equation}
1+2
\end{equation}
$$

Some text

$$
\begin{equation}
3+4
\end{equation}
$$

more text

$$
\begin{equation}
5+6
\end{equation}
$$

even more text

$$
\begin{equation}
7+8
\end{equation}
$$

the end.

@jjallaire
Copy link
Collaborator

@jjallaire jjallaire commented Jun 20, 2022

@cscheid I think it would be best if don't introduce special markdown syntax constraints that apply only when using Quarto. So we should ultimately liberalize our parsing rules to handle $$\begin{equation} (however I'm fine if we defer that to post v1.0 if we consider the fix to be risky). Let me know what you think.

@cscheid
Copy link
Collaborator

@cscheid cscheid commented Jun 20, 2022

I'm ok with fixing that, but do note that even in pandoc this doesn't totally work across formats:

$ pandoc -t pdf -s -o test-pandoc.pdf test.md
Error producing PDF.
! LaTeX Error: Bad math environment delimiter.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...

l.58 \[\begin{equation}

@cscheid cscheid self-assigned this Jun 20, 2022
@jjallaire
Copy link
Collaborator

@jjallaire jjallaire commented Jun 20, 2022

If that's the case then we definitely shouldn't support it (i.e. if it only works in HTML then we shouldn't encourage it)

@asmaier
Copy link
Author

@asmaier asmaier commented Jun 20, 2022

Hi - in quarto, you need the $$ delimiters to be in a line by themselves, because they're used as block delimiters in other parts of the pipeline.

Unfortunately this is not documented here: https://quarto.org/docs/authoring/markdown-basics.html#equations

But apart from that, originally my markdown file was created by converting with pandoc from latex to markdown. So the default markdown writer of pandoc is using $$ delimiters as shown im the example test.qmd above. So if you insist on Quarto needing $$ on a single line it means people cannot use the default markdown writer of pandoc to produce files which are compatible with Quarto. Of course nowadays you can easily write a lua filter or custom writer in pandoc to solve the issue, but it is still an annoyance for people who might want to convert their files to pandoc markdown for use with Quarto.

@cscheid
Copy link
Collaborator

@cscheid cscheid commented Jun 20, 2022

But apart from that, originally my markdown file was created by converting with pandoc from latex to markdown.

Huh, this is interesting. So you have a file which pdflatex builds correctly, but if you convert from latex to markdown with pandoc, then pandoc fails to convert from markdown to pdf? I don't know what are the guarantees that pandoc provides with respect to formats and roundtrips, but I wonder if this is an issue with pandoc.

@jjallaire jjallaire added this to the Future milestone Jun 21, 2022
@asmaier
Copy link
Author

@asmaier asmaier commented Jun 21, 2022

So you have a file which pdflatex builds correctly, but if you convert from latex to markdown with pandoc, then pandoc fails to convert from markdown to pdf?

That seemed odd to me and I investigated the issue a bit more. It turns out my example given in the bug description above is not an example that would be created by pandoc when converting from latex. I created what I thought is a minimal example, but in fact it is not quite correct.

When converting from latex

\begin{equation}
1+2
\end{equation} 
Some text 
\begin{equation}
3+4
\end{equation} 

this will be converted by pandoc to

$$1+2$$
Some text
$$3+4$$

So my example in the bug description is misleading and cannot be converted by pandoc to pdf, as you have shown.

However when starting from a latex file like

\begin{align}
1+2
\end{align} 
Some text 
\begin{align}
3+4
\end{align} 

this will be converted by pandoc --wrap=preserve -t markdown -s -o test-mini.md test-mini.tex to

$$\begin{aligned}
1+2\end{aligned}$$
Some text
$$\begin{aligned}
3+4\end{aligned}$$

because apparently pandoc is treating the align environment different from the equation environment. It is converting an align environment into $$\begin{aligned}...\end{aligned}$$ . The latter file however can be converted by pandoc into html and pdf without problems. But when rendering this file with quarto render test-mini.md the HTML will show $$ in the text:

Bildschirmfoto 2022-06-21 um 22 12 28

@rressler
Copy link

@rressler rressler commented Jun 24, 2022

Quarto does Not seem to need the $$ to be on a separate line. See https://community.rstudio.com/t/inconsistent-rendering-of-display-math-between-rstudio-and-quarto-render/140669.
I was able to "fix" the issue by getting rid of every line break between the beginning and ending $$. That makes for some painful reading of the LaTeX but the document at least now works. I don't know if it is Quarto or it happens later in the process. However the fact that copied and pasted code will work, then not work, then work again seems strange (as in the reference image.

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

4 participants