next-theme / hexo-filter-mathjax

💯 Server side MathJax renderer plugin for Hexo.
https://www.npmjs.com/package/hexo-filter-mathjax
MIT License
105 stars 6 forks source link

Are linebreaks supported? #30

Closed ZodmanPerth closed 3 years ago

ZodmanPerth commented 3 years ago

I've been trying to output several different formulas on multiple lines, but am unable to get any linebreaks. I've tried pretty much all the methods I found in the KaTeX documentation but had no luck.

For example, using the editor at katex.org, the text

\textcolor{purple}{z}=(\textcolor{green}{c_1} \space choose \space \textcolor{teal}3)+(\textcolor{green}{c_2} \space choose \space \textcolor{teal}2)+(\textcolor{green}{c_3} \space choose \space \textcolor{teal}1)\\
\space\\
OR\\
\space\\
\textcolor{purple}{z}=\bigg(\vcenter{\textcolor{green}{c_1} \atop \textcolor{teal}3}\bigg)+\bigg(\vcenter{\textcolor{green}{c_2} \atop \textcolor{teal}2}\bigg)+\bigg(\vcenter{\textcolor{green}{c_3} \atop \textcolor{teal}1}\bigg)\\

produces

image

but through hexo-filter-mathjax it produces

image

I am new to writing math with these TeX type libraries so hopefully I am just doing something wrong, but I can't spot it. Are linebreaks supported in this package?

stevenjoezhang commented 3 years ago

\ may be interpreted by Hexo as an escape character, so you need another \ to escape itself:

\textcolor{purple}{z}=(\textcolor{green}{c_1} \space choose \space \textcolor{teal}3)+(\textcolor{green}{c_2} \space choose \space \textcolor{teal}2)+(\textcolor{green}{c_3} \space choose \space \textcolor{teal}1)\\\\
\space\\\\
OR\\\\
\space\\\\
\textcolor{purple}{z}=\bigg(\vcenter{\textcolor{green}{c_1} \atop \textcolor{teal}3}\bigg)+\bigg(\vcenter{\textcolor{green}{c_2} \atop \textcolor{teal}2}\bigg)+\bigg(\vcenter{\textcolor{green}{c_3} \atop \textcolor{teal}1}\bigg)\\\\
ZodmanPerth commented 3 years ago

No luck. I've also tried \newline. All of them produce a single line result.

stevenjoezhang commented 3 years ago

Have you tried to put it in the eqnarray environment? It's working as expected on my website:

\begin{eqnarray\*}
\textcolor{purple}{z}=(\textcolor{green}{c_1} \space choose \space \textcolor{teal}3)+(\textcolor{green}{c_2} \space choose \space \textcolor{teal}2)+(\textcolor{green}{c_3} \space choose \space \textcolor{teal}1)\\\\
\space\\\\
OR\\\\
\space\\\\
\textcolor{purple}{z}=\bigg(\vcenter{\textcolor{green}{c_1} \atop \textcolor{teal}3}\bigg)+\bigg(\vcenter{\textcolor{green}{c_2} \atop \textcolor{teal}2}\bigg)+\bigg(\vcenter{\textcolor{green}{c_3} \atop \textcolor{teal}1}\bigg)\\\\
\end{eqnarray\*}
截屏2021-03-26 下午1 10 05
ZodmanPerth commented 3 years ago

Well that's odd, this works. I believed I had tried this before, but this now works on my website as well. It's not the layout I want, but at least it appears the library is working properly.

I really want all lines to be centered horizontally, and can't find the right syntax. Looks like I'll have to go with two mathjax blocks separated by a div.

Thanks for your help.

stevenjoezhang commented 3 years ago

Try this:

\begin{eqnarray\*}
&\textcolor{purple}{z}=(\textcolor{green}{c_1} \space choose \space \textcolor{teal}3)+(\textcolor{green}{c_2} \space choose \space \textcolor{teal}2)+(\textcolor{green}{c_3} \space choose \space \textcolor{teal}1)\\\\
&\space\\\\
&OR\\\\
&\space\\\\
&\textcolor{purple}{z}=\bigg(\vcenter{\textcolor{green}{c_1} \atop \textcolor{teal}3}\bigg)+\bigg(\vcenter{\textcolor{green}{c_2} \atop \textcolor{teal}2}\bigg)+\bigg(\vcenter{\textcolor{green}{c_3} \atop \textcolor{teal}1}\bigg)\\\\
\end{eqnarray\*}

See also https://tex.stackexchange.com/questions/114471/how-to-simply-center-equations-using-eqnarray

ZodmanPerth commented 3 years ago

Yes, that works great! Thank you!

Thanks for the link; that helps me improve my google-fu when it comes to these sorts of things.

stevenjoezhang commented 3 years ago

You're welcome :)

MathJax is compatible with most common LaTeX syntax, so you can find answers on this website: https://tex.stackexchange.com