16

Is there a way to directly compile TeX code into the SVG image format (rather than going the detour over TeX => PDF => SVG)?

I found this question: Convert LaTeX to SVG online

But I don't want to do it online - it should be a command-line call.

  • Perhaps download.cnet.com/Free-PDF-to-SVG-Converter/… . Google may find other downloadable tools. – Ethan Bolker Jul 15 '15 at 13:41
  • 1
    inkscape --without-gui --file=input.pdf --export-plain-svg=output.svg (stackoverflow.com/a/10290006/2442087) – giordano Jul 15 '15 at 13:43
  • 2
    Yeah, I know these solutions. I'm currently using pdf2svg-0.2.2. But I was hoping for a direct tex-to-svg solution... – lukas.coenig Jul 15 '15 at 14:33
  • 2
    ok, i'll elaborate a little: i compile the latex code from inside a servlet. the output is sent to the user as a svg figure in a web page. using tex=>pdf=>svg works in principle, but is more costly in terms of server resources than i assume a single step would be. also, sometimes pdflatex doesn't terminate. i'm looking into the reason for this, but was hoping to avoid the debugging by simply avoiding pdf. – lukas.coenig Jul 15 '15 at 16:31
  • 2
    Does batchmode help to avoid the termination problem? See this question – Jost Jul 15 '15 at 17:05
7

One can use mathjax-node-cli in combination with node.js for doing so.

(X)Ubuntu LTS requires only two easy installation steps:

$ sudo apt-get install nodejs-legacy npm
$ sudo npm install --global mathjax-node-cli

If you use node with NVM, the path is going to be different:

type node

Will help you. And the command

/usr/local/lib/node_modules/mathjax-node-cli/bin/tex2svg '\sin^2{\theta} + \cos^2{\theta} = 1' > test.svg

will yield:

tex2svg output, rasterised at 300 dpi

The generated SVG file renders properly inside a browser but cannot be displayed using standard image tools.

To generate from a file:

cat YOURSOURCEFILE.tex | xargs -0 -t -I % /usr/local/lib/node_modules/mathjax-node-cli/bin/tex2svg '%' > YOURENDFILE.svg
  • 1
    You may need to use sudo npm install --global mathjax-node-cli and /usr/local/lib/node_modules/mathjax-node-cli/bin/tex2svg '\sin^2{\theta} + \cos^2{\theta} = 1' > test.svg now – omnomnom Feb 14 '18 at 14:40
6

You can use classical LaTeX (with dvi output) and dvisvgm ( http://www.ctan.org/pkg/dvisvgm ) to convert the dvi file to SVG.

EDIT: I am not aware of a *svgtex implementation that does the conversion in one step.

  • 2
    Could you explain, why going via DVI is an improvement over going via PDF? – Jost Jul 15 '15 at 16:16
  • 1
    @Jost Frankly, no, but the OP asked for a pdf-free way to achieve his goal. – jknappen Jul 15 '15 at 16:17
  • Not me but the OP asked the question. I'm just curious. – Jost Jul 15 '15 at 16:29
  • i (the "OP", i assume - what does it mean anyway?) elaborated above why i looked for a pdf-free method. i'll certainly try your suggestion using dvi - thanks for that! However, i'm starting to feel that pdflatex is not the real problem, and i'll run into the same trouble with dvi... – lukas.coenig Jul 15 '15 at 16:34
  • 2
    @lukas.coenig OP is our slang for "original poster" – jknappen Jul 15 '15 at 16:36

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.