Mathjax doesn't work from some formula

I have been setup mathjax to help me render math formula.And now when i type a formula like this

$\alpha_t = \prod_{i=1}^t \alpha_i$,
Hugo server render correctly, but when i type formula like this
$\bar{\alpha}_t = \prod_{i=1}^t \alpha_i$

, hugo doesn’t convert this text to math formula. Does anyone have the same problem, it’s really strange, hope anyone can discuss with me, thanks a lot😊

This is happening because the markdown is rendered to HTML before mathjax renders the math.

Example

markdown

$\bar{\alpha}_t = \prod_{i=1}^t \alpha_i$

rendered

<p>$\bar{\alpha}<em>t = \prod</em>{i=1}^t \alpha_i$</p>

See the em element? That’s due to the underscores in the markdown.

fix (escape first underscore)

$\bar{\alpha}\_t = \prod_{i=1}^t \alpha_i$

Alternative

To prevent Hugo from rendering to HTML before Mathjax renders the math, use a shortcode or code block render hook. Here’s a small test site that demonstrates both:

git clone --single-branch -b hugo-forum-topic-41107 https://github.com/jmooring/hugo-testing hugo-forum-topic-41107
cd hugo-forum-topic-41107
hugo server
1 Like

Thanks for your answer, it works for me :grinning:
and debugging the rendering Html code way is really useful, I solved similar problems this way.
And here is my summary, hope is useful for others:

replace _{ to \_{
replace }_ to }_\
replace \\ to \\\

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.