Hello, hope that question from non-technical folks is tolerated here. I am trying to eliminate the use of JS on a simple website I have setup using Hugo and followed steps in this hugo documention to use transform.ToMath however, the equations are not rendered. I am using hugo v0.133.0
Here’s the config.toml:
Sorry, but that’s not the full context.
Please show the full site/code you are using. Ideally, you create a repo that shows your current approach. Then share this repo with us, e.g. on GitHub or so. This way, we can effectively help you and hopefully solve your problems within short time. Thanks for providing us with your minimal repo!
Did you follow these steps too? To actually render equations you need to load a JS file on those pages. After you got MathML of any kind running with the steps in THIS documentation then you can try to change the passthrough renderer.
especially here I miss some details. Isn’t it that you get the following error:
Error: error building site: render: failed to render pages:
render of "home" failed: "C:\_repos\github\clone\topic-52152\layouts\_default\home.html:3:6":
execute of template failed: template: _default/home.html:3:6: executing "main" at <.Content>:
error calling Content: "C:\_repos\github\clone\topic-52152\content\_index.md:1:1":
execute of template failed: template: _default/_markup/render-passthrough.html:1:0:
executing "_default/_markup/render-passthrough.html" at <_html_template_htmlescaper>:
error calling _html_template_htmlescaper: not a function
Keep in mind, that the toMath is marked as “experimental”
looks like this is called if the displayMode option is set:
If you omit these $opt it seems to work for both block and inline
The hook becomes just:
{{ transform.ToMath .Inner }}
and then this is rendered properly:
Markdown equations
inline: $ c = \pm\sqrt{a^2 + b^2} $ is fine
block:
$$ c = \pm\sqrt{a^2 + b^2} $$
Yours also work
$$\frac 1 2$$, $\frac 1 2$, \(\frac 1 2\) and \[\frac 1 2\]
Which does not mean that it’s not working nor that it’s going away (it’s just allowing me to have a slightly better conscience I need to change the API slightly).
I think hhe mystic “calling _html_template_htmlescaper: not a function” error is masking the “real error” (I know what happens there and we/I should fix the error handling/reporting).
That said, if you found a bug, please create a GitHub issue and I will look at it, but we have pretty good tests for this feature.
git clone --single-branch -b hugo-forum-topic-52152 https://github.com/jmooring/hugo-testing hugo-forum-topic-52152
cd hugo-forum-topic-52152
hugo server
Files of interest:
hugo.toml
layouts/_default/_markup/render-passthrough.html
layouts/_default/baseof.html (lines 8-12)
@davidsneighbour The transform.ToMath template function does not require any JavaScript. The transformation is performed during the build, not on the client side.
If you set the “output” option to html or htmlAndMathml, you need to include the KaTeX CSS file. That’s what we do in the example site above.
Using html or htmlAndMathml output looks better than mathml. I recommend using htmlAndMathml for accessibility.
title = 'transform.toMath'
date = 2023-01-01T08:00:00-07:00
draft = false
+++
## Markdown Equations
inline: $ c = \pm\sqrt{a^2 + b^2} $ is fine
block:
$$ c = \pm\sqrt{a^2 + b^2} $$
These also work
$$\frac 1 2$$, $\frac 1 2$, \(\frac 1 2\) and \[\frac 1 2\]
Hello ^^
WOW, that’s amazing, it works out of the box for me!
I’ll be comparing codes from my site and your example trying to figure out where I messed up, and I’ll comment about it here once I figure out. Thanks a lot for the files.
@irkode Sorry, I can only guess that it has something to do with you hugo version maybe. I’m using hugo v0.133.0 windows/amd64. Also I tried omitting options like you mentioned but I’m getting same results.
@irkode seems like latex syntax unsupported by pandoc is also able to cause that same error. For example, \^Z should be equivalent to \hat Z but is unsupported by pandoc. Just putting this out here in case it helps.
PS I got everything working and eventually figured that the code provided in the documentation also works, it seems that I had spelled a few more things wrong so, my bad. Let’s hope that this thread remains useful to someone anyway. Especially nice to compare a working example