Make small adjustments to backend math post.
This commit is contained in:
parent
b631346379
commit
fdaec6d5a9
|
@ -89,7 +89,7 @@ to `node2nix`:
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
The Ruby script I wrote for this (more on that soon) required the `nokigiri` gem, which
|
The Ruby script I wrote for this (more on that soon) required the `nokogiri` gem, which
|
||||||
I used for traversing the HTML generated for my site. Hugo was obviously required to
|
I used for traversing the HTML generated for my site. Hugo was obviously required to
|
||||||
generate the HTML.
|
generate the HTML.
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ some Bash scripts. The math on this page was rendered at the time it was generat
|
||||||
|
|
||||||
This is a great point, and KaTeX is indeed usable for server-side rendering. But I've
|
This is a great point, and KaTeX is indeed usable for server-side rendering. But I've
|
||||||
seen few people who do actually use it. Unfortunately, as I pointed out in my previous post on the subject,
|
seen few people who do actually use it. Unfortunately, as I pointed out in my previous post on the subject,
|
||||||
few tools that actually take your HTML page and replace LaTeX with rendered math.
|
few tools actually take your HTML page and replace LaTeX with rendered math.
|
||||||
Here's what I wrote about this last time:
|
Here's what I wrote about this last time:
|
||||||
|
|
||||||
> [In MathJax,] The bigger issue, though, was that the `page2html`
|
> [In MathJax,] The bigger issue, though, was that the `page2html`
|
||||||
|
@ -183,7 +183,7 @@ some captions, alt texts, and similar elements should also be left alone.
|
||||||
However, I don't have those on my website (yet), and I won't worry about
|
However, I don't have those on my website (yet), and I won't worry about
|
||||||
them now. Either way, because of the code tags,
|
them now. Either way, because of the code tags,
|
||||||
we can't just search-and-replace over the entire page; we need to be context
|
we can't just search-and-replace over the entire page; we need to be context
|
||||||
aware. This is where `nokigiri` comes in. We parse the HTML, and iterate
|
aware. This is where `nokogiri` comes in. We parse the HTML, and iterate
|
||||||
over all of the 'text' nodes, calling `perform_katex_sub` on all
|
over all of the 'text' nodes, calling `perform_katex_sub` on all
|
||||||
of those that _aren't_ inside code tags.
|
of those that _aren't_ inside code tags.
|
||||||
|
|
||||||
|
@ -222,7 +222,7 @@ All in all:
|
||||||
//*[not(self::code)]/text()
|
//*[not(self::code)]/text()
|
||||||
```
|
```
|
||||||
|
|
||||||
Finally, we use this XPath from `nokigiri`:
|
Finally, we use this XPath from `nokogiri`:
|
||||||
|
|
||||||
```Ruby {linenos=table}
|
```Ruby {linenos=table}
|
||||||
files = ARGV[0..-1]
|
files = ARGV[0..-1]
|
||||||
|
@ -278,7 +278,7 @@ take a few dozen seconds to run on my relatively small site. The
|
||||||
better approach would be to use a NodeJS script, rather than a Ruby one,
|
better approach would be to use a NodeJS script, rather than a Ruby one,
|
||||||
to perform the conversion. KaTeX also provides an API, so such a NodeJS
|
to perform the conversion. KaTeX also provides an API, so such a NodeJS
|
||||||
script can find the files, parse the HTML, and perform the substitutions.
|
script can find the files, parse the HTML, and perform the substitutions.
|
||||||
I did quite like using `nokigiri` here, though, and I hope that an equivalently
|
I did quite like using `nokogiri` here, though, and I hope that an equivalently
|
||||||
pleasant solution exists in JavaScript.
|
pleasant solution exists in JavaScript.
|
||||||
|
|
||||||
Re-rendering the whole website is also pretty wasteful. I rarely change the
|
Re-rendering the whole website is also pretty wasteful. I rarely change the
|
||||||
|
@ -287,6 +287,15 @@ to re-run the script, and therefore re-render every page. This makes sense
|
||||||
for me, since I use Nix, and my builds are pretty much always performed
|
for me, since I use Nix, and my builds are pretty much always performed
|
||||||
from scratch. On the other hand, for others, this may not be the best solution.
|
from scratch. On the other hand, for others, this may not be the best solution.
|
||||||
|
|
||||||
|
### Alternatives
|
||||||
|
The same person who sent me the original email above also pointed out
|
||||||
|
[this `pandoc` filter for KaTeX](https://github.com/Zaharid/pandoc_static_katex).
|
||||||
|
I do not use Pandoc, but from what I can see, this fitler relies on
|
||||||
|
Pandoc's `Math` AST nodes, and applies KaTeX to each of those. This
|
||||||
|
should work, but wasn't applicable in my case, since Hugo's shrotcodes
|
||||||
|
don't mix well with Pandoc. However, it certainly seems like a workable
|
||||||
|
solution.
|
||||||
|
|
||||||
### Conclusion
|
### Conclusion
|
||||||
With the removal of MathJax from my site, it is now completely JavaScript free,
|
With the removal of MathJax from my site, it is now completely JavaScript free,
|
||||||
and contains virtually the same HTML that it did beforehand. This, I hope,
|
and contains virtually the same HTML that it did beforehand. This, I hope,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user