forked from mirrors/hugo-tufte
fix katex, 1 new shortcode, various fixes
This commit is contained in:
parent
e6c63a59cb
commit
e6d583a987
9 changed files with 90 additions and 46 deletions
22
assets/latex-fix.js
Normal file
22
assets/latex-fix.js
Normal 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/
|
|
@ -21,8 +21,7 @@ article,
|
|||
header,
|
||||
footer,
|
||||
.pure-g [class*="pure-u"] {
|
||||
font-family: "et-book", -apple-system, "San Francisco", "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell",
|
||||
"Open Sans", "Helvetica Neue", "Lucida Grand", sans-serif;
|
||||
font-family: et-book, "Noto Serif SC", Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif;
|
||||
}
|
||||
|
||||
p {
|
||||
|
|
2
assets/scss/vendor/tufte.scss
vendored
2
assets/scss/vendor/tufte.scss
vendored
|
@ -64,7 +64,7 @@ body {
|
|||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
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;
|
||||
color: #111;
|
||||
max-width: 1400px;
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="{{ .Site.LanguageCode }}">
|
||||
{{- partial "header.html" . -}}
|
||||
{{- partial "header.html" . -}}
|
||||
|
||||
<body >
|
||||
{{ block "main" . }}{{ end }}
|
||||
</body>
|
||||
<body >
|
||||
{{ block "main" . }}{{ end }}
|
||||
|
||||
<!-- Load Katex, if necessary. -->
|
||||
{{ if or .Params.math .IsHome }}
|
||||
{{ partial "math.html" . }}
|
||||
{{ end }}
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -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">
|
||||
<!-- Pure 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 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 -->
|
||||
<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="{{ "/css/hugo-tufte-override.css" | relURL }}">
|
||||
|
||||
|
||||
|
|
|
@ -1,29 +1,28 @@
|
|||
{{ if .Params.katex }}
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css">
|
||||
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.js"></script>
|
||||
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/contrib/auto-render.min.js"></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>
|
||||
<!-- <script src="{{ "/js/math-code.js" | relURL }}"></script> -->
|
||||
{{ $script := resources.Get "latex-fix.js" | resources.Minify }}
|
||||
{{ with $script.Content }}
|
||||
<script>{{ . | safeJS }}</script>
|
||||
{{ 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>
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
<p>
|
||||
{{ .Inner | markdownify }}
|
||||
</p>
|
||||
<footer>{{ .Get "footer" }}</footer>
|
||||
<footer>{{ .Get "footer" }}{{ with .Get "cite" }}, <cite>{{ . }}</cite>{{ end }}</footer>
|
||||
</blockquote>
|
12
layouts/shortcodes/cols.html
Normal file
12
layouts/shortcodes/cols.html
Normal 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>
|
|
@ -11,5 +11,5 @@
|
|||
{{ with .Get "post" }}{{ . }}{{ end }}
|
||||
</footer>
|
||||
{{ end }}
|
||||
<blockquote>
|
||||
</blockquote>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue