<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>LaTeX on kenji.blog</title><link>http://kenji.blog/en/tags/latex/</link><description>Recent content in LaTeX on kenji.blog</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>kenjinote</copyright><lastBuildDate>Fri, 31 Mar 2023 23:11:26 +0900</lastBuildDate><atom:link href="http://kenji.blog/en/tags/latex/index.xml" rel="self" type="application/rss+xml"/><item><title>How to enable KaTeX (LaTeX-style math formulas) in Hugo</title><link>http://kenji.blog/en/p/hugo%E3%81%A7katexlatex%E9%A2%A8%E6%95%B0%E5%BC%8F%E8%A1%A8%E7%A4%BA%E3%82%92%E6%9C%89%E5%8A%B9%E3%81%AB%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95/</link><pubDate>Fri, 31 Mar 2023 23:11:26 +0900</pubDate><guid>http://kenji.blog/en/p/hugo%E3%81%A7katexlatex%E9%A2%A8%E6%95%B0%E5%BC%8F%E8%A1%A8%E7%A4%BA%E3%82%92%E6%9C%89%E5%8A%B9%E3%81%AB%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95/</guid><description>&lt;img src="http://kenji.blog/p/hugo%E3%81%A7katexlatex%E9%A2%A8%E6%95%B0%E5%BC%8F%E8%A1%A8%E7%A4%BA%E3%82%92%E6%9C%89%E5%8A%B9%E3%81%AB%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95/img.png" alt="Featured image of post How to enable KaTeX (LaTeX-style math formulas) in Hugo" />&lt;h1 id="what-is-katex">What is KaTeX
&lt;/h1>&lt;p>KaTeX is a JavaScript library for displaying LaTeX-style mathematical formulas in HTML.&lt;/p>
&lt;p>Specifically, it can display formulas like the following:&lt;/p>
$$f(x) = x^2 + x + 41$$
&lt;p>There seem to be other LaTeX-style math rendering libraries, but KaTeX is known for being simple and fast.&lt;/p>
&lt;h1 id="how-to-introduce-it-to-hugo">How to introduce it to Hugo
&lt;/h1>&lt;ol>
&lt;li>Create a new &lt;code>layouts/partials/math.html&lt;/code> in your Hugo folder hierarchy.&lt;/li>
&lt;/ol>
&lt;p>Make the contents as follows:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">&amp;lt;link rel=&amp;#34;stylesheet&amp;#34; href=&amp;#34;https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.css&amp;#34; integrity=&amp;#34;sha384-vKruj+a13U8yHIkAyGgK1J3ArTLzrFGBbBc0tDp4ad/EyewESeXE/Iv67Aj8gKZ0&amp;#34; crossorigin=&amp;#34;anonymous&amp;#34;&amp;gt;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&amp;lt;script defer src=&amp;#34;https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.js&amp;#34; integrity=&amp;#34;sha384-PwRUT/YqbnEjkZO0zZxNqcxACrXe+j766U2amXcgMg5457rve2Y7I6ZJSm2A0mS4&amp;#34; crossorigin=&amp;#34;anonymous&amp;#34;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&amp;lt;script defer src=&amp;#34;https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/contrib/auto-render.min.js&amp;#34; integrity=&amp;#34;sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05&amp;#34; crossorigin=&amp;#34;anonymous&amp;#34;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&amp;lt;script&amp;gt;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">document.addEventListener(&amp;#34;DOMContentLoaded&amp;#34;, function() {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> renderMathInElement(
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> document.body,
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> delimiters: [
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> {left: &amp;#34;$$&amp;#34;, right: &amp;#34;$$&amp;#34;, display: true},
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> {left: &amp;#34;\\[&amp;#34;, right: &amp;#34;\\]&amp;#34;, display: true},
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> {left: &amp;#34;$&amp;#34;, right: &amp;#34;$&amp;#34;, display: false},
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> {left: &amp;#34;\\(&amp;#34;, right: &amp;#34;\\)&amp;#34;, display: false}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> ]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> });
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> });
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&amp;lt;/script&amp;gt;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;ol start="2">
&lt;li>Next, add the following code to the existing file &lt;code>layouts/partials/extend_head.html&lt;/code>.&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">{{ if or .Params.math .Site.Params.math }}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">{{ partial &amp;#34;math.html&amp;#34; . }}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">{{ end }}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;ol start="3">
&lt;li>Now you are ready to use KaTeX.&lt;/li>
&lt;/ol>
&lt;p>You can enable KaTeX by adding &lt;code>math: true&lt;/code> to the front matter of a page.&lt;/p>
&lt;ol start="4">
&lt;li>All you have to do is write formulas in LaTeX style in the body of the page article.&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">$$ e^{i \pi} = -1 $$
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>If you describe it as above, it will be displayed as follows:&lt;/p>
$$ e^{i \pi} = -1 $$
&lt;h1 id="references">References
&lt;/h1>&lt;ul>
&lt;li>&lt;a class="link" href="https://reorx.github.io/hugo-PaperModX/docs/math-typesetting/" target="_blank" rel="noopener"
>Math Typesetting | PaperModX&lt;/a>&lt;/li>
&lt;li>&lt;a class="link" href="https://katex.org/docs/autorender.html" target="_blank" rel="noopener"
>KaTex Auto-render Extension&lt;/a>&lt;/li>
&lt;li>&lt;a class="link" href="https://www.storange.jp/2017/02/katex.html" target="_blank" rel="noopener"
>Introduction to KaTeX | The Strange Storage&lt;/a>&lt;/li>
&lt;/ul></description></item></channel></rss>