
I occasionally write blog posts with some math. So far I have been using latex-formulae family of packages. This week Andres Löh asked whether LaTeX can be rendered as SVGs. The answer turns out to be yes, it wasn't few years ago. The preview CTAN package, and the dvisvgm tool make it very easy. I forked latex-formulae into latex-svg to use above mentioned tools. There are three packages on Hackage now: - latex-svg-image: render LaTeX formulae to SVG images - latex-svg-pandoc: render LaTeX formulae in pandoc documents - latex-svg-hakyll: render LaTeX formulae in hakyll pages To mention some differences between latex-formulae and latex-svg: - latex-svg-image uses only latex and dvisvgm, ImageMagick is not required. You don't need to tweak policy.xml to allow rasterization of PostScript. (See this StackOverflow question). - latex-svg-image supports global cache (off by default), which speedups hakyll site builds. My blog builds in 20 seconds instead of three minutes with empty cache. I wouldn't worry about space usage too much, the cache contents take 15M after building my blog. which is way less than the size of site executable. - latex-svg-hakyll has initFormulaCompilerSVGPure variant, which doesn't need IO to be created. You don't need to thread renderFormulae function through. Together with global cache, the perfomance penalty is small. - One drawback is that result pages become bigger (and slower). For example a formula-heavy https://oleg.fi/gists/posts/2018-12-12-find-correct-laws.html is - 576k in size with latex-formulae - 2819k in size with latex-svg (almost 5 times larger). Rendering SVG images is also more CPU expensive. Otherwise the API and module names are the same. If you are already a user of latex-formulae you can easily migrate to latex-svg. See the announcement blog post how some examples look like: https://oleg.fi/gists/posts/2020-03-06-latex-svg.html http://oleg.fi/gists/posts/2020-03-06-latex-svg.html http://oleg.fi/gists/posts/2020-03-06-latex-svg.html Crisp math-blogging to everyone - Oleg Grenrus http://oleg.fi/gists/posts/2020-03-06-latex-svg.html

On 3/6/20 7:41 AM, Oleg Grenrus wrote:
- One drawback is that result pages become bigger (and slower). For example a formula-heavy https://oleg.fi/gists/posts/2018-12-12-find-correct-laws.html is
- 576k in size with latex-formulae - 2819k in size with latex-svg (almost 5 times larger).
Rendering SVG images is also more CPU expensive.
I've been looking for a way to do away with MathJax for a while, and this is pretty cool. I know this is probably tricky to do in Hakyll, but you might be able to address the page-size issue by saving the SVG files externally and gzipping them. That would also get rid of some of the XHTML strict warnings (like the duplicate id="page1").

Hi Michael, thanks for the reply. In my blog I use mod_deflate (Transfer-Encoding: gzip), and the result is Uncompressed Page Size: 2392.6 KB Compressed Page Size: 806.5 KB Savings: 66.3% (I tweaked parameters for dvisvgm, so uncompressed size went down too). The overall gzipping is quite good and easy solution, basically adding AddOutputFilterByType DEFLATE text/html to .htaccess for Apache. --- Good that you pointed out `<g id="page1">`; that id is unnecessary, and I should strip it off. It does not add any value. --- About saving images as external files, Hakyll does support such functionality: https://groups.google.com/forum/#!topic/hakyll/vQpijNtTG5M The latex-formulae-hakyll (and therefore latex-svg-hakyll) has internal to do note to add support for storing files externally, which is doable using Hakyll metacompilers. One can name files using hash of their contents. That is a feature waiting to be done. --- I opened issues to remember these issues, but I cannot promise to work on them (especially second one) any time soon. - https://github.com/phadej/latex-svg/issues/2 - https://github.com/phadej/latex-svg/issues/3 https://github.com/phadej/latex-svg/issues/2 Best regards, Oleg Grenrus On 11.3.2020 5.05, Michael Orlitzky wrote:
On 3/6/20 7:41 AM, Oleg Grenrus wrote:
- One drawback is that result pages become bigger (and slower). For example a formula-heavy https://oleg.fi/gists/posts/2018-12-12-find-correct-laws.html is
- 576k in size with latex-formulae - 2819k in size with latex-svg (almost 5 times larger).
Rendering SVG images is also more CPU expensive.
I've been looking for a way to do away with MathJax for a while, and this is pretty cool. I know this is probably tricky to do in Hakyll, but you might be able to address the page-size issue by saving the SVG files externally and gzipping them. That would also get rid of some of the XHTML strict warnings (like the duplicate id="page1"). _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

