# How to use tikz-timing together with the external library

I would like to generate a tikz-timing signal in my LaTeX document and to save it, using external library as pdf file.

Here is an example of a combine code:

\documentclass[border=5pt]{scrbook}
\usepackage{tikz-timing}
\usetikzlibrary{external}
\tikzexternalize[
figure list=true,
prefix=./]
\usetikztiminglibrary{nicetabs} % a bit strange with \Huge; use belowrulesep to adjust

\begin{document}
\begin{figure}
\begin{tikztimingtable}
& 4L      \\
& 4H      \\
& 2LCH    \\
& [C]CCCC \\
& 2{2C}   \\
\extracode
\tablegrid[black!25,step=1]
\end{tikztimingtable}
\end{figure}
\end{document}


the error that i get is:

Opening 'test.figlist' for writing.
**Writing './signal1' to 'test.figlist'.
)
Runaway argument?
\par
! File ended while scanning use of \tikzexternal@laTeX@collect@until@end@tikzpi
cture.
<inserted text>

-
Note that the border class option is just for standalone. With scrbook it is ignored. –  Martin Scharrer May 3 '12 at 22:18

The tikztimingtable is unfortunately not compatible with the external library. The \texttiming and \timing macros will work however. The reason for the incompatibility is because the tikzpicture is nested inside tikztimingtable which is not supported by external as described in section 32.2 Requirements of the v2.10 TikZ/PGF manual. The error occurs because the external library can't find the \end{tikzpicture} because it is inside the \end{tikztimingtable}.

One workaround to avoid errors is to disable the externalization for tikztimingtables as described in e.g. tikzexternalize only (or not) for flagged graphics. You can add a \tikzexternaldisable macro inside the figure before the tikztimingtable. However, then you will get this benefit only for other tikzpictures. If you only have tikztimingtables you can avoid using external altogether.

\documentclass{scrbook}
\usepackage{tikz-timing}
\usetikzlibrary{external}
\tikzexternalize[
figure list=true,
prefix=./]
\usetikztiminglibrary{nicetabs} % a bit strange with \Huge; use belowrulesep to adjust

\begin{document}
\begin{figure}
\tikzexternaldisable
\begin{tikztimingtable}
& 4L      \\
& 4H      \\
& 2LCH    \\
& [C]CCCC \\
& 2{2C}   \\
\extracode
\tablegrid[black!25,step=1]
\end{tikztimingtable}
\end{figure}
\end{document}


An alternative to external is the standalone class and package. With this you must place the code in question in an file of its own, where you can have a full preamble. This file can then be compiled by itself, i.e. standalone, which is very nice for larger pictures which must be recompiled often during the creation process. With the standalone package you can then include the standalone file without removing the preamble. It also allows automatic generation of PDF images from the standalone files. See the manual and search for mode.

% main document
\documentclass{scrbook}
\usepackage[mode=buildnew]{standalone}
\usepackage{tikz-timing}
\usetikztiminglibrary{nicetabs} % a bit strange with \Huge; use belowrulesep to adjust

\begin{document}
\begin{figure}
\includestandalone{sometttable}
\end{figure}
\end{document}

% sometttable.tex
\documentclass{standalone}
\usepackage{tikz-timing}
\usetikztiminglibrary{nicetabs} % a bit strange with \Huge; use belowrulesep to adjust

\begin{document}
\begin{tikztimingtable}
& 4L      \\
& 4H      \\
& 2LCH    \\
& [C]CCCC \\
& 2{2C}   \\
\extracode
\tablegrid[black!25,step=1]
\end{tikztimingtable}
\end{document}

-