Wowchemy-hugo-modules: Latex support problem

Created on 11 Apr 2017  ·  4Comments  ·  Source: wowchemy/wowchemy-hugo-modules

When I try writing the following equation

$$\text{softmax}(z)_j = \frac{e^{z_j}}{\sum_{i=0}^{\text{dim}(z)}e^{z_i}}$$ 

I cannot manage to get the output generated. By removing different parts of the equations I eventually realized the problem happens at \sum_{i=0}, more specifically at the underscore part. So, the following works.

$$\text{softmax}(z)_j = \frac{e^{z_j}}{\sum_i^{\text{dim}(z)}e^{z_i}}$$ 

I am not sure if this is a template problem, but since I do not know what Latex-generating 3rd-party tool Hugo uses, perhaps someone else could report upstream.

Most helpful comment

I think I finally figured it out. According to Hugo Markdown documentation:

Issues with Markdown
After enabling MathJax, any math entered in-between proper markers (see documentation) will be processed and typeset in the web page. One issue that comes up, however, with Markdown is that the underscore character (_) is interpreted by Markdown as a way to wrap text in emph blocks while LaTeX (MathJax) interprets the underscore as a way to create a subscript. This “double speak” of the underscore can result in some unexpected and unwanted behavior.
Solution
There are multiple ways to remedy this problem. One solution is to simply escape each underscore in your math code by entering _ instead of _. This can become quite tedious if the equations you are entering are full of subscripts.

This solved this issue, sorry for not checking the docs earlier.

All 4 comments

Good to hear you got it working and thanks for posting the fix, I'll report it upstream.

@eduardohenriquearnold Are you trying to add the LaTeX code to a parameter in the +++ preamble at the top of content files? Or are you trying to add it to the body of your content?

If the former, then you will need to escape some special TOML characters using backslash (\). If the latter, then it may possibly be a bug with the LaTeX parser, MathJAX (https://mathjax.org).

@chasgames It is not fixed since it does not render the desired output. I just can make it work by removing the i=0 part underneath the sum.

@gcushen It is the former case, so I believe it is a MathJax integration bug. But when I try using it on their live (https://www.mathjax.org/) it works fine. Could anyone else confirm this problem?

I think I finally figured it out. According to Hugo Markdown documentation:

Issues with Markdown
After enabling MathJax, any math entered in-between proper markers (see documentation) will be processed and typeset in the web page. One issue that comes up, however, with Markdown is that the underscore character (_) is interpreted by Markdown as a way to wrap text in emph blocks while LaTeX (MathJax) interprets the underscore as a way to create a subscript. This “double speak” of the underscore can result in some unexpected and unwanted behavior.
Solution
There are multiple ways to remedy this problem. One solution is to simply escape each underscore in your math code by entering _ instead of _. This can become quite tedious if the equations you are entering are full of subscripts.

This solved this issue, sorry for not checking the docs earlier.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JOduMonT picture JOduMonT  ·  4Comments

chris-prener picture chris-prener  ·  3Comments

saadjavaid picture saadjavaid  ·  3Comments

HughP picture HughP  ·  4Comments

somnathrakshit picture somnathrakshit  ·  3Comments