On 3/11/20 7:23 AM, Oleg Grenrus wrote:
Hi Michael,
thanks for the reply. In my blog I use mod_deflate (Transfer-Encoding: gzip), and the result is
Uncompressed Page Size: 2392.6 KB Compressed Page Size: 806.5 KB Savings: 66.3%
That would actually work great on my static site, but for example we have mod_deflate disabled at work to mitigate the BREACH attacks in the thousands of random copy & pasted javascript/PHP libraries that constitute "web development" these days. I'm glad to hear the compression brings things back down to a reasonable size, though.
I opened issues to remember these issues, but I cannot promise to work on them (especially second one) any time soon. - https://github.com/phadej/latex-svg/issues/2 - https://github.com/phadej/latex-svg/issues/3
Thanks! I'll keep an eye on them.

I wrote a package a month ago with the same name and does roughly the same XD (https://github.com/poscat0x04/latex-svg) Your package is definitely more polished. On 3/6/20 8:41 PM, Oleg Grenrus wrote:
I occasionally write blog posts with some math. So far I have been using latex-formulae family of packages. This week Andres Löh asked whether LaTeX can be rendered as SVGs.
The answer turns out to be yes, it wasn't few years ago.
The preview CTAN package, and the dvisvgm tool make it very easy. I forked latex-formulae into latex-svg to use above mentioned tools. There are three packages on Hackage now:
- latex-svg-image: render LaTeX formulae to SVG images - latex-svg-pandoc: render LaTeX formulae in pandoc documents - latex-svg-hakyll: render LaTeX formulae in hakyll pages
To mention some differences between latex-formulae and latex-svg:
- latex-svg-image uses only latex and dvisvgm, ImageMagick is not required. You don't need to tweak policy.xml to allow rasterization of PostScript. (See this StackOverflow question).
- latex-svg-image supports global cache (off by default), which speedups hakyll site builds. My blog builds in 20 seconds instead of three minutes with empty cache. I wouldn't worry about space usage too much, the cache contents take 15M after building my blog. which is way less than the size of site executable.
- latex-svg-hakyll has initFormulaCompilerSVGPure variant, which doesn't need IO to be created. You don't need to thread renderFormulae function through. Together with global cache, the perfomance penalty is small.
- One drawback is that result pages become bigger (and slower). For example a formula-heavy https://oleg.fi/gists/posts/2018-12-12-find-correct-laws.html is
- 576k in size with latex-formulae - 2819k in size with latex-svg (almost 5 times larger).
Rendering SVG images is also more CPU expensive.
Otherwise the API and module names are the same. If you are already a user of latex-formulae you can easily migrate to latex-svg.
See the announcement blog post how some examples look like: https://oleg.fi/gists/posts/2020-03-06-latex-svg.html http://oleg.fi/gists/posts/2020-03-06-latex-svg.html http://oleg.fi/gists/posts/2020-03-06-latex-svg.html
Crisp math-blogging to everyone
- Oleg Grenrus
http://oleg.fi/gists/posts/2020-03-06-latex-svg.html
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

Am Freitag, den 06.03.2020, 14:41 +0200 schrieb Oleg Grenrus:
There are three packages on Hackage now:
- latex-svg-image: render LaTeX formulae to SVG images - latex-svg-pandoc: render LaTeX formulae in pandoc documents - latex-svg-hakyll: render LaTeX formulae in hakyll pages
Hi, Oleg! Thanks for this great work.
https://oleg.fi/gists/posts/2018-12-12-find-correct-laws.html
It seems that baselines of formulas and surrounding text are aligned, which is an important feature, which is missing from several other solutions. However, when looking at the situation in detail, the formulas seem to be slightly too high. Does the conversion mechanism take baselines into account, or is the approximate alignment achieved just by accident?
See the announcement blog post how some examples look like: https://oleg.fi/gists/posts/2020-03-06-latex-svg.html http://oleg.fi/gists/posts/2020-03-06-latex-svg.html http://oleg.fi/gists/posts/2020-03-06-latex-svg.html
I see a small problem here: The example formula (x = y) ↔ (∀z. (z ≤ x) ↔ (z ≤ y)) has the letters y slightly cut off at the bottom, probably because they extend some automatically computed bounding box. Could this be fixed? All the best, Wolfgang
participants (4)
-
Michael Orlitzky
-
Oleg Grenrus
-
Poscat
-
Wolfgang Jeltsch