cl-projects.de
 
Bauteile-Verwaltung part-db
Tools
Laminator-Umbau

Verschiedenes
miscellaneous stuff

ExportOverpic.py

An Inkscape Extension for LaTeX overpic

December 2015

Introduction

Mathematical symbols in Figures are a crucial part of scientific communication, especially in the Sciences. The document is usually prepared using LaTeX, but it is not straightforward to benefit from its superior math typesetting capabilities in figures prepared with an external program. On the other hand, one would like to prepare the figures with a graphics program such as Inkscape. However, it is challenging to use mathematical expressions in the figure.

The LaTeX package overpic addresses this dilemma. After import of the graphics file LaTeX expressions can put anywhere on the figure. Determining the positions of these snippets is usually an extra task that might require many builds of the LaTeX document. So it would be desirable that everything is generated from one file. These points motivated the creation of the Inkscape extension ExportOverpic.py.

Workflow

In Inkscape, select all text objects you would like to be generated in the LaTeX run. Then from the Extensions menu, choose "Export", "Export text for overpic". The extension prepares \put commands to be put in the overpic environment. A window pops up, displaying the generated commands. Copy these to your clipboard and paste them in the LaTeX document at the appropriate position.

For instance, the LaTeX file from which the example document is generated, reads

\begin{figure}
        \centering
        \begin{overpic}[width=0.7\textwidth]{exportoverpic_example_img.pdf}
                \input{exportoverpic_example_img.tex}
        \end{overpic}
        \caption{Figure composed from the PDF in Fig.\,\ref{fig:file_allbutmath}
           and the \LaTeX\ commands. This is the final result.}
        \label{fig:final_result}
\end{figure}
The file exportoverpic_example_img.tex contains the commands prepared by the Inkscape extension:
\put(75.000002,3.333334){\makebox(0,0)[b]{$b$}}
\put(94.166671,10.833333){\makebox(0,0)[b]{$x$}}
\put(33.333333,3.333334){\makebox(0,0)[b]{$a$}}
\put(56.666670,9.999999){\makebox(0,0)[b]{$\int\limits_a^b dx\,f(x)$}}
\put(8.333334,46.666668){\makebox(0,0)[b]{$f(x)$}}
The makebox command is used for relative aligning the LaTeX text w.r.t. the coordinates in the put statement. These coordinates track changes in the Inkscape document, so you don't have to change them manually.

Next, export the Figure as PDF without the text just prepared for LaTeX. It is handy to have these on a separate layer which you can switch of prior to writing the PDF.

An example

The screenshots are from the example document. The complete source material for Inkscape and LaTeX is in the downloadable archives.
Contents of the Inkscape .svg file. The contents of the text fields is the LaTeX input, the position of the text fields is used to control where LaTeX puts its output.
PDF export from Inkscape. This is the basis that will have the LaTeX material put on it.
The final result after processing with pdflatex.

Downloads

Note: Although this software works for me, it is still considered alpha software. I release it without any warranty, so use it at your own risk.
  • Version 0.1 of the ExportOverpic.py extension for Inkscape (ZIP, tarball)
  • The example document (source material to build it with pdflatex is included in the archives)
  • Another example document illustrating the different ways to position the text (source material to build it with pdflatex is included in the archives)

Installation

This extension is installed as any other Inkscape extension, that is put the ExportOverpic.py and ExportOverpic.inx files in the extensions directory of your Inkscape installation. It has been verified to work on Windows and Linux (Inkscape 0.48r5).

FIXME: to be finished.

Links

  • Homepage of the Inkscape project, an open source vector graphics program

Impressum