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

Mathjax support #1

Closed
paniash opened this issue Sep 22, 2020 · 3 comments
Closed

Mathjax support #1

paniash opened this issue Sep 22, 2020 · 3 comments

Comments

@paniash
Copy link

paniash commented Sep 22, 2020

Hello there!

How do I get LaTeX snippets to be properly rendered. I tried using

<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

from the official website but the rendering is pretty bad. I'd be glad if you could help.

@ojroques
Copy link
Owner

ojroques commented Sep 22, 2020

Hello!

Following your issue I have added support for KaTeX for math typesetting (#2). You can enable it on a per-page basis by including math: true on your content files or globally by adding math: true to your project configuration. It is disabled by default.

Use $$ for block expressions and $ for inline expressions like so:

Inline math: $\varphi = \dfrac{1+\sqrt5}{2}= 1.6180339887…$

Block math:
$$
 \varphi = 1+\frac{1} {1+\frac{1} {1+\frac{1} {1+\cdots} } } 
$$

image

Check the doc for the available math functions.

I am not familiar with KaTeX and did not test it extensively so feel free to report any bugs :). I'm closing the issue in the meantime.

@paniash
Copy link
Author

paniash commented Sep 23, 2020

Hello @ojroques!
Thanks for adding KaTeX support. I was testing it and found that environments are not rendered at all. For example,

$$
f(x) = \int_{-\infty}^\infty \hat{f} (\xi), e^{2 \pi i \xi x} d\xi
$$

is rendered properly but when using environments, say when writing a matrix

$$
\begin{pmatrx}
a & b \\
c & d
\end{matrix}
$$

It doesn't render at all. Any idea what is going on?

@ojroques
Copy link
Owner

Hello,

It seems that new lines in block environment are not correctly interpreted by KaTeX. Hugo introduces
tags when it sees newlines which breaks KaTeX. You can write your matrices on a single-line (make sure to escape \\):

$$ \begin{pmatrix} a & b \\\\ c & d \end{pmatrix} $$

It is not very readable though. I added a math shortcode to do that for us. You can use it for block environments:

{{< math >}}
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
{{< /math >}}

Or even inline:

In-line: {{< math >}} f(x) = \int_{-\infty}^\infty \hat{f} (\xi), e^{2 \pi i \xi x} d\xi {{< /math >}}

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

2 participants