hugo-book
hugo-book copied to clipboard
inline math rendering with $
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.
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.
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
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 :-/
https://github.com/alex-shpak/hugo-book/blob/master/layouts/shortcodes/katex.html#L5
it's here, function called renderMathInElement
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.