Graphics and LaTeX

I’ve been using TeX/LaTex for many years and have observed at close hand how LaTeX has evolved with the addition of new editors, bibliography support and particularly support for graphics. In my book “Enzyme Kinetics for Systems Biology”, I use three mechanisms for including illustrations. The first is simply to use \includeGraphics to include an external file. I use pdflatex exclusively now and in this case I include external pdf files into the document. For example the following LaTeX snippet will include the external pdf file called “externalPdfFile”. includeGraphics has a lot of flexibility for scaling the image, rotating the image etc.

\begin{figure}[htb]
\begin{center}
\includegraphics[scale = 0.5]{externalPdfFile}
\caption{Include an external pdf file into the document.}
\label{fig:externalPdfFile}
\end{center}
\end{figure}

Pdf illustrations can be either produced by commercial products such as Adobe Illustrator or open source offerings such as Inkscape.

A modern TeX/LaTeX based solution to illustrations and data graphing is PGF/Tikz and PGFPlot. Both these tools are extremely useful for creating diagrams and data plots. The example below illustrates a simple plot generated using pdfplot showing the difference between a hyperbolic and sigmoidal response. The advantage, as least I see it as an advantage, to using something like PGFPlot, it that the information to generate the plot can be embedded in the text itself. Now I know many will say it is good practice to separate presentation from content but from my point of view including them in the same file save a lot of trouble. The code itself is given below the graph.

\begin{tikzpicture}
\begin{axis}[
xlabel={Substrate Concentration},
ylabel={Reaction Rate},
xmin=0, xmax=3,
ymin=0, ymax=1,
width=8cm, height=6cm]
\addplot[color=orange,line width=1.5pt] expression[domain=0:3,samples=20]{x^4./(1+x^4.)};
\addplot[color=blue,line width=1.5pt] expression[domain=0:3,samples=20]{x/(0.3+x)};
\end{axis}
\end{tikzpicture}

PGFPlot is based on PGF/Tikz. PGF/Tikz is itself a general purpose illustration package for LaTeX or TeX. PGF is the low-level language component, while Tikz is a set of higher-level calls to PGF. For most users the Tikz layer (now at version 2.10) is the most appropriate to use. The Tikz manual (over 700 pages) is one of the best manuals I’ve come across, containing many examples and tutorials. The small biochemical network below was produced using Tikz. For those who use SBML (Systems Biology Markup Language), there is also the package SBML2Tilkz that can convert SBML models into ready to go Tikz files.

The code for the above diagram is given here:

\begin{tikzpicture}
\draw(38pt,50pt) node[anchor=west] {$S_1$};
\draw(102pt,50pt) node[anchor=west] {$S_2$};

\draw[-stealth,color=blue,very thick] (50pt,60pt) to [controls=+(50:1) and +(130:1)] (110pt,60pt);
\draw[stealth-,color=blue,very thick] (50pt,40pt) to [controls=+(130:-1) and +(50:-1)] (110pt,40pt);

\draw[-stealth,color=blue,very thick] (50pt,93.5pt) to [controls=+(130:-1) and +(50:-1)] (110pt,93.5pt);
\draw[stealth-,color=blue,very thick] (50pt,6.5pt) to [controls=+(50:1) and +(130:1)] (110pt,6.5pt);

\draw(72pt,15pt) node[anchor=west] {$v_1$};
\draw(72pt,85pt) node[anchor=west] {$v_2$};

\draw(36pt,100pt) node[anchor=west] {$A$};
\draw(105pt,100pt) node[anchor=west] {$B$};

\draw(36pt,0pt) node[anchor=west] {$D$};
\draw(105pt,0pt) node[anchor=west] {$C$};
\end{tikzpicture}

Note that the WordPress QuickLaTex allows one to embed PGFPlot or Tikz code in the WordPress page itself although it can be a bit slow to render. The above figures were in fact rendered first using QuickLaTeX then png copies were extracted using “right-click” and “Save image as”. The images were then inserted into the WordPress page. This significantly improved the rendering speed.

This entry was posted in LaTeX, Publishing. Bookmark the permalink.

One Response to Graphics and LaTeX

  1. @”The above figures were in fact rendered first using QuickLaTeX then png copies were extracted using “right-click” and “Save image as”.”

    QuickLaTeX does this automatically. It renders image only once (which can be slow), and stores generated image on the user’s web server in wp-content\ql-cache. On subsequent page visits QuickLaTeX uses cached image without re-rendering.

    This feature is enabled by default, check switch “QuickLaTeX->System->Cache images locally.” Also check permissions for ql-cache folder, it should be writable chmod 777 will do the trick.

    Thank you for promoting QuickLaTeX!

Leave a Reply

Your email address will not be published.