1

I have one file, and I want to alternately produce printable PDF files via xelatex and HTML pages via htlatex. By default, htlatex produces just really ugly, low-resolution PNG equations. I want SVG instead.

I do not want to use MathJaX. I want my file to work without JavaScript, and I don't want users to have to render the complex TeX every time.

Following advice online, I put this in c.cfg...

\Preamble{ext=htm,charset="utf-8",p-width,pic-align}
  \Configure{Picture}{.svg}  
  \makeatletter
  \Configure{graphics*}
  {svg}
  {
    {\Configure{Needs}{File: \Gin@base.svg}\Needs{}}
    \Picture[\csname a:GraphicsAlt\endcsname]{\csname Gin@base\endcsname.svg
            \csname a:Gin-dim\endcsname}
  }
  \begin{document}
\EndPreamble

Ran htlatex via htlatex myfile "c"...and, got this: pstoedit: Unsupported output format svg.

Hmm, what happened here? Is my system misconfigured, as this Debian bug reporter thought? No. Perhaps at one point pstoedit's SVG conversion was free software, but not anymore.

SVG is a shareware "plugin" of pstoedit, and there is no binary for my OS, FreeBSD.

How can I have SVG math, and really SVG anything else marked between some command, with htlatex without pstoedit?

I've determined that htlatex works internally by first generating an EPS file, e.g. zztest.eps. It then tries pstoedit -f svg zztest.eps test0x.svg. So I thought I'd just try another converter, but other converters, such as uniconvertor and inkscape -z, do not properly recognize LaTeX's magic, and put the EPS onto a huge canvas (see below). Also, it is cumbersome to have to run the other convertor every time, there should be a way to specify which convertor to use.

enter image description here

The image should look like the output of default htlatex, just as an SVG.

enter image description here

2

We should really replace pstoedit with something better. In reality, the process where we convert DVI to PostScript and then to SVG isn't really necessary today, as direct DVI do SVG convertor exists nowadays.

You can change the commands for image conversion in tex4ht.env file, but this process isn't really easy. Instead, I would use make4ht, which is modern replacement for htlatex with support for build files. You can specify custom commands for image conversion in these build files.

Save the following code as test.mk4:

Make:image("svg$","dvisvgm -n -p ${page} -c 1.4,1.4 -s ${source} > ${output}")

The build file is a Lua script, Make:image command provides command for image conversion. This command has two arguments, the first is configured image format (it is an regular expression, thus $ at the end), the second is template for conversion command. There are three important parameters, ${source} is name of the DVI file, ${page} is page number of the converted image and ${output} is name of the generated image.

You can compile your document using command

make4ht -c c.cfg test.tex

The build file is used automatically when it's named as the input TeX file with .mk4 extension.

Last comment regarding math quality: it would best to use mathml format, because images have also other issues apart from resolution (accessibility, mismatch between font sizes, they don't align with baseline, and probably many more). The issue with mathml is a poor browser support, which is virtually non-existent apart from Firefox. Mathjax add good support for it to all browsers, but I fully understand that you don't like that. There is a possibility to use Mathjax at the compile time. This method replaces mathml with portable HTML, which can then be displayed without Javascript. See Mathjax-node. Next version of Make4ht will provide option for this project.

  • Thanks for your help! I was not aware that htlatex had been replaced, but using dvisvgm this way solves the problem. As far as dislike of MathJaX, for most documents it would be fine, but this one has too much going on (obviously the 2 1/2 was just an example xD) and it needs to display on old PC's fast. The MathJax compile time was way too long. For accessibility...yeah SVG is a bummer, but could just put the MathML in between Aria code saying not to display, right? – Fredrick Brennan Feb 2 '17 at 1:38
  • @FredrickBrennan I meant using MathJax at compilation time, the resulting document looks like if MathJax was used, but it doesn't use any JavaScript at all. – michal.h21 Feb 2 '17 at 13:57
  • Ah, OK, I understand. That would also work. Thanks again for the help. :) – Fredrick Brennan Feb 3 '17 at 1:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.