mathjax / MathJax

Beautiful and accessible math in all browsers
http://www.mathjax.org/
Apache License 2.0
10.21k stars 1.16k forks source link

Github page fails to render \begin{align} environment #2274

Closed mufan-li closed 4 years ago

mufan-li commented 4 years ago

See equation (4) on the published page here https://mufan-li.github.io/auffinger_chen/

It seems that all equations are being rendered correctly except for when I use the align environment like this $$ \begin{align} ... \end{align} $$

On the other hand, when I render the page locally, I see this equation rendered properly. Screen Shot 2019-12-23 at 5 27 31 PM

You can find the website repository here https://github.com/mufan-li/mufan-li.github.io/blob/master/_posts/2019-02-13-auffinger_chen.md

Please advise on how I might approach this problem.

dpvc commented 4 years ago

Your expression begins with a percent sign (%) and contains no newlines, so it is all treated as a comment (the percent sign is the comment character). Perhaps you meant to put a newline after the % <![CDATA[ and before the \begin{align}? You may have had newlines in your original file, and they were removed by the content-management system, as it seems there are no newlines in the document at all (it seems to be one long line). That could account for why a local copy works, but the web version doesn't.

dpvc commented 4 years ago

PS, you are using version 2.7.1 of MathJax, which is quite old at this point (the current version 2 version is 2.7.7). You might consider updating to use that.

mufan-li commented 4 years ago

Thanks the quick reply. It's essentially exactly what you expected, but I will add some more details for others who will possibly run into the same problem.

To start, it seems that I should be using \begin{align} without the $$ environment. Whenever I use \begin{align} within the $$ environment, I get this % <![CDATA[ in the final HTML code. Now this % will comment out everything else after it, which caused the problem.

To replicate the same problem, here's my markdown code

$$
\begin{align}
    \Phi(0,x) = \max_{u \in \mathcal{D}} \bigg[
        \mathbb{E} & \Phi\left(1, 
        x + \int_0^1 \sigma^2(s) \, \zeta(s) \, u_s \, ds
        + \int_0^1 \sigma(s) \, dW_s
    \right) \\
        &- \frac{1}{2} \int_0^1 \sigma^2(s) \, \zeta(s) \,
        \mathbb{E} u_s^2  \, ds
    \bigg].
\end{align}
$$

In the local version of my site, the HTML code kept the line structure, which will run properly

<script type="math/tex; mode=display">% <![CDATA[
\begin{align}
    \Phi(0,x) = \max_{u \in \mathcal{D}} \bigg[
        \mathbb{E} & \Phi\left(1, 
        x + \int_0^1 \sigma^2(s) \, \zeta(s) \, u_s \, ds
        + \int_0^1 \sigma(s) \, dW_s
    \right) \\
        &- \frac{1}{2} \int_0^1 \sigma^2(s) \, \zeta(s) \,
        \mathbb{E} u_s^2  \, ds
    \bigg].
\end{align} %]]></script>

However, in the Github page version, all the lines collapsed into one large line, which means the rest of the equation got commented out.

% <![CDATA[ \begin{gather} \Phi(0,x) = \max_{u \in \mathcal{D}} \bigg[ \mathbb{E} & \Phi\left(1, x + \int_0^1 \sigma^2(s) \, \zeta(s) \, u_s \, ds + \int_0^1 \sigma(s) \, dW_s \right) \\ &- \frac{1}{2} \int_0^1 \sigma^2(s) \, \zeta(s) \, \mathbb{E} u_s^2 \, ds \bigg]. \end{gather} %]]>

Removing the $$ environment essentially fixes the rendering problem, however there is one additional change I need to make. In this new environment of HTML and mathjax, I need to escape the \ symbol through both parts, which means \\\\ will only lead to \ in the HTML output. And to get a line break in Latex, I need to type \ 8 times. This leads to the following markdown code that works.

\begin{align}
    \Phi(0,x) = \max_{u \in \mathcal{D}} \bigg[
        \mathbb{E} & \Phi\left(1, 
        x + \int_0^1 \sigma^2(s) \, \zeta(s) \, u_s \, ds
        + \int_0^1 \sigma(s) \, dW_s
    \right) \\\\\\\\
        &- \frac{1}{2} \int_0^1 \sigma^2(s) \, \zeta(s) \,
        \mathbb{E} u_s^2  \, ds
    \bigg].
\end{align}
RylanSchaeffer commented 4 years ago

This is gnarly. Are so many slashes really needed?

richard-warren commented 4 years ago

It appears that the problem has to do with the way the html is formatted for AcademicPages. There are no line breaks in the html, which causes the CDATA flag to effectively comment out the \being{aligned} portions of code. I opened up a new issue to try and sort this out.

richard-warren commented 4 years ago

Problem solved! AcademicPages uses html compression that screws up multi-line equations. See the solution here.

misrab commented 1 year ago

Ditto for my hugo website, needed to use \\\\, in case this helps anyone else. Thanks