Usage: make
will yield pdf for all SVG file in the directory. make png
will rasterize them to png
Created
June 2, 2016 17:23
-
-
Save arthurmensch/634884e52d7852586fd1171179e7fa6a to your computer and use it in GitHub Desktop.
SVG + latex to png/pdf converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%!TEX root = modl_tsp.tex | |
\def\EE{{\mathbb E}} | |
\def\RR{{\mathbb R}} | |
\def\PP{{\mathbb P}} | |
\def\x{{\mathbf x}} | |
\def\f{{\mathbf f}} | |
\def\e{{\mathbf e}} | |
\def\c{{\mathbf c}} | |
\def\n{{\mathbf n}} | |
\def\v{{\mathbf v}} | |
\def\A{{\mathbf A}} | |
\def\B{{\mathbf B}} | |
\def\C{{\mathbf C}} | |
\def\D{{\mathbf D}} | |
\def\E{{\mathbf E}} | |
\def\F{{\mathbf F}} | |
\def\I{{\mathbf I}} | |
\def\L{{\mathbf L}} | |
\def\M{{\mathbf M}} | |
\def\N{{\mathbf N}} | |
\def\R{{\mathbf R}} | |
\def\T{{\mathbf T}} | |
\def\U{{\mathbf U}} | |
\def\V{{\mathbf V}} | |
\def\X{{\mathbf X}} | |
\def\Y{{\mathbf Y}} | |
\def\b{{\mathbf b}} | |
\def\a{{\mathbf a}} | |
\def\d{{\mathbf d}} | |
\def\q{{\mathbf q}} | |
\def\u{{\mathbf u}} | |
\def\x{{\mathbf x}} | |
\newcommand{\balpha}{\boldsymbol{\alpha}} | |
\newcommand{\bbeta}{\boldsymbol{\beta}} | |
\newcommand{\bGamma}{\boldsymbol{\Gamma}} | |
\newcommand{\bgamma}{\boldsymbol{\gamma}} | |
\newcommand{\bxi}{\boldsymbol{\xi}} | |
\def\trace{{\mathrm{Tr}\;}} | |
\def\sample{{\mathtt{sample}}} | |
\def\exactsurr{\mathcal{S}_{\rho, L}(f, \theta)} | |
\def\approxsurr{\mathcal{T}_{\rho, L}(f, \theta, \mu)} | |
\newcommand{\argmin}{\operatornamewithlimits{\mathrm{argmin}}} | |
\newcommand{\argmax}{\operatornamewithlimits{\mathrm{argmax}}} | |
\newcommand{\transpose}{^\top} | |
\newenvironment{sansfont}{\fontfamily{fvs}\selectfont}{\par} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SRC=$(wildcard *.svg) | |
OBJS_PDF=$(SRC:.svg=_latex.pdf) | |
OBJS_PNG=$(SRC:.svg=.png) | |
OBJS_PDF_TEX=$(SRC:.svg=.pdf_tex) | |
all: pdf | |
pdf: $(OBJS_PDF) | |
png: $(OBJS_PNG) | |
%.pdf_tex %.pdf: %.svg | |
inkscape -z -f $< --export-latex -A $*.pdf -C; \ | |
# This won't be useful once the bug is fixed | |
PAGES=$$(pdfinfo "$*.pdf" | grep Pages | cut -d" " -f11); \ | |
for j in $$(egrep "includegraphics.*page=" "$*.pdf_tex"); do\ | |
CHECKPAGE="$$(echo $$j | sed 's/^.*page=\([0-9]*\).*$$/\1/g')";\ | |
if [ $$CHECKPAGE -gt $$PAGES ]; then\ | |
sed -i 's/^.*includegraphics.*page='$$CHECKPAGE'.*$$//g' $<;\ | |
fi;\ | |
done | |
%_latex.pdf: %.pdf %.pdf_tex wrapper.tex | |
cp wrapper.tex wrapper_temp.tex; \ | |
sed -i 's/FILENAME/'$*'.pdf_tex/g' wrapper_temp.tex; \ | |
PAGEWIDTH=$$(pdfinfo "$*.pdf" | grep "Page size" | cut -d" " -f8); \ | |
sed -i 's/PAGEWIDTH/'$$PAGEWIDTH'/g' wrapper_temp.tex; \ | |
PAGEHEIGHT=$$(pdfinfo "$*.pdf" | grep 'Page size' | cut -d" " -f10); \ | |
sed -i 's/PAGEHEIGHT/'$$PAGEHEIGHT'/g' wrapper_temp.tex; \ | |
pdflatex wrapper_temp.tex; \ | |
mv wrapper_temp.pdf $@; \ | |
rm wrapper_temp.*; | |
%.png: %_latex.pdf | |
convert -density 600 $< $@ | |
clean: | |
echo 'clean';\ | |
rm -f *.pdf *.pdf_tex *.aux *.log *.png wrapper_temp.*; | |
.INTERMEDIATE: $(OBJS_PDF_TEX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{minimal} | |
\usepackage[margin=0pt, paperwidth=PAGEWIDTHpt, paperheight= PAGEHEIGHTpt]{geometry} | |
% *** Math | |
\usepackage{{color}} | |
\usepackage{amsmath} | |
\usepackage{amsfonts} | |
\usepackage[pdftex]{graphicx} | |
\renewcommand{\familydefault}{\sfdefault} | |
\input{commands.tex} | |
\def\svgwidth{.97\paperwidth} | |
\begin{document}% | |
\input{FILENAME} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment