hugo-book icon indicating copy to clipboard operation
hugo-book copied to clipboard

inline math rendering with $

Open TheChymera opened this issue 2 years ago • 4 comments

Would improve inline math support in line with https://github.com/alex-shpak/hugo-book/issues/117#issuecomment-573690333 and https://stackoverflow.com/questions/27375252/how-can-i-render-all-inline-formulas-in-with-katex .

$ is easier to type and read and therefore much more comfy. Also, it seems very common; and batch converting between \\( and $ is not that straightforward since in the former case the delimiters are not identical — so it makes sense to support both rather than “just change it”.

Tested and works.

TheChymera avatar Apr 16 '22 22:04 TheChymera

Hi! I rememeber when adding KaTeX looking at it, and decided to keep default setting. Can't recall no why 🤔 there was some compatability issue. I will think about it.

alex-shpak avatar Apr 18 '22 14:04 alex-shpak

Perhaps it is better to parameterize renderMathInElement as in future I might accidentaly overwrite auto-render.min.js file when updating katex.

ref: https://katex.org/docs/autorender.html#usage

alex-shpak avatar Apr 18 '22 14:04 alex-shpak

auto-render.min.js

Yeah, I got the feeling that that file is probably not manually written ^^

Perhaps it is better to parameterize renderMathInElement

not sure I understand how :-/

TheChymera avatar Apr 21 '22 03:04 TheChymera

https://github.com/alex-shpak/hugo-book/blob/master/layouts/shortcodes/katex.html#L5 it's here, function called renderMathInElement

alex-shpak avatar Apr 26 '22 11:04 alex-shpak

Do I have to use shortcodes to use katex in markdowns? Is there a way where I just use regular $ and \[ etc in the .md and it just works?

Edit: nevermind. The default works for $$ and \\[ blocks. To add inline $ and \\( support, edit themes/hugo-book/layouts/shortcodes/katex.html so that it's

<script defer src="{{ "katex/auto-render.min.js" | relURL }}" onload="renderMathInElement(document.body, {
  delimiters: [
      {left: '$$', right: '$$', display: true},
      {left: '\\[', right: '\\]', display: true},
      {left: '$', right: '$', display: false},
      {left: '\\(', right: '\\)', display: false}
  ]
});"></script>

and now you can use all $$; \\[; $; and \\( directly in markdowns, and add more delimiters as you see fit.

RexYuan avatar May 15 '23 18:05 RexYuan