ojroques / hugo-researcher

A simple resume theme for Hugo
GNU General Public License v3.0
232 stars 131 forks source link

Mathjax support #1

Closed paniash closed 4 years ago

paniash commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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