doks
doks copied to clipboard
KaTex cannot render some equations
The problem is that when I use KaTex to render my equations, some eqautions can be rendered while others cannot be. Such equation like below cannot be rendered: (use env aligned)
$$\left\{
\begin{aligned}
PDE \quad &u_{tt}-a^2u_{xx}=0 \\
B.C.\quad &u(0,t)=u(l,t)=0\quad t\ge 0 \\
I.C.\quad & u(x,0)=\varphi(x),u_t(x,0)=\phi(x)\quad 0\le x\le l
\end{aligned}
\right.$$
And the result is below:

Thanks for your time !
I find that codes below can work.
- no line feed
- use
\\not\
$$\\left\\{\\begin{aligned}PDE \\quad &u_{tt}-a^2u_{xx}=0 \\\B.C.\\quad &u(0,t)=u(l,t)=0\\quad t\\ge 0 \\\I.C.\\quad & u(x,0)=\\varphi(x),u_t(x,0)=\\phi(x)\\quad 0\\le x\\le l \\\\ \end{aligned}\\right.$$
So how I fix it? Is that an error that maybe happened in keTax.auto-render?
@preminstrel, I think it's a configuration setting in ./assets/js/katex.js — see also "newLineInDisplayMode" in options.
Unfortunately, I'm not a KaTeX /LaTeX expert. @emptymalei, could you be of any help? Thanks!
For now, using \newline in stead of \\ does work:
$$
\begin{aligned}
PDE \quad &u_{tt}-a^2u_{xx}=0 \newline
B.C.\quad &u(0,t)=u(l,t)=0\quad t\ge 0 \newline
I.C.\quad & u(x,0)=\varphi(x),u_t(x,0)=\phi(x)\quad 0\le x\le l
\end{aligned}
$$

@h-enk I'm not familiar with KaTeX. I've been using Mathjax for math. The double-slash works fine in mathjax.
I'll have a look at this. I'm also interested in switching to KaTeX as it is faster than mathjax.
Thank you for your time!
It exactly works. @h-enk
It seems to be a Goldmark issue. A better (portable) trick for now, use <div></div> like so:
<div>
$$\left\{
\begin{aligned}
PDE \quad &u_{tt}-a^2u_{xx}=0 \\
B.C.\quad &u(0,t)=u(l,t)=0\quad t\ge 0 \\
I.C.\quad & u(x,0)=\varphi(x),u_t(x,0)=\phi(x)\quad 0\le x\le l
\end{aligned}
\right.$$
</div>
This method seems extremely good and portable. I will use this one!😀 Thanks for your time and nice theme.
Katex seems to be broken.
I checked #181, but the math equation on the site is not working anymore.
https://math-typesetting--doks.netlify.app/docs/examples/math/

I tried
$$
\begin{aligned }
J_n = nqv_d \newline
J_n = nq\dfrac{1}{2} \dfrac{q\tau}{m^{2}}E
\end{aligned }
$$
$$
\begin{aligned}
a &=b+c \cr
d+e &=f
\end{aligned}
$$
$$
\begin{aligned}
a & b \\\\ c & d
\end{aligned}
$$
but none of them works.
@tuyenld Hmm, I can't confirm your issue — following (the example in) the Doks docs (https://getdoks.org/docs/how-to/extra-features/katex/), it works for me.
Also, this works for me:
$$
J_n = nqv_d \newline
J_n = nq\dfrac{1}{2} \dfrac{q\tau}{m^{2}}E
$$

Do you have a repo you could share?
Do you have a repo you could share?
Yes. Here is my post, and this is my md file.
I changed script-footer.html to adapt my front matter need, but I don't think it is a problem.
Turn out that if I removed minify from $katex | minify on script-footer.html, it displays correctly. Don't know what causes the problem.
Could you try with removing the space in \begin{aligned } and \end{aligned }, like so:
$$
\begin{aligned}
J_n = nqv_d \newline
J_n = nq\dfrac{1}{2} \dfrac{q\tau}{m^{2}}E
\end{aligned}
$$
Turn out that if I removed minify from $katex | minify on script-footer.html, it displays correctly. Don't know what causes the problem.
Yes, confirmed. We could configure the Hugo minify command to make it work. But, I think it's best to use the minified Katex script itself in the first place.
So,
-
Update https://github.com/h-enk/doks/blob/master/layouts/partials/footer/script-footer.html#L10:
{{ $katex := resources.Get "js/vendor/katex/dist/katex.min.js" -}} -
Update https://github.com/h-enk/doks/blob/master/layouts/partials/footer/script-footer.html#L99:
{{ $katex := $katex | fingerprint "sha512" -}}
Turn out that if I removed minify from $katex | minify on script-footer.html, it displays correctly. Don't know what causes the problem.
Yes, confirmed. We could configure the Hugo
minifycommand to make it work. But, I think it's best to use the minified Katex script itself in the first place.So,
- Update https://github.com/h-enk/doks/blob/master/layouts/partials/footer/script-footer.html#L10:
{{ $katex := resources.Get "js/vendor/katex/dist/katex.min.js" -}}- Update https://github.com/h-enk/doks/blob/master/layouts/partials/footer/script-footer.html#L99:
{{ $katex := $katex | fingerprint "sha512" -}}
It is not enough for this case.
$$
\begin{align*}
u(t)={
\begin{cases}
1&{\text{if }}t \ge 0 \newline
0&{\text{if }}t \lt 0 \newline
\end{cases}}
\qquad
u[n]={
\begin{cases}
1&{\text{if }}n \ge 0 \newline
0&{\text{if }}n \lt 0 \newline
\end{cases}}
\end{align*}
$$
I need to use {{ .Inner }} shortcode to make it works.
Doks now uses the free Math API service. See also Mathematical Expressions