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

LaTeX reader sometimes omits expressions containing square brackets [ #7512

Open
nilaykumar opened this issue Aug 20, 2021 · 5 comments
Open

Comments

@nilaykumar
Copy link

In LaTeX, I have an expression [d,\delta]=0 that I've placed in an equation* environment. Upon converting to HTML, all I see is "=0" (see screenshot below), even if we were to get rid of MathJax. When placed in the \[ \] environment, however, the expression converts correctly.

The following is a working example:

\documentclass{article}
\begin{document}
\noindent With the arguments
\begin{verbatim}
pandoc test.tex -f latex -t html --mathjax -s -o out.html
\end{verbatim}
the code
\begin{verbatim}
\begin{equation*}
  [d,\delta]=0.
\end{equation*}
\end{verbatim}
results in
\begin{equation*}
  [d,\delta]=0.
\end{equation*}
but the code
\begin{verbatim}
\[ [d,\delta] = 0\]
\end{verbatim}
results in
\[ [d,\delta]=0.\]
\end{document}

resulting in
Screen Shot 2021-08-19 at 8 35 57 PM

Interestingly, throwing a character a[d,\delta]=0 in front of the opening square bracket in the equation* environment solves the problem. Is this a bug or a feature that I should work around? Thanks!

Version: I'm running pandoc version 2.14.1 on macOS Big Sur 11.4 on a Macbook Air (M1 2020).

@nilaykumar nilaykumar added the bug label Aug 20, 2021
@jgm
Copy link
Owner

jgm commented Aug 20, 2021

The issue is shown a bit more clearly by:

% pandoc --mathjax -t html  -f latex
\begin{equation*}
[d,\delta]=0.
\end{equation*}
^D
<p><span class="math display">\[=0.\]</span></p>

@jgm
Copy link
Owner

jgm commented Aug 20, 2021

I think what's happening here is that there's some code in the LaTeX reader's generic environment parser that skips over bracketed optional arguments that some environments have. This is obviously not wanted for the equation* environment! Escaping the square brackets should be a workaround.

@jgm
Copy link
Owner

jgm commented Aug 20, 2021

More workarounds:

{}[d,\delta]=0

{[d,\delta]}=0

@jgm jgm changed the title LaTeX to HTML (with MathJax) sometimes omits expressions containing square brackets [ LaTeX reader sometimes omits expressions containing square brackets [ Aug 20, 2021
@jgm
Copy link
Owner

jgm commented Aug 20, 2021

I've modified the title because this isn't specific to HTML output or mathjax.

% pandoc -t native -f latex
\begin{equation*}
[d,\delta]=0.
\end{equation*}
^D
[Para [Math DisplayMath "=0."]]

@fedeinthemix
Copy link

I would like to provide another example where this happens: In the following table the first entry in the second row (starts with [) is dropped by pandoc while it's present if the file is processed with LaTeX.

\documentclass{article}
\begin{document}
\begin{table}[htb]
  \centering
  \begin{tabular}{|c|c|c|c|c|c|c|}
       $W$      & $N_S$ & $L$  & $L$  & rel. err. & $L$  & rel. err. \\[0mm]
       [$\mu$m] & [-]   & [nH] & [nH] & [\%]      & [nH] & [\%]\\
    \hline\hline
    1.00 & 32 & 0.2871 & 0.293 & 2.06 & 0.294 & 2.40 \\
    2.00 & 32 & 0.2616 & 0.266 & 1.68 & 0.269 & 2.83 \\
  \end{tabular}
\end{table}
\end{document}

Note that the commands \\ and \\* do have an optional argument that in the example is used.

ultronozm added a commit to ultronozm/math that referenced this issue Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants