Differences

This shows you the differences between two versions of the page.

Link to this comparison view

howto:trace2umlinlatex [2015/05/13 16:36] (current)
thomas created
Line 1: Line 1:
 +====== HowTo Trace2UML in LaTeX ======
 +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.
  
 +===== LaTeX Trace2UML Macros =====
 +For the example in this article the following five macros have been used.
 +
 +**"​Call",​ "​Return from" and "​Create"​ a Macro**
 +<​code>​
 +\newcommand{\entermacroseq}[1]{%
 + \immediate\write\tracetouml{>​ #1}%
 + }%
 +</​code>​
 +<​code>​
 +\newcommand{\leavemacroseq}{%
 + \immediate\write\tracetouml{<​ }%
 + }%
 +</​code>​
 +<​code>​
 +\newcommand{\createmacroseq}[1]{%
 + \immediate\write\tracetouml{+ #1}
 + }%
 +</​code>​
 +
 +**Open and Close a Write Stream**
 +
 +Place these macros at the beginning and end of the document respectively:​
 +<​code>​
 +\newcommand{\openseqdiag}{%
 + \newwrite\tracetouml%
 + \immediate\openout\tracetouml=\jobname.seq%
 + }%
 +</​code>​
 +<​code>​
 +\newcommand{\closeseqdiag}{%
 + \immediate\closeout\tracetouml%
 + }%
 +</​code>​
 +To automatically open and close, respectively,​ the outpustream add
 +<​code>​
 +\AtBeginDocument{\openseqdiag}%
 +\AtEndDocument{\closeseqdiag}%
 +</​code>​
 +to the preamble of the document.
 +
 +===== Example Document =====
 +To demonstrate the basic idea the following LaTeX snippets show how to utilize these macros. First two new macros are defined:
 +
 +  * macroA that twice calls macroB
 +  * macroB that prints the current date and time (provided by scrtime)
 +
 +<​code>​
 +\newcommand{\macroA}{%
 + \entermacroseq{macroA}%
 + \textbf{\macroB}%
 + \macroB%
 + \leavemacroseq%
 +
 +\newcommand{\macroB}{%
 + \entermacroseq{macroB}%
 + \today, \thistime%
 + \leavemacroseq%
 + }
 +</​code>​
 +
 +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.
 +<​code>​
 +\entermacroseq{Document}
 +\macroA
 +\createmacroseq{macroA}
 +\renewcommand{\macroA}{
 + \entermacroseq{macroA}
 + \textit{\macroB}
 + \leavemacroseq
 + }
 +\\
 +\macroA
 +\leavemacroseq
 +</​code>​
 +
 +----
 +
 +The picture below shows the resulting sequence diagram.
 +
 +<format trace2uml>​
 +! 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 ​
 +</​format>​
 +<​code>​
 +! 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 ​
 +</​code>​
howto/trace2umlinlatex.txt ยท Last modified: 2015/05/13 16:36 by thomas
GNU Free Documentation License 1.3
Powered by PHP Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 Valid HTML5