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

Support for LaTeX environments in markdown to html #4640

Closed
rreece opened this issue May 9, 2018 · 2 comments
Closed

Support for LaTeX environments in markdown to html #4640

rreece opened this issue May 9, 2018 · 2 comments

Comments

@rreece
Copy link

rreece commented May 9, 2018

Similar to the issue reported here: #1938

I am having trouble getting both html and latex (to pdf) to render plain math latex environments.
For html to work, equation environments have to be nested inside $...$ but then that doesn't work for latex.

I think this issue was fixed in Pandoc 1.XX?, but I see the issue returning when I use 2.2.

Details below. Thanks for your help, and thanks for Pandoc!

--
Ryan


The contents of the example markdown document I am using are equivalent to

https://github.com/rreece/markdown-memo/blob/master/05-math.md

Locally, I have saved it as min.md.

cat min.md 

shows

Mathematical expressions
===============================================================================


Typesetting math
-------------------------------------------------------------------------------

You can do latex inline like this:

    Euler's formula is remarkable: $e^{i\pi} + 1 = 0$.

Euler's formula is remarkable: $e^{i\pi} + 1 = 0$.

You can use `$$` to make an equation block like this:

    $$ \frac{\partial \rho}{\partial t} + \nabla \cdot \vec{j} = 0 \,. \label{eq:continuity} $$

$$ \frac{\partial \rho}{\partial t} + \nabla \cdot \vec{j} = 0 \,. \label{eq:continuity} $$

The latex equation environment can be used directly.
Stokes' theorem is pretty cool:

    \begin{equation} \label{eq:stokes}
        \int_{\partial\Omega} \omega = \int_{\Omega} \mathrm{d}\omega \,.
    \end{equation}

\begin{equation} \label{eq:stokes}
    \int_{\partial\Omega} \omega = \int_{\Omega} \mathrm{d}\omega \,.
\end{equation}

You can also refer to labeled equations, such as [@eq:stokes],
with the syntax:

    ... such as [@eq:stokes],

The `align` environment can also be used.
Maxwell's equations, [@eq:maxwell], are also tough to beat:

    \begin{align}
        \nabla \cdot  \vec{E} &= \rho \nonumber \\
        \nabla \cdot  \vec{B} &= 0    \nonumber \\
        \nabla \times \vec{E} &= - \frac{\partial \vec{B}}{\partial t} \label{eq:maxwell} \\
        \nabla \times \vec{B} &= \vec{j} + \frac{\partial \vec{E}}{\partial t} \nonumber \,.
    \end{align}

\begin{align}
    \nabla \cdot  \vec{E} &= \rho \nonumber \\
    \nabla \cdot  \vec{B} &= 0    \nonumber \\
    \nabla \times \vec{E} &= - \frac{\partial \vec{B}}{\partial t} \label{eq:maxwell} \\
    \nabla \times \vec{B} &= \vec{j} + \frac{\partial \vec{E}}{\partial t} \nonumber \,.
\end{align}


Mathjax
-------------------------------------------------------------------------------

