# One of several LaTeX equations is not rendered by KaTeX

**URL:** <https://discourse.gohugo.io/t/one-of-several-latex-equations-is-not-rendered-by-katex/47790>\
**Category:** support\
**Tags:** typesetting\
**Created:** [January 11, 2024, 11:01am UTC](https://discourse.gohugo.io/t/one-of-several-latex-equations-is-not-rendered-by-katex/47790 "2024-01-11T11:01:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MLexplora](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@MLexplora](https://discourse.gohugo.io/u/MLexplora)\
**Post date:** [January 11, 2024, 11:01am UTC](https://discourse.gohugo.io/t/one-of-several-latex-equations-is-not-rendered-by-katex/47790/1 "2024-01-11T11:01:03Z")

</div>

Hello all,  
Been playing with Hugo/papermod theme to display matrix equations and I hit a wall recently

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/3X/c/7/c7c20f03fb56a152bdffc82037c93b2d9ae21638.jpeg)

The second equation (the one I’m interested in) does not render for some reason that idk.  
The code is available at [GitHub - MLExplora/Hugo\_site](https://github.com/MLExplora/Hugo_site)  
Does anybody have an idea ?  
Thanks for your help

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [January 11, 2024, 2:37pm UTC](https://discourse.gohugo.io/t/one-of-several-latex-equations-is-not-rendered-by-katex/47790/2 "2024-01-11T14:37:42Z")

</div>

There is a very long story behind this:  
[https://github.com/gohugoio/hugo/issues/10894](https://github.com/gohugoio/hugo/issues/10894)

### Problem

Your second example contains four pairs of matching underscores, two on each line. When the markdown renderer encounters these, it wraps the content between the underscores within an `em` element, which breaks the LaTeX. Technically the markdown renderer is doing what it should… text between underscores, [under certain conditions](https://spec.commonmark.org/0.30/#emphasis-and-strong-emphasis), should be emphasized.

The problem is that the markdown renderer does not recognize LaTeX delimiters. There is work underway to optionally enable such recognition, passing the content between and including the delimiters through without processing it as markdown.

But, even if that feature were available today, your second example would still fail because you are rendering the LaTeX client-side using KaTeX v0.12.0 (released in 2020), which has a [known bug](https://github.com/KaTeX/KaTeX/issues/2860) related to backslashes. That KaTeX bug was resolved in v0.13.6.

### Solution

#### Step 1

I noticed that you modified `themes/papermod/layouts/partials/extend_head.html`. If you ever update the theme you may inadvertently overwrite that file. So let’s move it to a layouts/partials directory in the root of your project:

```plaintext
mkdir -p layouts/partials
mv themes/papermod/layouts/partials/extend_head.html layouts/partials/

```

#### Step 2

Update to the latest KaTeX version using the [example from katex.org](https://katex.org/docs/autorender):

> **layouts/partials/extend\_head.html**
>
> ```plaintext
> {{- /* Head custom content area start */ -}}
> {{- /* Insert any custom code (web-analytics, resources, etc.) - it will appear in the <head></head> section of every page. */ -}}
> {{ if or .Params.math .Site.Params.math }}
> 
> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css" integrity="sha384-n8MVd4RsNIU0tAv4ct0nTaAbDJwPJzDEaqSD1odI+WdtXRGWt2kTvGFasHpSy3SV" crossorigin="anonymous">
> <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js" integrity="sha384-XjKyOOlGwcjNTAIQHIpgOno0Hl1YQqzUOEleOLALmuqehneUG+vnGctmUb0ZY0l8" crossorigin="anonymous"></script>
> <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js" integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous"></script>
> <script>
> document.addEventListener("DOMContentLoaded", function() {
> renderMathInElement(document.body, {
> // customised options
> // • auto-render specific keys, e.g.:
> delimiters: [
> {left: '$$', right: '$$', display: true},
> {left: '$', right: '$', display: false},
> {left: '\\(', right: '\\)', display: false},
> {left: '\\[', right: '\\]', display: true}
> ],
> // • rendering keys, e.g.:
> throwOnError : false
> });
> });
> </script>
> 
> {{ end }}
> {{- /* Can be overwritten by partial with the same name in the global layouts. */ -}}
> {{- /* Head custom content area end */ -}}
> 
> ```

#### Step 3

Until the LaTeX passthrough feature is available in Hugo, you can wrap your equations with the theme’s rawhtml shortcode:

```plaintext
But this is not rendered properly !

{{< rawhtml >}}
Y = 
$\begin{bmatrix}
    \alpha_{1,1}\mathbf{x}_1 +...+ \alpha_{1,M}\mathbf{x}_M \\\
    \vdots \\\
    \alpha_{N,1}\mathbf{x}_1 +...+ \alpha_{N,M}\mathbf{x}_M 
\end{bmatrix}$  
{{< /rawhtml >}}

```

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [January 28, 2024, 12:40pm UTC](https://discourse.gohugo.io/t/one-of-several-latex-equations-is-not-rendered-by-katex/47790/3 "2024-01-28T12:40:51Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
