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.
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.
tex2svgThe command tex2svg becomes available once mathjax-node-cli in combination with node.js is installed.
With (X)Ubuntu LTS, this requires only two installation steps:
$ sudo apt install nodejs npm
$ sudo npm install --global mathjax-node-cli
The command:
$ /usr/local/lib/node_modules/mathjax-node-cli/bin/tex2svg '\sin^2{\theta} + \cos^2{\theta} = 1' > test.svg
will yield:
Note 1: If node is used with NVM, the path may be different. The path can be found with:
$ type node
/usr/bin/node
Note 2: The generated SVG file renders properly inside a browser but cannot be displayed using standard image tools.
Note 3: Generating SVG from a TeX file can be done as follows:
$ cat YOURSOURCEFILE.tex | xargs -0 -t -I % /usr/local/lib/node_modules/mathjax-node-cli/bin/tex2svg '%' > YOURENDFILE.svg
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
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.
xelatex --no-pdf producing extended DVI (file ending xdv) and subsequent conversion to SVG with dvisvgm.
– AlexG
Nov 26 '18 at 10:09
In my windows, this works,
Install:
Then add the "bin" folder to path.
For example, I add "C:\Program Files\Inkscape\bin" and "C:\Program Files\gs\gs9.54.0\bin" to the user path.
If you have a "document.tex" file, then
pdflatex document.tex
gswin64 -dNoOutputFonts -sDEVICE=pdfwrite -o tmp.pdf document.pdf
inkscape -o document.svg tmp.pdf
Here gswin64 can convert the text to path, avoid the font error when inkscape convert to svg. Although the inkscape has "-T" option that convert text to path, however, this doesn't work sometimes expectially when you are use tikzpicture.
Here's a command line tool to convert mathematical expressions in tex to svg (via pdflatex and pdf2svg): https://github.com/yannikschaelte/tex2svg
Example usage:
tex2svg '$\exp(i\cdot\pi) + 1 = 0$' out.svg
(Disclaimer: I'm the author, so likely biased.)
inkscape --without-gui --file=input.pdf --export-plain-svg=output.svg(http://stackoverflow.com/a/10290006/2442087) – giordano Jul 15 '15 at 13:43batchmodehelp to avoid the termination problem? See this question – Jost Jul 15 '15 at 17:05pdflatex --interaction=batchmode --halt-on-errorshould resolve the not terminating. – MaxNoe Mar 02 '17 at 18:50