# pgf-umlsd and externalize

What would be the best solution to make pgf-umlsd and externalize compatible?

The latter expects \end{tikzpicture} which is "hidden" within sequencediagram environment the first provides. I guess I could convert beginning and the ending of the environment into two commands explicitly invoked at the beginning and ending of the tikzpicture environment meant to be sequence diagram, but it wouldn't survive pgf-umlsd.sty update (i.e. changing environment definition), requiring copy-paste to be redone.

Is there any clever way to solve this problem with as minimal effort as possible and avoiding any copy-pasting?

Should the package author be convinced to provide some begin-like and end-like commands for use within tikzpicture environment?

\documentclass{minimal}
\usepackage[paperwidth=48mm,paperheight=36mm,margin=0pt]{geometry}
\usepackage{parskip}
\usepackage{tikz}
\usepackage{pgf-umlsd}
\usetikzlibrary{external}
%\tikzexternalize
% uncommenting above line gives following error:
% ! File ended while scanning use of \tikzexternal@laTeX@collect@until@end@tikzpicture.
\begin{document}
\null\vfill
\begin{sequencediagram}
\newinst[1]{b}{B}
\begin{call}
{a}{call}
{b}{return}
\end{call}
\end{sequencediagram}
\vfill
\end{document}


Let's assume for a moment that author provides three macros (or: we changed pgf-umlsd.sty ourselves):

• \sdinit - layers declaration, required before starting tikzpicture
• \sdbegin - sequence diagram header for use at the beginning of tikzpicture
• \sdend - sequence diagram footer for use at the end of tikzpicture

Modifying above listing to use them:

\sdinit
\begin{tikzpicture}
\sdbegin
...
\sdend
\end{tikzpicture}


makes externalize happy, but the output is different.

Right part of the rightmost box shadow disappeared. Why? What would be the best way to fix it?

-
Bonus question: Why the diagram is not in the middle of the page? What I have forgot about? –  przemoc Feb 16 '13 at 23:42
Crippled shadow problem is related to a bounding box not covering all TikZ drawings. See TikZ External: Figure gets cropped. In this case adding \useasboundingbox ([shift={(0.2,0)}]current bounding box.east); before ending tikzpicture environment solves the problem. (I used 0.2 because it's a value used internally in pgf-umlsd as the offset of the first box, thus I get external PDF with symmetrical margins.) –  przemoc Feb 17 '13 at 11:43
To your bonus question: use \begin{figure}\centering\begin{tikzpicture/sequencediagram}...\end{tikzpicture/‌​sequencediagram}\end{figure} –  LaRiFaRi Jul 26 '13 at 17:43
@przemoc Self answering a question is good. Can you provide an answer, if you have solved the problem? Otherwise, please update the question. –  egreg Dec 7 '13 at 21:14