Trace2UML can be used to visualize the call of macros in LaTeX documents. This is implemented by writing the corresponding Trace2UML commands in a .seq-file while compiling the LaTeX document. Therefore macros are needed to open (close) a new outputstream and to write the desired output to the .seq-file.
For the example in this article the following five macros have been used.
“Call”, “Return from” and “Create” a Macro
\newcommand{\entermacroseq}[1]{% \immediate\write\tracetouml{> #1}% }%
\newcommand{\leavemacroseq}{% \immediate\write\tracetouml{< }% }%
\newcommand{\createmacroseq}[1]{% \immediate\write\tracetouml{+ #1} }%
Open and Close a Write Stream
Place these macros at the beginning and end of the document respectively:
\newcommand{\openseqdiag}{% \newwrite\tracetouml% \immediate\openout\tracetouml=\jobname.seq% }%
\newcommand{\closeseqdiag}{% \immediate\closeout\tracetouml% }%
To automatically open and close, respectively, the outpustream add
\AtBeginDocument{\openseqdiag}% \AtEndDocument{\closeseqdiag}%
to the preamble of the document.
To demonstrate the basic idea the following LaTeX snippets show how to utilize these macros. First two new macros are defined:
\newcommand{\macroA}{% \entermacroseq{macroA}% \textbf{\macroB}% \macroB% \leavemacroseq% } \newcommand{\macroB}{% \entermacroseq{macroB}% \today, \thistime% \leavemacroseq% }
Next the following LaTeX code is compiled. Here macroA is called and then redefined and called a second time. Note that the outpustream is opened and closed automatically as described above.
\entermacroseq{Document} \macroA \createmacroseq{macroA} \renewcommand{\macroA}{ \entermacroseq{macroA} \textit{\macroB} \leavemacroseq } \\ \macroA \leavemacroseq
The picture below shows the resulting sequence diagram.
! Document 0003 ~ ==> Document ! macroA 0005 Document ==> macroA ! macroB 0007 macroA ==> macroB 0008 macroA <== macroB 0009 macroA ==> macroB 0010 macroA <== macroB 0011 Document <== macroA 0012 Document (!) macroA 0014 Document ==> macroA 0015 macroA ==> macroB 0016 macroA <== macroB 0017 Document <== macroA 0018 ~ <== Document