Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KaTex cannot render some equations #455

Closed
preminstrel opened this issue Sep 11, 2021 · 15 comments
Closed

KaTex cannot render some equations #455

preminstrel opened this issue Sep 11, 2021 · 15 comments

Comments

@preminstrel
Copy link

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:
Snipaste_2021-09-11_12-46-29

Thanks for your time !

@preminstrel
Copy link
Author

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?

@h-enk
Copy link
Member

h-enk commented Sep 14, 2021

@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}
$$

Snag_5bcbdcd

@emptymalei
Copy link

@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.

@preminstrel
Copy link
Author

Thank you for your time!
It exactly works. @h-enk

@h-enk
Copy link
Member

h-enk commented Sep 15, 2021

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>

@preminstrel
Copy link
Author

This method seems extremely good and portable. I will use this one!😀
Thanks for your time and nice theme.

@tuyenld
Copy link

tuyenld commented Aug 10, 2022

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/

image

@tuyenld
Copy link

tuyenld commented Aug 10, 2022

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.

@h-enk
Copy link
Member

h-enk commented Aug 12, 2022

@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
$$

Snag_a9718a6

@h-enk
Copy link
Member

h-enk commented Aug 12, 2022

Do you have a repo you could share?

@tuyenld
Copy link

tuyenld commented Aug 12, 2022

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.

@h-enk
Copy link
Member

h-enk commented Aug 15, 2022

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}
$$

@h-enk
Copy link
Member

h-enk commented Aug 15, 2022

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,

  1. 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" -}}
  2. Update https://github.com/h-enk/doks/blob/master/layouts/partials/footer/script-footer.html#L99:

      {{ $katex := $katex | fingerprint "sha512" -}}

@h-enk h-enk reopened this Aug 15, 2022
@h-enk h-enk added the keep label Aug 15, 2022
@tuyenld
Copy link

tuyenld commented Aug 16, 2022

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,

  1. 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" -}}
    
  2. 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.

@h-enk h-enk removed the keep label Jan 8, 2024
@h-enk
Copy link
Member

h-enk commented Jan 8, 2024

Doks now uses the free Math API service. See also Mathematical Expressions

@h-enk h-enk closed this as completed Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants