1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
\documentclass[11pt]{article}
\usepackage[T1]{fontenc}%
\usepackage{libertine}%
\usepackage{booktabs}%
\usepackage{tabularx}%
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage[margin=0.85in,letterpaper]{geometry}
\usepackage[scaled=0.9]{inconsolata}
\usepackage{listings}
\definecolor{lightgrey}{rgb}{0.9,0.9,0.9}
\definecolor{darkgreen}{rgb}{0,0.6,0}
\definecolor{darkred}{rgb}{0.6,0,0}
\definecolor{myblue}{RGB}{20,105,176}
\definecolor{darkgreen}{rgb}{0,0.6,0}
\lstdefinelanguage{mytex}[LaTeX]{TeX}{
columns=flexible,
frame=single,
framerule=0pt,%
backgroundcolor=\color{gray!10},%
xleftmargin=\fboxsep,%
xrightmargin=\fboxsep,
alsoletter={\\,*,\&},
morekeywords={\\AtBeginDocument,
\\RequirePackage,
\\PreviewEnvironment,
\&},
morekeywords=[2]{pspicture,
verbatim,
table,
other,
tikzpicture,
postscript,
preview,
TRICKS,
POSTRICKS,
TIKZPICTURE,
OTHER,
nopreview},
morekeywords=[3]{\\begin,
\\pspicture,
\\TRICKS,
\\ENDTRICKS,
\\endpspicture,
\\end},
literate=*{\{}{{\textcolor{myblue}{\{}}}{1}
{\}}{{\textcolor{myblue}{\}}}}{1}
{[}{{\textcolor{myblue}{[}}}{1}
{]}{{\textcolor{myblue}{]}}}{1},
}
\lstset{language=mytex}
\lstdefinestyle{mystyle1}{
basicstyle=\small\ttfamily,
keywordstyle=\bfseries\color{red},
keywordstyle=[2]{\color{magenta}},
keywordstyle=[3]{\color{blue}},
commentstyle=\color{darkgreen},
stringstyle=\color{orange},
identifierstyle=\ttfamily,
showstringspaces=true,
breaklines=true,
tabsize=4,
columns=fullflexible,
keepspaces=true,
}
\lstset{style=mystyle1}
\begin{document}
\title{{\huge\textsf{lxtimg}}\\export tikz|pstricks environments to image format\\ \small v. 1.0}
\author{Pablo Gonz\'{a}lez Luengo\\ \small \ttfamily pablgonz at yahoo dot com}
\date{\today}
\maketitle
\begin{abstract}
\noindent
\textsf{ltximg}\footnote{Thanks to Giuseppe Matarazzo for his kind help on testing the script.} is a \textsf{Perl} script that automates the process to export \textsf{tikzpicture} or \textsf{pspicture} environments to image formats (PDF, EPS, PPM, PNG).
\end{abstract}
\tableofcontents
\section{Required Software}
For the full operation of the script you need the following opensource programs
(available for windows and linux), external to \textsc{ctan} repositories.
\begin{itemize}
\item \textsf{Perl}.
\item \textsf{Ghostscript}.
\item \textsf{pdftops} (optional, for images in EPS format).
\item \textsf{pdftoppm} (optional, for images in PPM format).
\item \textsf{ImageMagick} (optional, for conversion images).
\end{itemize}
\newpage
\section{Run and options}
For \TeX Live or Mik\TeX\ users the syntax for \textsf{ltximg} script is simple:
\begin{lstlisting}
perl ltximg file.tex -options
\end{lstlisting}
\begin{table}[htp]
\caption{Options for ltximg}
\begin{tabularx}{\linewidth}{@{}>{\ttfamily} l>{\ttfamily} l >{\ttfamily}l X @{}}\\\toprule
\emph{name} & \emph{short} & \emph{default} & \emph{description}\\\midrule
--help & --h & & display help information and exit.\\
--version & --v & & display version information and exit.\\
--license & --li & & display license information and exit.\\
--imageDir= & & images & The dir for the created images.\\
--DPI= & --d & 300 & Dots per inch for gs, pdftoppm and mogrify.\\
--IMO="..." & & & Aditional options for mogrify (need double quotes).\\
--clear & --c & & Delete all temp files.\\
--xetex & --xe & & Create all image using xelatex (tikz and pstricks).\\
--luatex & --lu & & Create all image using lualatex (tikz).\\
--latex & --la & & Create all image using latex(pstricks).\\
--useppm & --up & & Create jpg and png using mogrify and ppm\\
--usemog & --um & & Create jpg and png (transparent) using mogrify and pdf\\
--margins= & --m & 0 & Margins for pdfcrop.\\
--pdf & & & Create .pdf files using gs.\\
--ppm & & & Create .ppm files (need pdftoppm).\\
--eps & & & Create .eps files (need pdftops).\\
--jpg & & & Create .jpg files (deafult use gs).\\
--png & & & Create .png files (deafult use gs).\\
--skip= & --s & skip & Name for skip environmet in input file.\\
--other= & --o & other & Name for other export environmet.\\
--all & --a & & Create pdf/jpg/png/eps image type.\\
\bottomrule
\end{tabularx}
\end{table}
\section{How it works}
The script works in two steps, but giving the same result, a new file
\emph{without tikzpicture} environments and a folder with the images from
these environments.
\subsection{Comment and ignore}
The first step \textsf{ltximg } script create a image dir calls \textsf{images}
and create a copy for in file, processing is as follows, being assumed that our file is \texttt{test.tex}:
\begin{enumerate}
\item Create a copy file called test-tmp.tex and put the problematic environments (verbatim, verbatim\*, lstlisting,
LTXexample, Verbatim, comment, alltt, minted, tcblisting, xcomment and skip) inside the:
\begin{lstlisting}
\begin{nopreview}
...
\end{nopreview}
\end{lstlisting}
and:
\begin{enumerate}
\item If the option is latex adds the following lines to the beginning of the test-fig.tex:
\begin{lstlisting}
\AtBeginDocument{
\RequirePackage[active,tightpage]{preview}
\PreviewEnvironment{pspicture}
\PreviewEnvironment{other}}
\end{lstlisting}
\item If options its xetex adds the following lines to the beginning of the test-fig.tex:
\begin{lstlisting}
\AtBeginDocument{
\RequirePackage[xetex,active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\PreviewEnvironment{pspicture}
\PreviewEnvironment{other}}
\end{lstlisting}
\item And if no option is given, adds the following lines at the beginning of the test-fig.tex. This is the default for
lualatex and pdflatex.
\begin{lstlisting}
\AtBeginDocument{
\RequirePackage[pdftex,active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\PreviewEnvironment{other}}
\end{lstlisting}
\end{enumerate}
\item Open test-tmp.tex and change the problematic words for verbatin in line or after \% symbol:
\begin{lstlisting}
\pspicture => \TRICKS
\endpspicture => \ENDTRICKS
\begin{pspicture => \begin{TRICKS
\end{pspicture => \end{TRICKS
\begin{postscript} => \begin{POSTRICKS}
\end{postscript} => \end{POSTRICKS}
\begin{tikzpicture => \begin{TIKZPICTURE
\end{tikzpicture => \end{TIKZPICTURE
\begin{other => \begin{OTHER
\end{other => \end{OTHER
\end{lstlisting}
and save file called test-fig.tex then runs (pdf/lua/xe)latex in \texttt{test-fig.tex} and \textsf{pdfcrop} in
\texttt{test-fig.pdf}.
\end{enumerate}
\subsection{Split and convert}
If \textsf{ltximg} called with option \textsf{-pdf} or \textsf{-eps} or \textsf{-um} the file \texttt{test-fig.pdf}
is splitting in \texttt{test-fig-1.pdf, test-fig-2.pdf,\ldots} and puts them into \texttt{images} dir. The invoked behind this command is:
\begin{lstlisting}
gs -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -dNOPAUSE -dBATCH -sOutputFile=imageDir/test-fig-%d.pdf \
test-fig.pdf
\end{lstlisting}
and then processes the remaining options.
For example, if you use the option \textsf{-pdf -um} the command behind this is:
\begin{lstlisting}
mogrify -define png:format=png32 -define png:compression-filter=4 -quality 100 -transparent white \
-density 300 -format png *.pdf
\end{lstlisting}
And if you use the option \textsf{-pdf -up} the command behind this is:
\begin{lstlisting}
mogrify -quality 100 -define png:format=png32 -define png:compression-filter=4 -density 300 \
-format png *.ppm
\end{lstlisting}
\section{Creating other images format}
If you need to create other image formats we first need to generate the PPM format or PDF, then the procedure is simple
using the \textsf{ImageMagick} \texttt{convert} command, command usage is so:
\begin{lstlisting}
mogrify -format ext *.ppm
\end{lstlisting}
for TIFF use
\begin{lstlisting}
mogrify -format tiff *.ppm
\end{lstlisting}
\end{document}
|