title | author |
---|---|
Adoverpic - extracting LaTeX overpic commands from tags in .eps files |
Jaap-Henk Hoepman |
A clean way to include LaTeX typesetting (e.g. equations) within figures is the overpic
package. For example
\begin{figure}
\begin{overpic}[abs,unit=1mm]{figure.eps}
\put(0,39){\f}
\end{overpic}
\end{figure}
takes the .eps figure in figure.eps
and overlays the output of the (elsewhere defined) LaTeX command \f
on top of that figure at the coordinates
It would be nice to be able to automatically generate the coordinates (and the LaTeX commands) from the figures themselves. That is to say: it would be nice to be able to add special strings (called tags) that signal that the string in question should be interpreted as a LaTeX command, whose output should be put at the location where the tag appears in the figure. Moreover, the tags themselves should be removed from the figure (so that they do not interfere with the output generated by the LaTeX commands).
Affinity Designer, when exporting a figure in encapsulated postscript (using EPS (for export) mode), generates the outlines for each text string in the figure prepended with a comment containing the text string itself. For example, when the figure contains the text string .tag
, part of the exported encapsulated postscript output looks like
% .tag
1.13 2.525 m
1.13 2.525 1.13 3.727 1.13 3.727 c
1.13 3.727 2.331 3.727 2.331 3.727 c
where the first line (1.13 2.525 m
) specifies the coordinates of the start of
the string, i.e. the dot (in units that almost (!) correspond to LateX's pt
).
In Encapsulated Postscript, there are 72 points to an inch whereas TeX/LaTex have 72.27 points to an inch (The TeXbook, page 57).
Adoverpic processes an encapsulated postscript file generated by Affinity Designer (in EPS (for export) mode) and searches for all occurrences of tags.
Such tags are text strings that start with a period (.
). It creates a
corresponding overpic \put
command for these strings (using the coordinates
found on the next line of the encapsulated postscript file), transforming the
string into a LaTeX command by replacing the period with a slash. It also
converts the coordinates in EPS points to LaTeX points. It writes these put commands to an output file. For the encapsulated postscript file above it would generate the output
\put(1.13,2.525){\tag}
Adoverpic also creates a copy of the input, but with all postscript code used to render the curves corresponding to the command strings found removed. Note that tags can be complex calls to LateX commands including parameters, as long as they do not contain whitespace.
To be precise, a line on the input that starts with % .
followed by at least one non-whitespace character is considered to be a LaTeX command that needs to be converted to an overpic \put
command. All non-whitespace characters following the period (up to the first whitespace character, or a newline) are considered part of this LaTeX command. The next line of the input is assumed to contain two text strings (separated by a single space) that represent the real-valued x-coordinate and the y-coordinate respectively, in points.
Run adoverpic as follows:
adoverpic <eps-in-file> <eps-out-file> <overpic-out-file>
This processes the input file <eps-in-file>
and transforms all tags to corresponding overpic commands written to <overpic-out-file>
. The filtered output is stored in <eps-out-file>
. Adoverpic output is typically used as follows within a LaTeX document:
\begin{figure}
\begin{overpic}[abs,unit=1pt]{<eps-out-file>}
... <definitions> ...
\input{<overpic-out-file>
\end{overpic}
\end{figure}
Tested with the following version(s) of Affinity Designer
- 1.7.3
- 1.8.1
adoverpic is released under the MIT license.