Using transform.ToMath in Summary of Post in PaperMod Theme

I’m relatively new to Hugo, so apologies if it is a simple fix. I was trying to follow this thread (How to use the transform.ToMath function? - support - HUGO) to have purely server-side latex rendering and looked through the provided example repo in the solution.

I have set-up an example of my issue here ( pocofrosty/math-rendering-with-PaperMod-example: Testing MathJax with PaperMod Theme). I installed the PaperMod theme and added the stylesheet by overwriting the extend_head.html file and added the render-passthrough file.

When I localhost and select a post, I am able to see the latex rendered. On the other hand, from the main page, the summary of the post does not render properly (Confusingly, it duplicates it 3 times it seems). Using a manual summary from Hugo’s documentation didn’t seem to resolve this issue.

I think the relevant code to modify is in themes/PaperMod/layouts/_default/_list.html.

  {{- if (ne (.Param "hideSummary") true) }}
  <div class="entry-content">
    <p>{{ .Summary | plainify | htmlUnescape }}{{ if .Truncated }}...{{ end }}</p>
  </div>
  {{- end }}

The KaTeX stylesheet is only included on the page that includes mathematical markup. To include the KaTeX stylesheet on list pages as well, change layouts/_default/partials/extend_head.html to:

{{ $noop := .WordCount }}
{{ if or (.Page.Store.Get "hasMath") .IsNode }}
  <link href="https://cdn.jsdelivr.net/npm/katex@0.16.22/dist/katex.min.css" rel="stylesheet">
{{ end }}

You also need to override themes/PaperMod/layouts/_default/list.html because it strips HTML tags from the summary:

I would do this:

mkdir -p layouts/_default
cp themes/PaperMod/layouts/_default/list.html layouts/_default/

Then, in the file you just created, replace line 84 with this, and don’t wrap it within a p element:

{{ .Summary }}

Finally, use manual summaries instead of automatic summaries on pages that include mathematical markup that you want to appear in the summary. For example:

\[3x + 2 = 5\]

$$2x + 5 = 6 $$

Example Equation in Summary

<!--more-->

And here's the rest of the content...

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