Math equations with the less than sign (<) can't render correctly

This is my markdown:

`$a<b$` results in $a<b$

`$a< b$` results in $a< b$

The first line can’t render correctly. Because the browser think <b is the start of a HTML element. This is the html:

<p><code>$a&lt;b$</code> results in $a<b$</p>
<p><code>$a&lt; b$</code> results in $a< b$</p>

According to Less than sign adjacent to letter in version 3 · Issue #2669 · mathjax/MathJax, HTML special characters will be interpreted by the browser long before MathJax (or KaTeX) runs.

My solution is add a space after < or use \lt. But I’m worried that I might forget to do that; is there any other way to solve this?

No, there is not.

While browsing the Hugo documentation today, I discovered that I missed the Passthrough render hooks. We can use render-passthrough.html to convert < to < , for example:

{{- $content := .Inner -}}
{{- $content := replace $content "<" "< " -}}
{{- if eq .Type "block" -}}
  {{- printf "$$%s$$" $content -}}
{{- else -}}
  {{- printf "$%s$" $content -}}
{{- end -}}

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