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 css/js not included #40

Open
jpf91 opened this issue Jan 7, 2025 · 3 comments
Open

Katex css/js not included #40

jpf91 opened this issue Jan 7, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@jpf91
Copy link

jpf91 commented Jan 7, 2025

Hi,

sorry if this is a dumb question, but I couldn't find a solution.
I'm using the latest version of the PaperMod theme and hugo v0.140.2.

I've added this to layouts/partials/extend_head.html:

{{ partial "katex/assets/css" . }}
{{ partial "katex/assets/js" . }}

And if I add some debug text there I also see that it's always included. However, if I run hugo serve, add the example to a post and save:

{{< katex >}}
\begin{array}{l}
E*{o 1}=\frac{1}{2}\left( { target }*{o 1}- { out }_{o 1}\right)^{2}=\frac{1}{2}(0.01-0.75136507)^{2}=0.274811083 \\
E_{o 2}=0.023560026 \\
E*{ {total }}=E*{o 1}+E\_{o 2}=0.274811083+0.023560026=0.298371109
\end{array}
{{< /katex >}}

Then the latex does not render and the CSS and JS is not included. If I now open extend_head.html and save it, hugo recompiles, the page reloads, the imports are there and Katex renders. But if I now modify the article and save that file, it doesn't render again. Any idea what could cause this?

@razonyang
Copy link
Member

razonyang commented Jan 8, 2025

I couldn't replicate this with PaperMod (latest version). Would you be willing to share a minimal repository for testing purposes?

The KaTeX diagrams were rendered correctly when editing the extend_head, content file with or without KaTeX.

@jpf91
Copy link
Author

jpf91 commented Jan 8, 2025

Hi @razonyang, thanks for looking into this!

I've pushed a minimal reproduction repository here: https://github.com/jpf91/katex-repro

The easiest way to reproduce: If I just run hugo serve and open the blog post, math is not rendered. If I then edit and save extend_head.html and reload the web page, it renders.

@razonyang razonyang added the bug Something isn't working label Jan 9, 2025
@razonyang
Copy link
Member

razonyang commented Jan 9, 2025

There is a workaround to replace the extend_head with the following template instead, to make sure the content was processed first, then generate the CSS and JS markup.

{{ $data := dict "page" . }}
{{ with (templates.Defer (dict "data" $data)) }}
  {{ partial "katex/assets/css" .page }}
  {{ partial "katex/assets/js" .page }}
{{ end }}

It's a bug. I will take a close look at it if I have time, so please do not close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants