Can't render \begin{cases}…\end{cases} using Jekyll

77 views
Skip to first unread message

Jon Froehlich

unread,
Apr 28, 2021, 10:49:48 AM4/28/21
to MathJax Users

I asked this question on the tex StackExchange and they suggested we ask here. The StackExchange post has better formatting than this email.

We use MathJax 2.7 on our course website, which is implemented in Jekyll and hosted on GitHub pages. For small, straightforward equations, MathJax works great but I've never been able to get even slightly more complicated equations to work. I've spent many hours investigating and experimenting, so I thought I'd finally ask here.

For example, the following fails to render:

$$ S_{i} = \begin{cases} X_{1} & \text{if i = 1}\\ \alpha \cdot X_{i} + (1 - \alpha) \cdot S_{i-1} & \text{if i $>$ 1} \end{cases} $$

The rendered output in the web browser is literally blank.

When I look at the rendered html, I see:

<p> <span class="MathJax_Preview" style="color: inherit; display: none;"></span> <span id="MathJax-Element-5-Frame" class="mjx-chtml MathJax_CHTML" tabindex="0" data-mathml=" <math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot; />" role="presentation" style="font-size: 113%; position: relative;"> <span id="MJXc-Node-149" class="mjx-math" aria-hidden="true"> <span id="MJXc-Node-150" class="mjx-mrow"></span> </span> <span class="MJX_Assistive_MathML" role="presentation"> <math xmlns="http://www.w3.org/1998/Math/MathML"> </math> </span> </span> <script type="math/tex" id="MathJax-Element-5">% <![CDATA[ S_{i} = \begin{cases} X_{1} & \text{if i = 1}\\ \alpha \cdot X_{i} + (1 - \alpha) \cdot S_{i-1} & \text{if i $>$ 1} \end{cases} %]]> </script> </p>

I'm not a LaTeX expert so I often write equations (or at least check them) in online editors like https://www.codecogs.com/latex/eqneditor.php or OverLeaf. They render fine there.

Thanks,

Jon

David Farmer

unread,
Apr 28, 2021, 11:24:36 AM4/28/21
to MathJax Users

There is nothing wrong with your source (actually, it is not quite
right, but that is not the issue). I pasted it into a web page,
and it worked as expected.

So, it is something with your setup.

Maybe it is the backslashes, maybe it is the curly brackets.
Maybe it is the \text or the math inside text.

If you can't post a live example, can you probe the boundary
of what works and what doesn't work?
> --
> You received this message because you are subscribed to the Google Groups "MathJax Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> mathjax-user...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mathjax-users/1c829772-0a77-4913-ad81-f012b6d0c0adn%40googlegroups.com.
>
>

David Starbuck

unread,
Apr 28, 2021, 11:32:09 AM4/28/21
to mathja...@googlegroups.com
It might be the CDATA surrounding the equation. Also, I would recode as:

\[

S_{i} =
\begin{cases}
X_{1} & \text{if } i = 1\\
\alpha \cdot X_{i} + (1 - \alpha) \cdot S_{i-1} & \text{if } i > 1
\end{cases}
\]

$$ delimiters shouldn't be used in LaTeX.

-David





--
------------------------------------------------------
David Starbuck
Programmer/System Analyst
IEEE Publications
d.sta...@ieee.org
1+ 732 465 6484 (office)
-------------------------------------------------------

Davide Cervone

unread,
Apr 28, 2021, 11:47:48 AM4/28/21
to mathja...@googlegroups.com
David is right that the CDATA is partly at fault (but it is really the percent sign that is the trouble, as I will explain below).

It looks like whatever Jekyll plugin you are using inserts the math as MathJax <script> tags (<script type="math/tex">), and the contents of that tag are the TeX expression.  Unfortunately, the plugin is inserting some additional text to mark the contents as CDATA.  This is not needed in HTML, but may be for XHTML.  Is your page XHTML (I don't know what Jekyll produces)?

In any case, the plugin probably originally inserted 

<script type="math/tex">
% <![CDATA[
... your expression...
% ]]>
</script>

That would have worked (even if it is unnecessary), because the % in TeX marks a comment, so the <![CDATA[ will be ignored, and so will the closing ]]>.

except that GitHub pages removes line breaks, and so you got

<script type="math/tex">% <![CDATA[... your expression...% ]]></script>

all on one line. That means the first % makes the entire rest of the expression into a comment, and the math is effectively commented out.  That means you get no output, since the math expression is actually empty.

This has come up before, and I proved a work-around here:


for version 2, and there is a version 3 snipped later on.  Read the whole thread as I think there may have been tweaks that the original posters may have had to do.

in any case, it is the (probably unnecessary) CDATA "comments", together with the removal of line breaks, that is causing the problem.

Davide



Davide Cervone

unread,
Apr 28, 2021, 11:49:21 AM4/28/21
to mathja...@googlegroups.com
David,

Since he is using Jekyll (probably with Kramdown), it may be that the MathJax processing only handles $$...$$ and not \[...\], since in markdown, the backslash already has a meaning, and \[...\] would interfere with that.

Davide


Jon Froehlich

unread,
Apr 28, 2021, 12:11:09 PM4/28/21
to mathja...@googlegroups.com
Davide,

This is genius! Thanks so much for your time and effort. Your solution here worked!

Here's a screenshot of the now correctly rendering equation (the MathJax version followed by a temporary .png that I was using as a placeholder, which I can now safely delete).

image.png

You mentioned that my Jekyll plugin might be the problem? I'm using the "github-pages" gem with the "pmarsceill/just-the-docs" remote theme. Maybe it's the github-pages part that is the problem?

Jon


You received this message because you are subscribed to a topic in the Google Groups "MathJax Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mathjax-users/YKftPSymXOA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mathjax-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mathjax-users/6391CD4A-E1D5-4C7E-8166-A93C42E0FA3F%40gmail.com.


--
Jon Froehlich
Associate Professor
Paul G. Allen School of Computer Science & Engineering
University of Washington

Davide Cervone

unread,
Apr 28, 2021, 12:30:54 PM4/28/21
to mathja...@googlegroups.com
You mentioned that my Jekyll plugin might be the problem? I'm using the "github-pages" gem with the "pmarsceill/just-the-docs" remote theme. Maybe it's the github-pages part that is the problem?

Whoever is inserting the CDATA comments is the problem (unless your pages really are XHTML), but I don't know the pipeline well enough to say which tool is doing it.  Or you could consider whoever is removing the line breaks to be the problem (that may be GitHub-pages).

In any case, if the pre-filter works for you, then I guess the actual culprit may not be that important.

Davide

Jon Froehlich

unread,
Apr 28, 2021, 12:34:18 PM4/28/21
to mathja...@googlegroups.com
Right. Agree.

I want to doubly thank you though because I've struggled with this for a while and just came back to the problem again this week. And now it's finally solved. Woohoo!

Jon

--
You received this message because you are subscribed to a topic in the Google Groups "MathJax Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mathjax-users/YKftPSymXOA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mathjax-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages