What is the canonical way to enable LaTex?

I used the directions here:

But they don’t work anymore.

As well, I tried:

https://geoffruddock.com/math-typesetting-in-hugo/

But at the end it says to “modify your CSS” file, which one?

Perhaps one you set here?

At any rate, there doesn’t seem to be a standard way to enable LaTex, pointers?

Thanks,
Adam

back to the roots

Add the scripts to your page template …

for the first start put it in layouts/_default/single.html

Putting either v2 or v3 script from the MathJax link above into layouts/_default/single.html causes all pages to be blank.

create a litle sample project on GitHub, so we can help

I use the scripts in may samples, if you want to see it working

PS: I trigger the script include and activation by using a {{<tex>}} shortcode

Well, my blog is pretty small but has two LaTeX-intensive pages:

I added layouts/js/mathjax.html, layouts/partials/meta.html, layouts/partials/preload.html, and layouts/shourtcodes/tex.html taken from your examples. Amusingly, it renders LaTex in my local preview pane from FrontMatter, but not on the site itself.

change site-scripts to

{{ $script := .Site.Data.webpack_assets.app }}
{{ with $script.js }}
     <script src="{{ relURL (printf "%s%s" "dist/" .) }}"></script>
{{ end }}

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({ tex2jax: {inlineMath: [["$$","$$"],["\\(","\\)"]]} })
</script>

and it works… AND changed single $ to double $$

Check .Site.Data.webpack_assets.app ! And better to use the newest MathJax version!

Good Luck!

Thank you, that worked!

Just as a note, switching $ to $$ doesn’t preserve inline behavior; here’s the script that did.

{{ $script := .Site.Data.webpack_assets.app }}
{{ with $script.js }}
<script src="{{ relURL (printf " %s%s" "dist/" .) }}"></script>
{{ end }}

<script type="text/javascript"
  src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
  </script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({ tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]} })
</script>

And to be clear, layouts/js/mathjax.html, layouts/partials/meta.html, layouts/partials/preload.html, and layouts/shortcodes/tex.html were all unnecessary … just the correct layouts/partials/site-scripts.html.

YES, i tryed to made the pages faster, embed scripts only if needed etc …
Thats work in progress :wink:

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