When doing md $\rightarrow$ tex $\rightarrow$ pdf, LaTeX takes care of the math,
but to render the math in html, we use [MathJax](https://www.mathjax.org/).
Our html template includes the following code
to ask MathJax to render it and number the equations:

    <!--- MathJax stuff -->
    <script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <script type="text/x-mathjax-config">
        MathJax.Hub.Config({ TeX: { equationNumbers: {autoNumber: "all"} } });
    </script>

Please note there are "naked" latex environments: \begin{equation}... and \begin{align}.
Things were working fine with an older version of pandoc.
Then if I switch to 2.2:

brew switch pandoc 2.2
Cleaning /usr/local/Cellar/pandoc/1.19.2.4
Cleaning /usr/local/Cellar/pandoc/2.2
5 links created for /usr/local/Cellar/pandoc/2.2

And then run pandoc -t html --standalone --mathjax min.md, I get:

[WARNING] Could not convert TeX math ' \frac{\partial \rho}{\partial t} + \nabla \cdot \vec{j} = 0 \,. \label{eq:continuity} ', rendering as TeX
[WARNING] This document format requires a nonempty <title> element.
  Please specify either 'title' or 'pagetitle' in the metadata.
  Falling back to 'min'
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
  <meta charset="utf-8" />
  <meta name="generator" content="pandoc" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
  <title>min</title>
  <style type="text/css">
      code{white-space: pre-wrap;}
      span.smallcaps{font-variant: small-caps;}
      span.underline{text-decoration: underline;}
      div.column{display: inline-block; vertical-align: top; width: 50%;}
  </style>
  <!--[if lt IE 9]>
    <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
  <![endif]-->
</head>
<body>
<h1 id="mathematical-expressions">Mathematical expressions</h1>
<h2 id="typesetting-math">Typesetting math</h2>
<p>You can do latex inline like this:</p>
<pre><code>Euler&#39;s formula is remarkable: $e^{i\pi} + 1 = 0$.</code></pre>
<p>Euler’s formula is remarkable: <span class="math inline"><em>e</em><sup><em>i</em><em>π</em></sup> + 1 = 0</span>.</p>
<p>You can use <code>$$</code> to make an equation block like this:</p>
<pre><code>$$ \frac{\partial \rho}{\partial t} + \nabla \cdot \vec{j} = 0 \,. \label{eq:continuity} $$</code></pre>
<p><br /><span class="math display">$$ \frac{\partial \rho}{\partial t} + \nabla \cdot \vec{j} = 0 \,. \label{eq:continuity} $$</span><br /></p>
<p>The latex equation environment can be used directly. Stokes’ theorem is pretty cool:</p>
<pre><code>\begin{equation} \label{eq:stokes}
    \int_{\partial\Omega} \omega = \int_{\Omega} \mathrm{d}\omega \,.
\end{equation}</code></pre>

<p>You can also refer to labeled equations, such as <span class="citation" data-cites="eq:stokes">[@eq:stokes]</span>, with the syntax:</p>
<pre><code>... such as [@eq:stokes],</code></pre>
<p>The <code>align</code> environment can also be used. Maxwell’s equations, <span class="citation" data-cites="eq:maxwell">[@eq:maxwell]</span>, are also tough to beat:</p>
<pre><code>\begin{align}
    \nabla \cdot  \vec{E} &amp;= \rho \nonumber \\
    \nabla \cdot  \vec{B} &amp;= 0    \nonumber \\
    \nabla \times \vec{E} &amp;= - \frac{\partial \vec{B}}{\partial t} \label{eq:maxwell} \\
    \nabla \times \vec{B} &amp;= \vec{j} + \frac{\partial \vec{E}}{\partial t} \nonumber \,.
\end{align}</code></pre>

<h2 id="mathjax">Mathjax</h2>
<p>When doing md <span class="math inline">→</span> tex <span class="math inline">→</span> pdf, LaTeX takes care of the math, but to render the math in html, we use <a href="https://www.mathjax.org/">MathJax</a>. Our html template includes the following code to ask MathJax to render it and number the equations:</p>
<pre><code>&lt;!--- MathJax stuff --&gt;
&lt;script type=&quot;text/javascript&quot; async src=&quot;https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS-MML_HTMLorMML&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
    MathJax.Hub.Config({ TeX: { equationNumbers: {autoNumber: &quot;all&quot;} } });
&lt;/script&gt;</code></pre>
</body>
</html>

Note that mathjax output of the naked latex environments is missing!

If I switch back to pandoc 1.19.2.4, everything is ok again.

brew switch pandoc 1.19.2.4
Cleaning /usr/local/Cellar/pandoc/1.19.2.4
Cleaning /usr/local/Cellar/pandoc/2.2
5 links created for /usr/local/Cellar/pandoc/1.19.2.4

The naked latex is passed to the html.
Running pandoc -t html --standalone --mathjax min.md, I get:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <meta name="generator" content="pandoc" />
  <title></title>
  <style type="text/css">code{white-space: pre;}</style>
  <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML-full" type="text/javascript"></script>
</head>
<body>
<h1 id="mathematical-expressions">Mathematical expressions</h1>
<h2 id="typesetting-math">Typesetting math</h2>
<p>You can do latex inline like this:</p>
<pre><code>Euler&#39;s formula is remarkable: $e^{i\pi} + 1 = 0$.</code></pre>
<p>Euler's formula is remarkable: <span class="math inline">\(e^{i\pi} + 1 = 0\)</span>.</p>
<p>You can use <code>$$</code> to make an equation block like this:</p>
<pre><code>$$ \frac{\partial \rho}{\partial t} + \nabla \cdot \vec{j} = 0 \,. \label{eq:continuity} $$</code></pre>
<p><span class="math display">\[ \frac{\partial \rho}{\partial t} + \nabla \cdot \vec{j} = 0 \,. \label{eq:continuity} \]</span></p>
<p>The latex equation environment can be used directly. Stokes' theorem is pretty cool:</p>
<pre><code>\begin{equation} \label{eq:stokes}
    \int_{\partial\Omega} \omega = \int_{\Omega} \mathrm{d}\omega \,.
\end{equation}</code></pre>
<span class="math display">\[\begin{equation} \label{eq:stokes}
    \int_{\partial\Omega} \omega = \int_{\Omega} \mathrm{d}\omega \,.
\end{equation}\]</span>
<p>You can also refer to labeled equations, such as <span class="citation">[@eq:stokes]</span>, with the syntax:</p>
<pre><code>... such as [@eq:stokes],</code></pre>
<p>The <code>align</code> environment can also be used. Maxwell's equations, <span class="citation">[@eq:maxwell]</span>, are also tough to beat:</p>
<pre><code>\begin{align}
    \nabla \cdot  \vec{E} &amp;= \rho \nonumber \\
    \nabla \cdot  \vec{B} &amp;= 0    \nonumber \\
    \nabla \times \vec{E} &amp;= - \frac{\partial \vec{B}}{\partial t} \label{eq:maxwell} \\
    \nabla \times \vec{B} &amp;= \vec{j} + \frac{\partial \vec{E}}{\partial t} \nonumber \,.
\end{align}</code></pre>
<span class="math display">\[\begin{align}
    \nabla \cdot  \vec{E} &amp;= \rho \nonumber \\
    \nabla \cdot  \vec{B} &amp;= 0    \nonumber \\
    \nabla \times \vec{E} &amp;= - \frac{\partial \vec{B}}{\partial t} \label{eq:maxwell} \\
    \nabla \times \vec{B} &amp;= \vec{j} + \frac{\partial \vec{E}}{\partial t} \nonumber \,.
\end{align}\]</span>
<h2 id="mathjax">Mathjax</h2>
<p>When doing md <span class="math inline">\(\rightarrow\)</span> tex <span class="math inline">\(\rightarrow\)</span> pdf, LaTeX takes care of the math, but to render the math in html, we use <a href="https://www.mathjax.org/">MathJax</a>. Our html template includes the following code to ask MathJax to render it and number the equations:</p>
<pre><code>&lt;!--- MathJax stuff --&gt;
&lt;script type=&quot;text/javascript&quot; async src=&quot;https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS-MML_HTMLorMML&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
    MathJax.Hub.Config({ TeX: { equationNumbers: {autoNumber: &quot;all&quot;} } });
&lt;/script&gt;</code></pre>
</body>
</html>

Note that you can now see the <span class="math display"> stuff for each latex environment.

@jgm
Copy link
Owner

jgm commented May 10, 2018

I think this is the same as #4639 which I just fixed today.

@jgm jgm closed this as completed May 10, 2018
@rreece
Copy link
Author

rreece commented May 10, 2018

@jgm, sounds like it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants