fix katex, 1 new shortcode, various fixes

This commit is contained in:
loikein 2023-04-14 19:21:10 +01:00
parent e6c63a59cb
commit e6d583a987
9 changed files with 90 additions and 46 deletions

22
assets/latex-fix.js Normal file
View file

@ -0,0 +1,22 @@
(function() {
var i, text, code, codes = document.getElementsByTagName('code');
for (i = 0; i < codes.length;) {
code = codes[i];
if (code.parentNode.tagName !== 'PRE' && code.childElementCount === 0 && !(code.classList.contains("nolatex")) ) {
text = code.textContent;
if (/^\$[^$]/.test(text) && /[^$]\$$/.test(text)) {
text = text.replace(/^\$/, '\\(').replace(/\$$/, '\\)');
code.textContent = text;
}
if (/^\\\((.|\s)+\\\)$/.test(text) || /^\\\[(.|\s)+\\\]$/.test(text) ||
/^\$(.|\s)+\$$/.test(text) ||
/^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) {
code.outerHTML = code.innerHTML; // remove <code></code>
continue;
}
}
i++;
}
})();
// https://yihui.org/en/2018/07/latex-math-markdown/

View file

@ -21,8 +21,7 @@ article,
header, header,
footer, footer,
.pure-g [class*="pure-u"] { .pure-g [class*="pure-u"] {
font-family: "et-book", -apple-system, "San Francisco", "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", font-family: et-book, "Noto Serif SC", Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif;
"Open Sans", "Helvetica Neue", "Lucida Grand", sans-serif;
} }
p { p {

View file

@ -64,7 +64,7 @@ body {
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
padding-left: 12.5%; padding-left: 12.5%;
font-family: et-book, Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif; font-family: et-book, "Noto Serif SC", Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif;
background-color: #fffff8; background-color: #fffff8;
color: #111; color: #111;
max-width: 1400px; max-width: 1400px;

View file

@ -1,9 +1,15 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="{{ .Site.LanguageCode }}"> <html lang="{{ .Site.LanguageCode }}">
{{- partial "header.html" . -}} {{- partial "header.html" . -}}
<body > <body >
{{ block "main" . }}{{ end }} {{ block "main" . }}{{ end }}
</body>
<!-- Load Katex, if necessary. -->
{{ if or .Params.math .IsHome }}
{{ partial "math.html" . }}
{{ end }}
</body>
</html> </html>

View file

@ -1,8 +1,3 @@
<!-- Load Katex, if necessary. -->
{{ if or .Params.math .IsHome }}
{{ partial "math.html" . }}
{{ end }}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/normalize.css@8.0.1/normalize.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/normalize.css@8.0.1/normalize.css">
<!-- Pure css --> <!-- Pure css -->
<link rel="stylesheet" href="https://unpkg.com/purecss@2.0.6/build/pure-min.css"> <link rel="stylesheet" href="https://unpkg.com/purecss@2.0.6/build/pure-min.css">
@ -12,6 +7,19 @@
<!-- <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface"> --> <!-- <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface"> -->
<!-- <link href='//fonts.googleapis.com/css?family=Raleway:400,200,100,700,300,500,600,800' rel='stylesheet' type='text/css'> --> <!-- <link href='//fonts.googleapis.com/css?family=Raleway:400,200,100,700,300,500,600,800' rel='stylesheet' type='text/css'> -->
<!-- asynchronously load Google Fonts -->
<!-- https://csswizardry.com/2020/05/the-fastest-google-fonts/#google-fonts-async-snippet -->
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link rel="preload" as="style"
href="https://fonts.googleapis.com/css?family=Noto+Serif+SC&display=swap" />
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Noto+Serif+SC&display=swap"
media="print" onload="this.media='all'" />
<noscript>
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Noto+Serif+SC&display=swap" />
</noscript>
<!-- Font Awesome --> <!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.css">
@ -20,5 +28,3 @@
<link rel="stylesheet" href="{{ $htstyle.Permalink | relURL }}"> <link rel="stylesheet" href="{{ $htstyle.Permalink | relURL }}">
<link rel="stylesheet" href="{{ "/css/hugo-tufte-override.css" | relURL }}"> <link rel="stylesheet" href="{{ "/css/hugo-tufte-override.css" | relURL }}">

View file

@ -1,29 +1,28 @@
{{ if .Params.katex }} <!-- <script src="{{ "/js/math-code.js" | relURL }}"></script> -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css"> {{ $script := resources.Get "latex-fix.js" | resources.Minify }}
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.js"></script> {{ with $script.Content }}
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/contrib/auto-render.min.js"></script> <script>{{ . | safeJS }}</script>
<script defer>
renderMathInElement(
document.body,
{
delimiters: [
{ left: "$$", right: "$$", display: true },
{ left: "\\[", right: "\\]", display: true },
{ left: "$", right: "$", display: false },
{ left: "\\(", right: "\\)", display: false }
],
displayMode: true
}
);
</script>
{{ else }}
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<script defer>
window.MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']]
}
};
</script>
{{ end }} {{ end }}
<link rel="stylesheet" href="{{ .Site.Params.KaTeXCDN }}/katex@{{ .Site.Params.KaTeXVersion }}/dist/katex.min.css" crossorigin="anonymous">
<script defer src="{{ .Site.Params.KaTeXCDN }}/katex@{{ .Site.Params.KaTeXVersion }}/dist/katex.min.js" crossorigin="anonymous"></script>
<script defer src="{{ .Site.Params.KaTeXCDN }}/katex@{{ .Site.Params.KaTeXVersion }}/dist/contrib/auto-render.min.js" crossorigin="anonymous"></script>
<!-- do not add onload attributes, breaks settings below -->
<script>
document.addEventListener("DOMContentLoaded", function() {
renderMathInElement(document.body, {
// delimiters: [
// {left: "$$\n", right: "\n$$", display: true},
// {left: "$$", right: "$$", display: false},
// {left: "\\[", right: "\\]", display: true},
// {left: "\\(", right: "\\)", display: false}
// ],
trust: (context) => ['\\htmlId', '\\href'].includes(context.command),
macros: {
"\\eqref": "\\href{###1}{(\\text{#1})}",
"\\ref": "\\href{###1}{\\text{#1}}",
"\\label": "\\htmlId{#1}{}"
}
});
});
</script>

View file

@ -2,5 +2,5 @@
<p> <p>
{{ .Inner | markdownify }} {{ .Inner | markdownify }}
</p> </p>
<footer>{{ .Get "footer" }}</footer> <footer>{{ .Get "footer" }}{{ with .Get "cite" }}, <cite>{{ . }}</cite>{{ end }}</footer>
</blockquote> </blockquote>

View file

@ -0,0 +1,12 @@
{{ $cols := split .Inner "||" }}
{{ $lang := .Get "lang" | default ( .Get 0 ) }}
{{ $lang := split $lang "," }}
<span class="row">
{{ range $indCol,$col := $cols }}
<span class="column" {{ with $lang }} lang="{{ index $lang $indCol }}"{{ end }}>
{{ . | $.Page.RenderString (dict "display" "block") }}
</span>
{{ end }}
</span>

View file

@ -11,5 +11,5 @@
{{ with .Get "post" }}{{ . }}{{ end }} {{ with .Get "post" }}{{ . }}{{ end }}
</footer> </footer>
{{ end }} {{ end }}
<blockquote> </blockquote>
</div> </div>