Getting good-looking diagrams and figures into a LaTeX document can be tricky. My favourite software (and I think it ought to be anyone's favourite) for drawing such figures is Inkscape. This post explains how to get text in the proper font into Inkscape, how to put equations into Inkscape drawings, and how to get those drawings out of Inkscape and into your LaTeX document.
It is a good idea to use the latest version of Inkscape, because the program is rapidly being improved all the time.
LaTeX font in Inkscape
To make your figure look good in its environment, you can use the same font family that the surrounding body text uses. In LaTeX's case: Computer Modern.
As Computer Modern is written in the METAFONT format, it cannot be directly used in Inkscape. For that, we need the font in OpenType (OTF) format, preferred for Linux (and MacOS?) systems, or in TrueType (TTF) on Windows. (Side note: here's an interesting article on the differences between all the font formats.)
The BaKoMa font bundle provides the Computer Modern font in these and some more formats. Download it here, then extract to a temporary directory. Installation is as follows:
- Open up Fonts in the Control Panel and drag-and-drop all files from the ttf directory into here.
- Ubuntu Linux
- Open a file browser (Nautilus) and navigate to fonts://, then drop the fonts from the otf directory here. You may need to run Nautilus as root using the command
- Non-Ubuntu Linux (and Ubuntu Hardy, because they broke it)
- Copy the files (as root) from the otf directory to anywhere you like inside /usr/share/fonts, then run
sudo fc-cache -fv. (For a single-user installation, ~/.fonts might work, but no guarantees!)
Creating the figure
If you start Inkscape, new fonts with names like BKM-cmr10 should be available. Here, cm stands for Computer Modern, r means roman (normal body-text font) and 10 is the point size. Simply use this font for all the text in your illustrations to make them integrate seamlessly with the text in LaTeX.
Or, almost seamlessly. It seems that Inkscape (version 0.46) does something strange with the font size, or the BaKoMa fonts are too small to begin with. In any case, I find that using BKM-cmr10 at 12 points in Inkscape provides the best match to the default 10-point LaTeX body font. I personally prefer BKM-cmss10, the sans-serif version of Computer Modern, because it integrates nicely with abstract line drawings and with the surrounding serif body text, but if you use mathematics in you figures this is probably not an option.
LaTeX equations into Inkscape
Yes, it is possible to add mathematical symbols and equations to your Inkscape drawing! You can also use this for normal text, but it is more cumbersome than the font approach detailed above.
First, you need textext. Simply extract the two files from the archive into /usr/share/inkscape/extensions for a systemwide installation, and fix the permissions:
sudo chmod 644 textext.inx
sudo chmod 755 textext.py
(For a single-user installation, ~/.inkscape/extensions should work.)
You'll need some extra packages for the script to work. On Ubuntu:
sudo apt-get install python-lxml
sudo apt-get install pstoedit
On non-Debian based Linux distributions, install pstoedit and the Python lxml package in some other way. On Windows, see the textext web page for details.
Now (re)start Inkscape, click Effects, Tex Text and type your LaTeX code! You can even load a preamble from a file to include additional packages such as amsmath. (Unfortunately the file must contain only the preamble, not an entire document.) The same problem occurs as with the previous approach: you need to set a scale factor of 1.25 to (approximately) match the font size of the LaTeX document. Close the dialog with the OK button or with Ctrl+Enter.
The equation (or other LaTeX text) is then placed as a group of shapes into Inkscape. To edit it (yes, that is possible!), select it and click Effects, Tex Text again. This feature is a little feeble, however: do not ungroup the text object, or else it will become uneditable.
From Inkscape to LaTeX
Exporting from Inkscape
When the figure is done, deselect all objects, then go to Document Properties and click Fit page to selection. This will adjust the page boundaries to fit exactly around all objects. Then save the figure to Inkscape SVG format (for later editing), but also save a copy as “PDF via Cairo”. Check the box to Convert text to paths, because otherwise the kerning seems to be messed up in the export.
Including in LaTeX
This is a simple matter of
in the preamble, and then placing the figure using
as usual. Do not use any of the scaling options of
\includegraphics, since they will cause the text in the figure to scale as well, and it will no longer match the size of the surrounding body text.
Compile your LaTeX document using
pdflatex (not normal
latex, since that only handles inclusion of EPS files), and there you go!