summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/rst
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/rst
Initial commit
Diffstat (limited to 'macros/latex/contrib/rst')
-rw-r--r--macros/latex/contrib/rst/README27
-rw-r--r--macros/latex/contrib/rst/rst-package.pdfbin0 -> 172653 bytes
-rw-r--r--macros/latex/contrib/rst/rst.sty1152
-rw-r--r--macros/latex/contrib/rst/urml2latex.perl385
4 files changed, 1564 insertions, 0 deletions
diff --git a/macros/latex/contrib/rst/README b/macros/latex/contrib/rst/README
new file mode 100644
index 0000000000..882512b923
--- /dev/null
+++ b/macros/latex/contrib/rst/README
@@ -0,0 +1,27 @@
+rst package
+Version 1.3, dated 17-Feb-2003
+
+TeX Macros to typeset Rhetorical Structures (RSTs).
+
+Written by David Reitter (reitter at mle.media.mit.edu)
+
+All rights reserved. Usage is free, put please cite or point to the manual.
+Copyright 2003 David Reitter. No redistribution, if .tar.gz file is altered.
+
+New versions to be found here: http://www.reitter-it-media.de/ (CompLing/Lang.Tech. area)
+
+This package provides the commands \dirrel, \multinuc, \rstsegment,
+the standalone command \rl,
+and the environment rhetoricaltext with the associated commands \unit, \source and \relr.
+
+Please refer to rst-package.pdf for instructions.
+
+Installation:
+
+Use .sty as usual with a \usepackage{rst} instruction.
+
+This package requires the following other packages, which usually come with the standard TeX installations.
+
+- color (can be avoided, see manual)
+- ifthen
+- calc \ No newline at end of file
diff --git a/macros/latex/contrib/rst/rst-package.pdf b/macros/latex/contrib/rst/rst-package.pdf
new file mode 100644
index 0000000000..2b5a7c40bf
--- /dev/null
+++ b/macros/latex/contrib/rst/rst-package.pdf
Binary files differ
diff --git a/macros/latex/contrib/rst/rst.sty b/macros/latex/contrib/rst/rst.sty
new file mode 100644
index 0000000000..ece81df513
--- /dev/null
+++ b/macros/latex/contrib/rst/rst.sty
@@ -0,0 +1,1152 @@
+%%%
+%%% Macros to typeset Rhetorical Structures (RSTs).
+%%%
+%%% Written by David Reitter (reitter at mle.media.mit.edu)
+%%%
+%%% All rights reserved. Usage is free, put please cite or point to the manual.
+%%% Copyright 2003 David Reitter
+%%%
+%%% New versions to be found here: http://www.reitter-it-media.de/compling/
+%%%
+
+%%%
+%%% This package provides the commands \dirrel, \multinuc, \rstsegment
+%%% and the environment rhetoricaltext with the associated commands \unit, \source and \relr.
+%%%
+%%% Please refer to rst.pdf for instructions.
+%%%
+
+%%% revised 11-06: horizontal spacing issues (at least) improved so that relation names
+%%% can be drawn correctly. Still does not work well in some multi-satellite
+%%% configurations.
+%%% revised 01-15: rhetoricaltext environment uses better label / reference mechanism now
+%%% so TeX won't run out of memory when working with large documents and
+%%% many rhetoricaltexts. You always need to compile twice to get the refs right!
+%%% revised 02-12: rhetoricaltext environment does not use \lineheight any more. Margins
+%%% before and after rhetoricaltexts may change.
+%%% revised 02-17: provide \rl command to format a relation name (capitalized)
+%%% All relation names in diagrams are capitalized now
+
+\ProvidesPackage {rst}
+ [2003/02/17 typeset rhetorical structures v. 1.3]
+
+\RequirePackage{color}
+
+\newlength{\compressionWidth}
+\setlength{\compressionWidth}{0pt} % set to any length>0 to compress trees horizontally
+
+\newlength{\terminalWidth}
+\setlength{\terminalWidth}{100pt} % set to any length>0 to compress trees horizontally
+
+\newlength{\rstmargin} % left and right margin
+\setlength{\rstmargin}{3pt}
+
+\newlength{\rstmiddleskip} % margin between spans
+
+\setlength{\rstmiddleskip}{1em}
+
+%empty the following two if you wish NOT to use the color package
+\newcommand{\relnamebgcolor}{}% background color.
+\newcommand{\relnamecolor}{red}% relation name color
+
+
+%uncomment the following two if you wish NOT to use the color package
+\newcommand{\mycolorbox}{} % uncommented so that \raisebox may be used
+
+%\newcommand{\mycolor}{}
+
+
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%% no change beyond this point.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+\providecommand {\rl}[1]{\textsc{\expandafter\MakeUppercase#1}}
+
+
+
+% internal stuff
+
+
+
+
+
+
+\newcommand{\nuc}{}
+
+
+
+\providecommand{\mycolorbox}{\colorbox}
+
+\providecommand{\mycolor}{\color}
+
+\newlength{\drwdone}
+\newlength{\drwdtwo}
+\newlength{\drwdthree}
+\newlength{\drwdfour}
+\newlength{\drwdfive}
+\newlength{\drwdtemp}
+\newlength{\drwdtempx}
+\newlength{\drwdtempy}
+
+
+\newlength{\drwdbezleft}
+\newlength{\drwdbezright}
+\newlength{\drwdbezA}
+\newlength{\drwdbezB}
+\newlength{\drwdbezC}
+\newlength{\drwdbezD}
+\newlength{\drwdbezE}
+\newlength{\drwdgraph}
+\newlength{\drwdmiddle}
+\newlength{\drwdmiddleOne}
+\newlength{\drwdmiddleTwo}
+\newlength{\drwdmiddleThree}
+\newlength{\drwdmiddleFour}
+\newlength{\drhegraph}
+\newlength{\drhetext}
+\newlength{\drhetotal}
+%\newlength{\drwdrstrealwidth}% temp (local)
+%\newlength{\rstrealwidth}% global (as return var)
+%\newlength{\rstleftoffset}% global (as return var)
+%\newlength{\rstrightoffset}% global (as return var)
+%\gdef\rstrealwidth{}\gdef\rstleftoffset{}\gdef\rstleftoffset{}% all global
+\newlength{\relnamepos}
+\newlength{\@relnamewd}
+\newsavebox{\rstboxone}
+\newsavebox{\rstboxtwo}
+\newsavebox{\rstboxthree}
+\newsavebox{\rstboxfour}
+\newsavebox{\rstboxfive}
+\newsavebox{\rstallbox}
+
+\newcommand\@optOne{}
+\newcommand\@optTwo{}
+\newcommand\@optThree{}
+\newcommand\@optFour{}
+\newcommand\@optFive{}
+\newcommand\@relOne{}
+\newcommand\@relTwo{}
+\newcommand\@relThree{}
+\newcommand\@relFour{}
+\newcommand\@relFive{}
+%\makeatletter
+\newcommand{\LenToUnit}[1]{%
+ #1\@gobble
+}
+%\makeatother
+
+\newcommand{\drhspacer}[1]{%
+\setlength{\unitlength}{#1}%
+\begin{picture}(1,0)(0,0)% spacing
+\end{picture}%
+}
+
+%% This package ...
+
+
+\let\rstvarfont=\it% Font for variables
+\let\rstcondfont=\rm% Font for conditions -- no spaces in here!!
+\let\rstseparator=\hline% Separator between variables and conditions
+
+\newcommand{\relnamefont} [1] {\mycolor\relnamecolor\small\rl{#1}}
+
+
+\newcount\@rstlevel \@rstlevel=0
+%\def\rst@strut{{\large\strut}}
+%\def\dirrel@strut{{\large\strut}}
+
+\newlength{\myVSpace}% the height of the box
+\setlength{\myVSpace}{1ex}% the default,
+\newcommand\xstrut{\raisebox{-1\myVSpace}% symmetric behaviour,
+ {\rule{0pt}{\myVSpace}}%
+}
+
+
+% calc middle position
+\newcommand{\setmiddle}[3]{
+\setlength{#1}{#2}
+\addtolength{#1}{#3}
+\setlength{#1}{.5 #1}
+}
+
+
+\newlength{\@strhtemp}
+\newcommand{\settorealheight}[2]{%
+\settoheight{#1}{#2}%
+\settodepth{\@strhtemp}{#2}%
+\addtolength{#1}{\@strhtemp}%
+}%
+
+\newlength{\drwdemptycheck}
+\newcommand{\ifemptyd}[1]{\settowidth{\drwdemptycheck}{#1}\ifnum\drwdemptycheck<1}% this is stupid, but other variants did not work
+\newcommand{\ifemptydd}[3]{\settowidth{\drwdemptycheck}{#1}\ifnum\drwdemptycheck<1#2\else#3\fi}% this is stupid, but other variants did not work
+
+%for compatibility reasons (old aux files)
+\newcommand{\@definerstlabelu}[2]{}
+\newcommand{\@definerstlabelt}[2]{}
+
+% called from .aux file
+%\newcommand{\@definerstlabelu}[2]{\@ifundefined{c@uu#1}{\newcounter{uu#1}}{}%
+%\setcounter{uu#1}{#2}}
+%\newcommand{\@definerstlabelt}[2]{\@ifundefined{c@tt#1}{\newcounter{tt#1}}{}%
+%\setcounter{tt#1}{#2}}
+%\newcommand{\@definerstlabelu}[2]{\def{\c@rstuu#1}{#2}}%
+%\newcommand{\@definerstlabelt}[2]{\def{\c@rsttt#1}{#2}}%
+% local versions
+%\newcommand{\@definerstlabelintu}[2]{\newcounter{u#1}%
+%\setcounter{u#1}{#2}}
+%\newcommand{\@definerstlabelintt}[2]{\newcounter{t#1}%
+%\setcounter{t#1}{#2}}
+%\newcommand{\@definerstlabelintu}[2]{\def\u#1{#2}}
+%\newcommand{\@definerstlabelintt}[2]{\def\t#1{#2}}
+%
+\def\tmakedef#1#2{\expandafter\xdef\csname #1\endcsname{#2}}%
+\newcounter{rhetoricaltextno}
+\setcounter{rhetoricaltextno}{0}
+\newcounter{rhetoricalunitno}
+\newenvironment{rhetoricaltext}{
+\addtocounter{rhetoricaltextno}{1}\setcounter{rhetoricalunitno}{0}\setlength{\parindent}{0pt}\flushleft\sf}{\vspace{\baselineskip}}
+\newcommand{\unit}[2][]{%
+\ifemptyd{#1}[#2]\else%
+\addtocounter{rhetoricalunitno}{1}%
+%\@ifundefined{uu#1}{}{\typeout{rst-package error: you defined the #1 label for a rst unit twice.}}%
+%\@definerstlabelu{#1}{\value{rhetoricalunitno}}%
+%\@definerstlabelt{#1}{\value{rhetoricaltextno}}%
+%\if@filesw\immediate\write\@auxout{\noexpand\@definerstlabelu{#1}{\arabic{rhetoricalunitno}}}%
+%\immediate\write\@auxout{\noexpand\@definerstlabelt{#1}{\arabic{rhetoricaltextno}}}\fi%
+\if@filesw\immediate\write\@auxout{\noexpand\tmakedef{rstuu#1}{\Alph{rhetoricalunitno}}}%
+\immediate\write\@auxout{\noexpand\tmakedef{rsttt#1}{\arabic{rhetoricaltextno}}}\fi%
+%\def\c@u#1{\Alph{rhetoricalunitno}}%
+%\def\c@t#1{\arabic{rhetoricaltextno}}%
+[#2]$^{\arabic{rhetoricaltextno}\Alph{rhetoricalunitno}}$\fi}
+%\newcommand{\refr}[1]{\@ifundefined{@rstt#1}{\@ifundefined{@rsttt#1}{??}{\csname\@rsttt#1\endcsname\csname\@rstuu#1\endcsname}}{\csname\t#1\endcsname\csname\u#1\endcsname}}
+
+\def\tcallup#1{\csname #1\endcsname}
+\newcommand{\refr}[1]{\tcallup{rsttt#1}\tcallup{rstuu#1}}%
+
+%\newcommand{\refr}[1]{\@ifundefined{\expandafter\csname\@rsttt #1\endcsname}{??}{\csname\@rsttt#1\endcsname\csname\@rstuu#1\endcsname}}%
+%\newcommand{\refr}[1]{\@ifundefined{c@t#1}{\@ifundefined{c@tt#1}{??}{\arabic{tt#1}\Alph{uu#1}}}{\arabic{t#1}\Alph{u#1}}}
+\newcommand{\source}[1]{ {\hfill\small(#1)}}
+
+
+
+
+\newcommand{\addadditionalspace}%
+{\ifemptydd{\@relOne}%\else% if 1 is the nuc
+{% to 1st right
+\settowidth{\drwdtemp}{\relnamefont{\ \@relTwo\ }}%
+\setlength{\drwdtemp}{1.0\drwdtemp}% space that we need
+\setlength{\drwdtempx}{0.5\drwdone}%half of nuc
+\addtolength{\drwdtempx}{\drwdmiddleOne}%
+\addtolength{\drwdtempx}{0.8\drwdtwo}%most of right
+\ifdim\drwdtemp>\drwdtempx%
+\addtolength{\drwdtemp}{-\drwdtempx}%
+\addtolength{\drwdmiddleOne}{\drwdtemp}%
+\fi%
+% to 2. right
+\settowidth{\drwdtemp}{\relnamefont{\ \@relThree\ }}%
+\setlength{\drwdtemp}{1.0\drwdtemp}% space that we need
+\setlength{\drwdtempx}{0.5\drwdone}%half of nuc
+\addtolength{\drwdtempx}{\drwdmiddleOne}%
+\addtolength{\drwdtempx}{\drwdtwo}%
+\addtolength{\drwdtempx}{\drwdmiddleTwo}%
+\addtolength{\drwdtempx}{0.8\drwdthree}%most of right
+\ifdim\drwdtemp>\drwdtempx
+\addtolength{\drwdtemp}{-\drwdtempx}%
+\addtolength{\drwdmiddleTwo}{\drwdtemp}%
+\fi%
+% to 3. right
+\settowidth{\drwdtemp}{\relnamefont{\ \@relFour\ }}%
+\setlength{\drwdtemp}{1.0\drwdtemp}% space that we need
+\setlength{\drwdtempx}{0.5\drwdone}%half of nuc
+\addtolength{\drwdtempx}{\drwdmiddleOne}%
+\addtolength{\drwdtempx}{\drwdtwo}%
+\addtolength{\drwdtempx}{\drwdmiddleTwo}%
+\addtolength{\drwdtempx}{\drwdthree}%
+\addtolength{\drwdtempx}{\drwdmiddleThree}%
+\addtolength{\drwdtempx}{0.8\drwdfour}%most of right
+\ifdim\drwdtemp>\drwdtempx
+\addtolength{\drwdtemp}{-\drwdtempx}%
+\addtolength{\drwdmiddleThree}{\drwdtemp}%
+\fi%
+% to 4. right
+\settowidth{\drwdtemp}{\relnamefont{\ \@relFive\ }}%
+\setlength{\drwdtemp}{1.0\drwdtemp}% space that we need
+\setlength{\drwdtempx}{0.5\drwdone}%half of nuc
+\addtolength{\drwdtempx}{\drwdmiddleOne}%
+\addtolength{\drwdtempx}{\drwdtwo}%
+\addtolength{\drwdtempx}{\drwdmiddleTwo}%
+\addtolength{\drwdtempx}{\drwdthree}%
+\addtolength{\drwdtempx}{\drwdmiddleThree}%
+\addtolength{\drwdtempx}{\drwdthree}%most of right
+\addtolength{\drwdtempx}{\drwdmiddleFour}%
+\addtolength{\drwdtempx}{0.8\drwdfive}%most of right
+\ifdim\drwdtemp>\drwdtempx
+\addtolength{\drwdtemp}{-\drwdtempx}%
+\addtolength{\drwdmiddleFour}{\drwdtemp}%
+\fi%
+}{}%
+\ifnum\drwdtwo>0\ifemptydd{\@relTwo}%\else% if 2 is the nuc
+{% to 1st left
+\settowidth{\drwdtemp}{\relnamefont{\ \@relOne\ }}%
+\setlength{\drwdtemp}{1.0\drwdtemp}% space that we need
+\setlength{\drwdtempx}{0.8\drwdone}%most of left
+\addtolength{\drwdtempx}{\drwdmiddleOne}%
+\addtolength{\drwdtempx}{0.5\drwdtwo}%half of nuc
+\ifdim\drwdtemp>\drwdtempx%
+\addtolength{\drwdtemp}{-\drwdtempx}%
+\addtolength{\drwdmiddleOne}{\drwdtemp}%
+\fi%
+% to 1st right
+\settowidth{\drwdtemp}{\relnamefont{\ \@relThree\ }}%
+\setlength{\drwdtemp}{1.0\drwdtemp}% space that we need
+\setlength{\drwdtempx}{0.5\drwdtwo}%half of nuc
+\addtolength{\drwdtempx}{\drwdmiddleTwo}%
+\addtolength{\drwdtempx}{0.8\drwdthree}%most of right
+\ifdim\drwdtemp>\drwdtempx
+\addtolength{\drwdtemp}{-\drwdtempx}%
+\addtolength{\drwdmiddleTwo}{\drwdtemp}%
+\fi%
+% to 2nd right
+\settowidth{\drwdtemp}{\relnamefont{\ \@relFour\ }}%
+\setlength{\drwdtemp}{1.0\drwdtemp}% space that we need
+\setlength{\drwdtempx}{0.5\drwdtwo}%half of nuc
+\addtolength{\drwdtempx}{\drwdmiddleTwo}%
+\addtolength{\drwdtempx}{\drwdthree}%
+\addtolength{\drwdtempx}{\drwdmiddleThree}%
+\addtolength{\drwdtempx}{0.8\drwdfour}%most of right
+\ifdim\drwdtemp>\drwdtempx
+\addtolength{\drwdtemp}{-\drwdtempx}%
+\addtolength{\drwdmiddleThree}{\drwdtemp}%
+\fi%
+% to 4th right
+\settowidth{\drwdtemp}{\relnamefont{\ \@relFive\ }}%
+\setlength{\drwdtemp}{1.0\drwdtemp}% space that we need
+\setlength{\drwdtempx}{0.5\drwdtwo}%half of nuc
+\addtolength{\drwdtempx}{\drwdmiddleTwo}%
+\addtolength{\drwdtempx}{\drwdthree}%
+\addtolength{\drwdtempx}{\drwdmiddleThree}%
+\addtolength{\drwdtempx}{\drwdthree}%most of right
+\addtolength{\drwdtempx}{\drwdmiddleFour}%
+\addtolength{\drwdtempx}{0.8\drwdfive}%most of right
+\ifdim\drwdtemp>\drwdtempx
+\addtolength{\drwdtemp}{-\drwdtempx}%
+\addtolength{\drwdmiddleFour}{\drwdtemp}%
+\fi%
+}{}\fi%
+\ifnum\drwdthree>0\ifemptydd{\@relThree}%\else% if 3 is the nuc
+{% to 1st left
+\settowidth{\drwdtemp}{\relnamefont{\ \@relTwo\ }}%
+\setlength{\drwdtemp}{1.0\drwdtemp}% space that we need
+\setlength{\drwdtempx}{0.8\drwdtwo}%most of left
+\addtolength{\drwdtempx}{\drwdmiddleTwo}%
+\addtolength{\drwdtempx}{0.5\drwdthree}%half of nuc
+\ifdim\drwdtemp>\drwdtempx%
+\addtolength{\drwdtemp}{-\drwdtempx}%
+\addtolength{\drwdmiddleTwo}{\drwdtemp}%
+\fi%
+% to 2nd left
+\settowidth{\drwdtemp}{\relnamefont{\ \@relOne\ }}%
+\setlength{\drwdtemp}{\drwdtemp}% space that we need
+\setlength{\drwdtempx}{0.8\drwdone}%most of left
+\addtolength{\drwdtempx}{\drwdmiddleOne}%
+\setlength{\drwdtempx}{\drwdtwo}%
+\addtolength{\drwdtempx}{\drwdmiddleTwo}%
+\addtolength{\drwdtempx}{0.5\drwdthree}%half of nuc
+\ifdim\drwdtemp>\drwdtempx%
+\addtolength{\drwdtemp}{-\drwdtempx}%
+\addtolength{\drwdmiddleOne}{\drwdtemp}%
+\fi%
+% to 1st right
+\settowidth{\drwdtemp}{\relnamefont{\ \@relFour\ }}%
+\setlength{\drwdtemp}{1.0\drwdtemp}% space that we need
+\setlength{\drwdtempx}{0.5\drwdthree}%half of nuc
+\addtolength{\drwdtempx}{\drwdmiddleThree}%
+\addtolength{\drwdtempx}{0.8\drwdfour}%most of right
+\ifdim\drwdtemp>\drwdtempx
+\addtolength{\drwdtemp}{-\drwdtempx}%
+\addtolength{\drwdmiddleThree}{\drwdtemp}%
+\fi%
+% to 2nd right
+\settowidth{\drwdtemp}{\relnamefont{\ \@relFive\ }}%
+\setlength{\drwdtemp}{1.0\drwdtemp}% space that we need
+\setlength{\drwdtempx}{0.5\drwdthree}%half of nuc
+\addtolength{\drwdtempx}{\drwdmiddleThree}%
+\addtolength{\drwdtempx}{\drwdfour}%
+\addtolength{\drwdtempx}{\drwdmiddleFour}%
+\addtolength{\drwdtempx}{0.8\drwdfive}%most of right
+\ifdim\drwdtemp>\drwdtempx
+\addtolength{\drwdtemp}{-\drwdtempx}%
+\addtolength{\drwdmiddleFour}{\drwdtemp}%
+\fi%
+}{}\fi%
+\ifnum\drwdfour>0\ifemptydd{\@relFour}%\else% if 4 is the nuc
+{% to 1st left
+\settowidth{\drwdtemp}{\relnamefont{\ \@relTwo\ }}%
+\setlength{\drwdtemp}{1.0\drwdtemp}% space that we need
+\setlength{\drwdtempx}{0.8\drwdthree}%most of left
+\addtolength{\drwdtempx}{\drwdmiddleThree}%
+\addtolength{\drwdtempx}{0.5\drwdfour}%half of nuc
+\ifdim\drwdtemp>\drwdtempx%
+\addtolength{\drwdtemp}{-\drwdtempx}%
+\addtolength{\drwdmiddleThree}{\drwdtemp}%
+\fi%
+% to 2nd left
+\settowidth{\drwdtemp}{\relnamefont{\ \@relOne\ }}%
+\setlength{\drwdtemp}{1.0\drwdtemp}% space that we need
+\setlength{\drwdtempx}{0.8\drwdtwo}%most of left
+\addtolength{\drwdtempx}{\drwdmiddleTwo}%
+\setlength{\drwdtempx}{\drwdthree}%
+\addtolength{\drwdtempx}{\drwdmiddleThree}%
+\addtolength{\drwdtempx}{0.5\drwdfour}%half of nuc
+\ifdim\drwdtemp>\drwdtempx%
+\addtolength{\drwdtemp}{-\drwdtempx}%
+\addtolength{\drwdmiddleTwo}{\drwdtemp}%
+\fi%
+% to 3rd left
+\settowidth{\drwdtemp}{\relnamefont{\ \@relOne\ }}%
+\setlength{\drwdtemp}{1.0\drwdtemp}% space that we need
+\setlength{\drwdtempx}{0.8\drwdone}%most of left
+\addtolength{\drwdtempx}{\drwdmiddleOne}%
+\setlength{\drwdtempx}{\drwdtwo}%
+\addtolength{\drwdtempx}{\drwdmiddleTwo}%
+\setlength{\drwdtempx}{\drwdthree}%
+\addtolength{\drwdtempx}{\drwdmiddleThree}%
+\addtolength{\drwdtempx}{0.5\drwdfour}%half of nuc
+\ifdim\drwdtemp>\drwdtempx%
+\addtolength{\drwdtemp}{-\drwdtempx}%
+\addtolength{\drwdmiddleOne}{\drwdtemp}%
+\fi%
+% to 1st right
+\settowidth{\drwdtemp}{\relnamefont{\ \@relFive\ }}%
+\setlength{\drwdtemp}{1.0\drwdtemp}% space that we need
+\addtolength{\drwdtempx}{0.5\drwdfour}%half of nuc
+\addtolength{\drwdtempx}{\drwdmiddleFour}%
+\addtolength{\drwdtempx}{0.8\drwdfive}%most of right
+\ifdim\drwdtemp>\drwdtempx
+\addtolength{\drwdtemp}{-\drwdtempx}%
+\addtolength{\drwdmiddleFour}{\drwdtemp}%
+\fi%
+}{}\fi%
+}%
+
+
+\newcommand{\initrstwidths}{%
+\settowidth{\drwdone}{\@optOne}%
+\settowidth{\drwdtwo}{\@optTwo}%
+\settowidth{\drwdthree}{\@optThree}%
+\settowidth{\drwdfour}{\@optFour}%
+\settowidth{\drwdfive}{\@optFive}%
+%\setlength{\drwdrstrealwidth}{\drwdone}%
+%\addtolength{\drwdrstrealwidth}{\drwdtwo}%
+%\addtolength{\drwdrstrealwidth}{\drwdthree}%
+%\addtolength{\drwdrstrealwidth}{\drwdfour}%
+%\addtolength{\drwdrstrealwidth}{\drwdfive}%
+\ifdim\compressionWidth>0pt\ifdim\drwdone>\compressionWidth\setlength{\drwdone}{\compressionWidth}\fi\fi%
+\ifdim\compressionWidth>0pt\ifdim\drwdtwo>\compressionWidth\setlength{\drwdtwo}{\compressionWidth}\fi\fi%
+\ifdim\compressionWidth>0pt\ifdim\drwdthree>\compressionWidth\setlength{\drwdthree}{\compressionWidth}\fi\fi%
+\ifdim\compressionWidth>0pt\ifdim\drwdfour>\compressionWidth\setlength{\drwdfour}{\compressionWidth}\fi\fi%
+\ifdim\compressionWidth>0pt\ifdim\drwdfive>\compressionWidth\setlength{\drwdfive}{\compressionWidth}\fi\fi%
+\savebox{\rstboxone}[\drwdone]{\@optOne}% returns rstrealwidth -- we just need left and right borders
+%\addtolength{\rstrealwidth}{-\drwdtwo}%
+%\addtolength{\rstleftoffset}{\rstrealwidth}%
+\savebox{\rstboxtwo}[\drwdtwo]{\@optTwo}%
+\savebox{\rstboxthree}[\drwdthree]{\@optThree}%
+\savebox{\rstboxfour}[\drwdfour]{\@optFour}%
+\savebox{\rstboxfive}[\drwdfive]{\@optFive}% one of these returns the right border (others are empty)
+%\ifnum\drwdtwo>0\addtolength{\rstrealwidth}{-\drwdtwo}\fi%
+%\ifnum\drwdthree>0\addtolength{\rstrealwidth}{-\drwdthree}\fi%
+%\ifnum\drwdfour>0\addtolength{\rstrealwidth}{-\drwdfour}\fi%
+%\ifnum\drwdfive>0\addtolength{\rstrealwidth}{-\drwdfive}\fi%
+%\addtolength{\rstrightoffset}{\rstrealwidth}%
+}%
+
+\newcommand{\returnrstrealwidths}{%
+%\setlength{\rstrealwidth}{\drwdrstrealwidth}% this to be returned to calling macro
+%\ifnum\drwdtwo>0\addtolength{\rstrealwidth}{\drwdmiddleOne}\fi%
+%\ifnum\drwdthree>0\addtolength{\rstrealwidth}{\drwdmiddleTwo}\fi%
+%\ifnum\drwdfour>0\addtolength{\rstrealwidth}{\drwdmiddleThree}\fi%
+%\ifnum\drwdfive>0\addtolength{\rstrealwidth}{\drwdmiddleFour}\fi%
+}
+
+
+
+%\long\def\rstbox#1{%
+%\setlength{\rstleftoffset}{0pt}\setlength{\rstrightoffset}{0pt}%
+%\savebox{\rstallbox}{#1}%
+%\frame{a\drhspacer{\rstrealwidth}b\usebox{\rstallbox}\drhspacer{\rstrightoffset}}}%
+
+
+\long\def\dirrel{%
+\dirrela}
+\long\def\dirrela#1{%
+\@ifnextchar\bgroup{\dirrelb{#1}}{\typeout{dirrel: syntax error. needs at least 3 \{ \} arguments (relname, nucleus-idx, segment+)}\relax}}
+\long\def\dirrelb#1#2{%
+\@ifnextchar\bgroup{\dirrelc{#1}{#2}}{\typeout{dirrel: syntax error. needs at least 3 \{ \} arguments (relname, nucleus-idx, segment+)}\relax}}
+\long\def\dirrelc#1#2#3{%
+\@ifnextchar\bgroup{\dirreld{#1}{#2}{#3}}{\dirrelz{#1}{#2}{#3}{}{}{}{}{}{}\relax}}
+\long\def\dirreld#1#2#3#4{%
+\@ifnextchar\bgroup{\dirrele{#1}{#2}{#3}{#4}}{\dirrelz{#1}{#2}{#3}{#4}{}{}{}{}\relax}}
+\long\def\dirrele#1#2#3#4#5{%
+\@ifnextchar\bgroup{\dirrelf{#1}{#2}{#3}{#4}{#5}}{\dirrelz{#1}{#2}{#3}{#4}{#5}{}{}{}{}\relax}}
+\long\def\dirrelf#1#2#3#4#5#6{%
+\@ifnextchar\bgroup{\dirrelg{#1}{#2}{#3}{#4}{#5}{#6}}{\dirrelz{#1}{#2}{#3}{#4}{#5}{#6}{}{}{}\relax}}
+\long\def\dirrelg#1#2#3#4#5#6#7{%
+\@ifnextchar\bgroup{\dirrelh{#1}{#2}{#3}{#4}{#5}{#6}{#7}}{\dirrelz{#1}{#2}{#3}{#4}{#5}{#6}{#7}{}{}\relax}}
+\long\def\dirrelh#1#2#3#4#5#6#7#8{%
+\@ifnextchar\bgroup{\dirreli{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}}{\dirrelz{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}{}\relax}}
+\long\def\dirreli#1#2#3#4#5#6#7#8#9{%
+\dirrelz{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}\relax}
+
+
+% syntax: \dirrel{relname}{nucleus-number}{arg1}...{arg5}
+
+
+\newcommand{\dirrelz}[9]%
+%\long\def\dirrelz#1#2#3#4#5#6#7#8#9%
+{%
+\bgroup%
+\advance\@rstlevel by 1%
+\renewcommand\@optOne{\ignorespaces#2}%
+\renewcommand\@optTwo{\ignorespaces#4}%
+\renewcommand\@optThree{\ignorespaces#6}%
+\renewcommand\@optFour{\ignorespaces#8}%
+\renewcommand\@optFive{}%
+\renewcommand\@relOne{\ignorespaces#1}%
+\renewcommand\@relTwo{\ignorespaces#3}%
+\renewcommand\@relThree{\ignorespaces#5}%
+\renewcommand\@relFour{\ignorespaces#7}%
+\renewcommand\@relFive{\ignorespaces#9}%
+\relax%
+{\rstcondfont%
+\def\arraystretch{0}% undefined by default: value for \arraystretch
+\fboxsep0pt% no space
+\fboxrule0pt% no space
+\initrstwidths%
+%%%%% calc graph width %%%%%%%%%%%%%%%%%%%%%%%%%%%
+%\setlength{\drwdmiddle}{\rstmiddleskip}% middle space
+\setlength{\drwdmiddleOne}{\rstmiddleskip}% middle space
+\setlength{\drwdmiddleTwo}{\rstmiddleskip}% middle space
+\setlength{\drwdmiddleThree}{\rstmiddleskip}% middle space
+\setlength{\drwdmiddleFour}{\rstmiddleskip}% middle space
+%%%%%%
+\addadditionalspace%
+\setlength{\drwdgraph}{2\rstmargin}
+\ifnum\drwdone>0\addtolength{\drwdgraph}{\drwdone}\fi%
+\ifnum\drwdtwo>0\addtolength{\drwdgraph}{\drwdtwo}\addtolength{\drwdgraph}{\drwdmiddleOne}\fi%
+\ifnum\drwdthree>0\addtolength{\drwdgraph}{\drwdthree}\addtolength{\drwdgraph}{\drwdmiddleTwo}\fi%
+\ifnum\drwdfour>0\addtolength{\drwdgraph}{\drwdfour}\addtolength{\drwdgraph}{\drwdmiddleThree}\fi%
+\ifnum\drwdfive>0\addtolength{\drwdgraph}{\drwdfive}\addtolength{\drwdgraph}{\drwdmiddleFour}\fi%
+%%%%% calc bezier positions %%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+\ifnum\drwdone>0%
+\setlength{\drwdbezA}{\rstmargin}%
+\addtolength{\drwdbezA}{.3333\drwdone}%
+\fi%
+\ifnum\drwdtwo>0%
+\setlength{\drwdbezB}{\rstmargin}%
+\addtolength{\drwdbezB}{\drwdone}%
+\addtolength{\drwdbezB}{\drwdmiddleOne}%
+\addtolength{\drwdbezB}{.5\drwdtwo}%
+%\setlength{\drwdbezB}{.5\drwdgraph}%
+\else%
+\addtolength{\drwdbezA}{.1666\drwdone}% a single branch should go straight down
+\fi%
+\ifnum\drwdthree>0%
+\setlength{\drwdbezC}{\rstmargin}%
+\addtolength{\drwdbezC}{\drwdone}%
+\addtolength{\drwdbezC}{\drwdmiddleOne}%
+\addtolength{\drwdbezC}{\drwdtwo}%
+\addtolength{\drwdbezC}{\drwdmiddleTwo}%
+\addtolength{\drwdbezC}{.5\drwdthree}%
+\else%
+\addtolength{\drwdbezB}{.1666\drwdtwo}% the rightmost branch goes further to the right
+\fi%
+\ifnum\drwdfour>0%
+\setlength{\drwdbezD}{\rstmargin}%
+\addtolength{\drwdbezD}{\drwdone}%
+\addtolength{\drwdbezD}{\drwdmiddleOne}%
+\addtolength{\drwdbezD}{\drwdtwo}%
+\addtolength{\drwdbezD}{\drwdmiddleTwo}%
+\addtolength{\drwdbezD}{\drwdthree}%
+\addtolength{\drwdbezD}{\drwdmiddleThree}%
+\addtolength{\drwdbezD}{.5\drwdfour}%
+\else%
+\addtolength{\drwdbezC}{.1666\drwdthree}% the rightmost branch goes further to the right
+\fi%
+\ifnum\drwdfive>0%
+\setlength{\drwdbezE}{\rstmargin}%
+\addtolength{\drwdbezE}{\drwdone}%
+\addtolength{\drwdbezE}{\drwdmiddleOne}%
+\addtolength{\drwdbezE}{\drwdtwo}%
+\addtolength{\drwdbezE}{\drwdmiddleTwo}%
+\addtolength{\drwdbezE}{\drwdthree}%
+\addtolength{\drwdbezE}{\drwdmiddleThree}%
+\addtolength{\drwdbezE}{\drwdfour}%
+\addtolength{\drwdbezE}{\drwdmiddleFour}%
+\addtolength{\drwdbezE}{.6666\drwdfive}%
+\else%
+\addtolength{\drwdbezD}{.1666\drwdfour}% the rightmost branch goes further to the right
+\fi%
+%
+%set nucleus position
+%
+\setlength{\drwdbezleft}{0pt}%
+\ifnum\drwdone>0\ifemptyd{\@relOne}\setlength{\drwdbezleft}{\drwdbezA}\fi\fi%
+\ifnum\drwdtwo>0\ifemptyd{\@relTwo}\setlength{\drwdbezleft}{\drwdbezB}\fi\fi%
+\ifnum\drwdthree>0\ifemptyd{\@relThree}\setlength{\drwdbezleft}{\drwdbezC}\fi\fi%
+\ifnum\drwdfour>0\ifemptyd{\@relFour}\setlength{\drwdbezleft}{\drwdbezD}\fi\fi%
+\ifnum\drwdfive>0\ifemptyd{\@relFive}\setlength{\drwdbezleft}{\drwdbezE}\fi\fi%
+\ifnum\drwdbezleft=0\typeout{dirrel: where's my nucleus?? One of the relation parameters should be empty}\fi%
+%
+%%%%% calc graph height %%%%%%%%%%%%%%%%%%%%%%%%%%
+\setlength{\drhegraph}{.3\drwdgraph}%
+\settorealheight{\drwdtemp}{\relnamefont{\mycolorbox{\relnamebgcolor}{\@relOne}}}%
+\setlength{\drwdtemp}{2.5\drwdtemp}% 1/(0.4) = 2.5
+\addtolength{\drwdtemp}{4pt}%
+\ifnum\drhegraph<\drwdtemp\setlength{\drhegraph}{\drwdtemp}\fi%
+%%%%% calc text height %%%%%%%%%%%%%%%%%%%%%%%%%%%
+\settorealheight{\drhetext}{\usebox{\rstboxone}}%
+\settorealheight{\drwdtemp}{\usebox{\rstboxtwo}}%
+\ifnum\drhetext<\drwdtemp\setlength{\drhetext}{\drwdtemp}\fi%
+\settorealheight{\drwdtemp}{\usebox{\rstboxthree}}%
+\ifnum\drhetext<\drwdtemp\setlength{\drhetext}{\drwdtemp}\fi%
+\settorealheight{\drwdtemp}{\usebox{\rstboxfour}}%
+\ifnum\drhetext<\drwdtemp\setlength{\drhetext}{\drwdtemp}\fi%
+\settorealheight{\drwdtemp}{\usebox{\rstboxfive}}%
+\ifnum\drhetext<\drwdtemp\setlength{\drhetext}{\drwdtemp}\fi%
+%%%%% calc total height %%%%%%%%%%%%%%%%%%%%%%%%%%
+\setlength{\drhetotal}{\drhetext}%
+\addtolength{\drhetotal}{\drhegraph}%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\setlength{\baselineskip}{0pt}%
+%\frame{%
+\limparbox{\drwdgraph}{\drhetotal}{%
+% vertical space
+\setlength{\unitlength}{\drhegraph}%
+\begin{picture}(0,1)(0,0)% spacing
+\end{picture}%
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\setlength{\unitlength}{\drwdgraph}% middle
+\begin{picture}(0,0)(0,0)%
+\ifnum\drwdone>0\ifnum\drwdbezA=\drwdbezleft\else\ifnum\drwdbezA<\drwdbezleft\put(\LenToUnit{\drwdbezleft},0){\vector(1,-1){0}}\else\put(\LenToUnit{\drwdbezleft},0){\vector(-1,-1){0}}\fi\setmiddle{\drwdtempx}{\drwdbezleft}{\drwdbezA}\qbezier(\LenToUnit{\drwdbezA},0)(\LenToUnit{\drwdtempx},\LenToUnit{.3\drwdgraph})(\LenToUnit{\drwdbezleft},.0)\fi\fi%
+\ifnum\drwdtwo>0\ifnum\drwdbezB=\drwdbezleft\else\ifnum\drwdbezB<\drwdbezleft\put(\LenToUnit{\drwdbezleft},0){\vector(1,-1){0}}\else\put(\LenToUnit{\drwdbezleft},0){\vector(-1,-1){0}}\fi\setmiddle{\drwdtempx}{\drwdbezleft}{\drwdbezB}\qbezier(\LenToUnit{\drwdbezB},0)(\LenToUnit{\drwdtempx},\LenToUnit{.3\drwdgraph})(\LenToUnit{\drwdbezleft},.0)\fi\fi%
+\ifnum\drwdthree>0\ifnum\drwdbezC=\drwdbezleft\else\ifnum\drwdbezC<\drwdbezleft\put(\LenToUnit{\drwdbezleft},0){\vector(1,-1){0}}\else\put(\LenToUnit{\drwdbezleft},0){\vector(-1,-1){0}}\fi\setmiddle{\drwdtempx}{\drwdbezleft}{\drwdbezC}\qbezier(\LenToUnit{\drwdbezC},0)(\LenToUnit{\drwdtempx},\LenToUnit{.3\drwdgraph})(\LenToUnit{\drwdbezleft},.0)\fi\fi%
+\ifnum\drwdfour>0\ifnum\drwdbezD=\drwdbezleft\else\ifnum\drwdbezD<\drwdbezleft\put(\LenToUnit{\drwdbezleft},0){\vector(1,-1){0}}\else\put(\LenToUnit{\drwdbezleft},0){\vector(-1,-1){0}}\fi\setmiddle{\drwdtempx}{\drwdbezleft}{\drwdbezD}\qbezier(\LenToUnit{\drwdbezD},0)(\LenToUnit{\drwdtempx},\LenToUnit{.3\drwdgraph})(\LenToUnit{\drwdbezleft},.0)\fi\fi%
+\ifnum\drwdfive>0\ifnum\drwdbezE=\drwdbezleft\else\ifnum\drwdbezE<\drwdbezleft\put(\LenToUnit{\drwdbezleft},0){\vector(1,-1){0}}\else\put(\LenToUnit{\drwdbezleft},0){\vector(-1,-1){0}}\fi\setmiddle{\drwdtempx}{\drwdbezleft}{\drwdbezE}\qbezier(\LenToUnit{\drwdbezE},0)(\LenToUnit{\drwdtempx},\LenToUnit{.3\drwdgraph})(\LenToUnit{\drwdbezleft},.0)\fi\fi%
+% draw vertical line; bezleft contains nucleus position
+\put(\LenToUnit{\drwdbezleft},0){\line(0,1){\LenToUnit{\drhegraph}}}%
+\end{picture}%
+%
+% draw relation name %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% attention: these picture environments must overlap 100%. no spaces inbetween in source code allowed!
+%\settowidth{\drwdtemp}{\relnamefont{#1}}%
+\setlength{\unitlength}{1pt}%
+%\addtolength{\unitlength}{.5\drwdtemp}%
+\begin{picture}(0,0)(0,0)%
+\ifemptyd{\@relOne}\else\setmiddle{\drwdtemp}{\drwdbezA}{\drwdbezleft}\settowidth{\drwdtempx}{\relnamefont{\@relOne}}\addtolength{\drwdtemp}{-.5\drwdtempx}\put(\LenToUnit{\drwdtemp},\LenToUnit{.6\drhegraph}){\relnamefont{\mycolorbox{\relnamebgcolor}{\@relOne}}}\fi%
+\ifemptyd{\@relTwo}\else\setmiddle{\drwdtemp}{\drwdbezB}{\drwdbezleft}\settowidth{\drwdtempx}{\relnamefont{\@relTwo}}\addtolength{\drwdtemp}{-.5\drwdtempx}\put(\LenToUnit{\drwdtemp},\LenToUnit{.6\drhegraph}){\relnamefont{\mycolorbox{\relnamebgcolor}{\@relTwo}}}\fi%
+\ifemptyd{\@relThree}\else\setmiddle{\drwdtemp}{\drwdbezC}{\drwdbezleft}\settowidth{\drwdtempx}{\relnamefont{\@relThree}}\addtolength{\drwdtemp}{-.5\drwdtempx}\put(\LenToUnit{\drwdtemp},\LenToUnit{.6\drhegraph}){\relnamefont{\mycolorbox{\relnamebgcolor}{\@relThree}}}\fi%
+\ifemptyd{\@relFour}\else\setmiddle{\drwdtemp}{\drwdbezD}{\drwdbezleft}\settowidth{\drwdtempx}{\relnamefont{\@relFour}}\addtolength{\drwdtemp}{-.5\drwdtempx}\put(\LenToUnit{\drwdtemp},\LenToUnit{.6\drhegraph}){\relnamefont{\mycolorbox{\relnamebgcolor}{\@relFour}}}\fi%
+\ifemptyd{\@relFive}\else\setmiddle{\drwdtemp}{\drwdbezE}{\drwdbezleft}\settowidth{\drwdtempx}{\relnamefont{\@relFive}}\addtolength{\drwdtemp}{-.5\drwdtempx}\put(\LenToUnit{\drwdtemp},\LenToUnit{.6\drhegraph}){\relnamefont{\mycolorbox{\relnamebgcolor}{\@relFive}}}\fi%
+\end{picture}%
+%%%%%% spacing %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\drhspacer{\rstmargin}%
+\settoheight{\unitlength}{\usebox{\rstboxone}}%
+\begin{picture}(0,0)(0,0)%
+\put(0,-1){\usebox{\rstboxone}}%
+\end{picture}%
+\setlength{\unitlength}{\drwdone}% left
+\begin{picture}(1,0)(0,0)% spacing
+\put(0,0){\line(1,0){1}}%
+\end{picture}%
+\setlength{\unitlength}{\drwdmiddleOne}% middle
+\begin{picture}(1,0)(0,0)%
+\end{picture}%
+%
+\settoheight{\unitlength}{\usebox{\rstboxtwo}}% text
+\begin{picture}(0,0)(0,0)%
+\put(0,-1){\usebox{\rstboxtwo}}%
+\end{picture}%
+\setlength{\unitlength}{\drwdtwo}% spacing
+\begin{picture}(1,0)(0,0)%
+\put(0,0){\line(1,0){1}}%
+\end{picture}%
+\setlength{\unitlength}{\drwdmiddleTwo}% middle
+\begin{picture}(1,0)(0,0)%
+\end{picture}%
+%
+\ifnum\drwdthree>0%
+\settoheight{\unitlength}{\usebox{\rstboxthree}}% text
+\begin{picture}(0,0)(0,0)%
+\put(0,-1){\usebox{\rstboxthree}}%
+\end{picture}%
+\setlength{\unitlength}{\drwdthree}% spacing
+\begin{picture}(1,0)(0,0)%
+\put(0,0){\line(1,0){1}}%
+\end{picture}%
+\setlength{\unitlength}{\drwdmiddleThree}% middle
+\begin{picture}(1,0)(0,0)%
+\end{picture}%
+\fi%
+%
+\ifnum\drwdfour>0%
+\settoheight{\unitlength}{\usebox{\rstboxfour}}% text
+\begin{picture}(0,0)(0,0)%
+\put(0,-1){\usebox{\rstboxfour}}%
+\end{picture}%
+\setlength{\unitlength}{\drwdfour}% spacing
+\begin{picture}(1,0)(0,0)%
+\put(0,0){\line(1,0){1}}%
+\end{picture}%
+\setlength{\unitlength}{\drwdmiddleFour}% middle
+\begin{picture}(1,0)(0,0)%
+\end{picture}%
+\fi%
+%
+\ifnum\drwdfive>0%
+\settoheight{\unitlength}{\usebox{\rstboxfive}}% text
+\begin{picture}(0,0)(0,0)%
+\put(0,-1){\usebox{\rstboxfive}}%
+\end{picture}%
+\setlength{\unitlength}{\drwdfive}% spacing
+\begin{picture}(1,0)(0,0)%
+\put(0,0){\line(1,0){1}}%
+\end{picture}%
+\fi%
+}%limpar
+%}%frame
+}%
+\egroup%
+} % close \dirrel
+
+
+
+
+%########## MULTINUC relations ########################################################################
+%##
+%##
+%##
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+\long\def\multirel{%
+\multirela}
+\long\def\multirela#1{%
+\@ifnextchar\bgroup{\expandafter\multirelb{#1}}{\multirelz{#1}{}{}{}{}\relax}}
+\long\def\multirelb#1#2{%
+\@ifnextchar\bgroup{\expandafter\multirelc{#1}{#2}}{\multirelz{#1}{#2}{}{}{}\relax}}
+\long\def\multirelc#1#2#3{%
+\@ifnextchar\bgroup{\expandafter\multireld{#1}{#2}{#3}}{\multirelz{#1}{#2}{#3}{}{}\relax}}
+\long\def\multireld#1#2#3#4{%
+\@ifnextchar\bgroup{\expandafter\multirele{#1}{#2}{#3}{#4}}{\multirelz{#1}{#2}{#3}{#4}{}\relax}}
+
+\long\def\multirele#1#2#3#4#5{%
+\multirelz{#1}{#2}{#3}{#4}{#5}\relax}
+
+%\def\multirelz#1#2#3#4#5{%
+% ( #1-#2-#3-#4-#5 )
+%}
+
+
+\newcommand{\multirelz}[6]{%
+\renewcommand\@optOne{\ignorespaces#2}%
+\renewcommand\@optTwo{\ignorespaces#3}%
+\renewcommand\@optThree{\ignorespaces#4}%
+\renewcommand\@optFour{\ignorespaces#5}%
+\renewcommand\@optFive{\ignorespaces#6}%
+\bgroup%
+\advance\@rstlevel by 1%
+\relax%
+{\raggedleft\rstcondfont%
+\def\arraystretch{0}% undefined by default: value for \arraystretch
+\fboxsep0pt% no space
+\fboxrule0pt% no space
+\initrstwidths%
+%%%%% calc graph width %%%%%%%%%%%%%%%%%%%%%%%%%%%
+\setlength{\drwdmiddle}{\rstmiddleskip}% middle space
+\setlength{\drwdgraph}{2\rstmargin}%
+\ifnum\drwdone>0\addtolength{\drwdgraph}{\drwdone}\fi%
+\ifnum\drwdtwo>0\addtolength{\drwdgraph}{\drwdtwo}\addtolength{\drwdgraph}{\drwdmiddle}\fi%
+\ifnum\drwdthree>0\addtolength{\drwdgraph}{\drwdthree}\addtolength{\drwdgraph}{\drwdmiddle}\fi%
+\ifnum\drwdfour>0\addtolength{\drwdgraph}{\drwdfour}\addtolength{\drwdgraph}{\drwdmiddle}\fi%
+\ifnum\drwdfive>0\addtolength{\drwdgraph}{\drwdfive}\addtolength{\drwdgraph}{\drwdmiddle}\fi%
+\settowidth{\drwdtemp}{\relnamefont{#1}}%
+\setlength{\drwdtemp}{1.3\drwdtemp}%
+\ifdim\drwdgraph<\drwdtemp%
+\ifnum\drwdone>0%
+\addtolength{\drwdtemp}{-\drwdgraph}%
+\addtolength{\drwdgraph}{\drwdtemp}%
+\ifnum\drwdtwo>0\setlength{\drwdtemp}{\drwdtemp}\fi%
+\ifnum\drwdthree>0\setlength{\drwdtemp}{.5\drwdtemp}\fi%
+\ifnum\drwdfour>0\setlength{\drwdtemp}{.3333\drwdtemp}\fi%
+\ifnum\drwdfive>0\setlength{\drwdtemp}{.25\drwdtemp}\fi%
+\addtolength{\drwdmiddle}{\drwdtemp}%
+\fi\fi%
+%%%%% calc bezier positions %%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%\setlength{\drwdbezleft}{10pt}%
+%\ifdim\drwdbezleft>0.333\drwdone%
+\setlength{\drwdbezleft}{0.333\drwdone}%
+%\fi%
+%
+\ifnum\drwdtwo>0%
+\setlength{\drwdbezA}{\rstmargin}%
+\addtolength{\drwdbezA}{\drwdone}%
+\addtolength{\drwdbezA}{\drwdmiddle}%
+\addtolength{\drwdbezA}{.5\drwdtwo}%
+%\setlength{\drwdbezA}{.5\drwdgraph}% uncomment this for nicer (straight) lines in the middle - layout may break!
+\else%
+\addtolength{\drwdbezC}{.1666\drwdbezleft}% a single branch should go straight down %%%%%%%%%%%%%% was \drwdleft ???
+\fi%
+\ifnum\drwdthree>0%
+\setlength{\drwdbezB}{\rstmargin}%
+\addtolength{\drwdbezB}{\drwdone}%
+\addtolength{\drwdbezB}{\drwdmiddle}%
+\addtolength{\drwdbezB}{\drwdtwo}%
+\addtolength{\drwdbezB}{\drwdmiddle}%
+\addtolength{\drwdbezB}{.5\drwdthree}%
+\else%
+\addtolength{\drwdbezA}{.1666\drwdtwo}% the rightmost branch goes further to the right
+\fi%
+\ifnum\drwdfour>0%
+\setlength{\drwdbezC}{\rstmargin}%
+\addtolength{\drwdbezC}{\drwdone}%
+\addtolength{\drwdbezC}{\drwdmiddle}%
+\addtolength{\drwdbezC}{\drwdtwo}%
+\addtolength{\drwdbezC}{\drwdmiddle}%
+\addtolength{\drwdbezC}{\drwdthree}%
+\addtolength{\drwdbezC}{\drwdmiddle}%
+\addtolength{\drwdbezC}{.5\drwdfour}%
+\else%
+\addtolength{\drwdbezB}{.1666\drwdthree}% the rightmost branch goes further to the right
+\fi%
+\ifnum\drwdfive>0%
+\setlength{\drwdbezD}{\rstmargin}%
+\addtolength{\drwdbezD}{\drwdone}%
+\addtolength{\drwdbezD}{\drwdmiddle}%
+\addtolength{\drwdbezD}{\drwdtwo}%
+\addtolength{\drwdbezD}{\drwdmiddle}%
+\addtolength{\drwdbezD}{\drwdthree}%
+\addtolength{\drwdbezD}{\drwdmiddle}%
+\addtolength{\drwdbezD}{\drwdfour}%
+\addtolength{\drwdbezD}{\drwdmiddle}%
+\addtolength{\drwdbezD}{.6666\drwdfive}%
+\else%
+\addtolength{\drwdbezC}{.1666\drwdfour}% the rightmost branch goes further to the right
+\fi%
+%
+%
+%%%%% calc graph height %%%%%%%%%%%%%%%%%%%%%%%%%%
+\setlength{\drhegraph}{.25\drwdgraph}%
+%%%%% calc text height %%%%%%%%%%%%%%%%%%%%%%%%%%%
+\settorealheight{\drhetext}{\usebox{\rstboxone}}%
+\settorealheight{\drwdtemp}{\usebox{\rstboxtwo}}%
+\ifnum\drhetext<\drwdtemp\setlength{\drhetext}{\drwdtemp}\fi%
+\settorealheight{\drwdtemp}{\usebox{\rstboxthree}}%
+\ifnum\drhetext<\drwdtemp\setlength{\drhetext}{\drwdtemp}\fi%
+\settorealheight{\drwdtemp}{\usebox{\rstboxfour}}%
+\ifnum\drhetext<\drwdtemp\setlength{\drhetext}{\drwdtemp}\fi%
+\settorealheight{\drwdtemp}{\usebox{\rstboxfive}}%
+\ifnum\drhetext<\drwdtemp\setlength{\drhetext}{\drwdtemp}\fi%
+%%%%% calc total height %%%%%%%%%%%%%%%%%%%%%%%%%%
+\setlength{\drhetotal}{\drhetext}%
+\addtolength{\drhetotal}{\drhegraph}%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\setlength{\baselineskip}{0pt}%
+%\frame{%
+\limparbox{\drwdgraph}{\drhetotal}{%
+%
+\setlength{\unitlength}{\drhegraph}%
+\begin{picture}(0,1)(0,0)% spacing
+\end{picture}%
+% a \vspace at this point would lead to a line break...
+%
+\setlength{\unitlength}{\drwdgraph}% middle
+\setlength{\drwdtemp}{.5\drwdgraph}%
+%
+\begin{picture}(0,0)(0,0)%
+\qbezier(\LenToUnit{\drwdbezleft},0)(\LenToUnit{\drwdtemp},.25)(\LenToUnit{\drwdtemp},.25)%
+\ifnum\drwdtwo>0\qbezier(\LenToUnit{\drwdbezA},0)(\LenToUnit{\drwdtemp},.25)(\LenToUnit{\drwdtemp},.25)\fi%
+\ifnum\drwdthree>0\qbezier(\LenToUnit{\drwdbezB},0)(\LenToUnit{\drwdtemp},.25)(\LenToUnit{\drwdtemp},.25)\fi%
+\ifnum\drwdfour>0\qbezier(\LenToUnit{\drwdbezC},0)(\LenToUnit{\drwdtemp},.25)(\LenToUnit{\drwdtemp},.25)\fi%
+\ifnum\drwdfive>0\qbezier(\LenToUnit{\drwdbezD},0)(\LenToUnit{\drwdtemp},.25)(\LenToUnit{\drwdtemp},.25)\fi%
+%\qbezier(\LenToUnit{\drwdbezleft},0)(.5,.3)(\LenToUnit{\drwdbezright},0)%
+\end{picture}%
+%%%%%%%% spacer %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%
+\drhspacer{\rstmargin}%
+%
+% draw relation name %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% attention: these picture environments must overlap 100%. no spaces inbetween in source code allowed!
+\settowidth{\drwdtemp}{\relnamefont{#1}}%
+\setlength{\unitlength}{.5\drwdgraph}%
+\addtolength{\unitlength}{-.5\drwdtemp}%
+\begin{picture}(0,0)(0,0)%
+% we need to center the relation name...
+%\put(\LenToUnit{.5\drwdgraph},0.1025){\colorbox}%
+\put(1,\LenToUnit{.2\drhegraph}){\relnamefont{#1}}%
+\end{picture}%
+%
+%
+%%%%%% text and horizontal lines %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\settoheight{\unitlength}{\usebox{\rstboxone}}%
+\begin{picture}(0,0)(0,0)%
+\put(0,-1){\usebox{\rstboxone}}%
+\end{picture}%
+\setlength{\unitlength}{\drwdone}% left
+\begin{picture}(1,0)(0,0)% spacing
+\put(0,0){\line(1,0){1}}%
+\end{picture}%
+%
+\drhspacer{\drwdmiddle}%
+%
+\settoheight{\unitlength}{\usebox{\rstboxtwo}}% text
+\begin{picture}(0,0)(0,0)%
+\put(0,-1){\usebox{\rstboxtwo}}%
+\end{picture}%
+\setlength{\unitlength}{\drwdtwo}% spacing
+\begin{picture}(1,0)(0,0)%
+\put(0,0){\line(1,0){1}}%
+\end{picture}%
+%
+\drhspacer{\drwdmiddle}%
+%
+\ifnum\drwdthree>0%
+\settoheight{\unitlength}{\usebox{\rstboxthree}}% text
+\begin{picture}(0,0)(0,0)%
+\put(0,-1){\usebox{\rstboxthree}}%
+\end{picture}%
+\setlength{\unitlength}{\drwdthree}% spacing
+\begin{picture}(1,0)(0,0)%
+\put(0,0){\line(1,0){1}}%
+\end{picture}%
+%
+\drhspacer{\drwdmiddle}%
+\fi%
+%
+\ifnum\drwdfour>0%
+\settoheight{\unitlength}{\usebox{\rstboxfour}}% text
+\begin{picture}(0,0)(0,0)%
+\put(0,-1){\usebox{\rstboxfour}}%
+\end{picture}%
+\setlength{\unitlength}{\drwdfour}% spacing
+\begin{picture}(1,0)(0,0)%
+\put(0,0){\line(1,0){1}}%
+\end{picture}%
+%
+\drhspacer{\drwdmiddle}%
+\fi%
+%
+\ifnum\drwdfive>0%
+\settoheight{\unitlength}{\usebox{\rstboxfive}}% text
+\begin{picture}(0,0)(0,0)%
+\put(0,-1){\usebox{\rstboxfive}}%
+\end{picture}%
+\setlength{\unitlength}{\drwdfive}% spacing
+\begin{picture}(1,0)(0,0)%
+\put(0,0){\line(1,0){1}}%
+\end{picture}%
+%
+%\drhspacer{\drwdmiddle}%
+\fi%
+%\setlength{\unitlength}{\drhetext}% spacing
+%\begin{picture}(0,1)(0,0)%
+%\end{picture}%
+}%limpar
+%}% frame
+}% font
+% add margins to global width variable (needed for positioning if \compressionWidth works!)
+\returnrstrealwidths%
+\egroup%
+} % close \dirrel
+
+
+
+
+\newcommand{\rstsegment}[1]{\ifdim\terminalWidth>0pt\naturalparbox[\terminalWidth]{\vspace{1ex}\setlength{\baselineskip}{11pt}{\raggedright#1}\vspace{1ex}}\else\naturalparbox{\vspace{1ex}\setlength{\baselineskip}{11pt}{\raggedright#1}\vspace{1ex}}\fi%
+}%
+
+
+
+%\newcommand{\rstsegment}[1]{\vspace{1ex}\setlength{\baselineskip}{11pt}{\raggedright#1}}
+
+
+
+\newcommand\limparbox[4][c]{{\mbox{%
+\dimen0=2\fboxrule\advance\dimen0 2\fboxsep%
+\dimen1=#2\advance\dimen1 -\dimen0%
+\dimen2=#3\advance\dimen2 -\dimen0%
+\parbox[#1][\dimen2][t]{\dimen1}{#4}}}}%
+
+\newcommand\limfparbox[4][c]{\mbox{\fbox{%
+\dimen0=0pt%2\fboxrule\advance\dimen0 2\fboxsep%
+\dimen1=#2\advance\dimen1 -\dimen0%
+\dimen2=#3\advance\dimen2 -\dimen0%
+\parbox[#1][\dimen2][t]{\dimen1}{#4}}}}%
+
+
+
+
+% naturalparbox
+%
+% Crude attempt at making parboxes of `natural' width.
+%
+% Author: Stephan Lehmke <Stephan.Lehmke@cs.uni-dortmund.de>
+%
+% Originally, this belongs to the TeXPower package: http://texpower.sourceforge.net/
+
+\NeedsTeXFormat{LaTeX2e}
+
+%\ProvidesPackage{naturalparbox}
+%[2001/11/11 Attempt at making parboxes of `natural' width]
+
+\RequirePackage{ifthen}
+\RequirePackage{calc}
+
+% User-configurable: Which `resolution' should be used when searching for `best' width?
+\newcommand{\optwidthsteps}{100}
+
+% User-configurable: Which badness should be tolerated as `perfect' (stopping the search for a better one).
+\newcommand{\optwidthlinetolerance}{200}
+
+% Internal parameter: Badness of the parbox currently under consideration.
+\let\maxbadness@NPB=\@tempcnta
+
+\newlength{\maxheight@NPB}
+\newlength{\optwidth@NPB}
+\newlength{\tempdima@NPB}
+\newcounter{probe@NPB}
+\newboolean{carryon@NPB}
+\newbox\tempbox@NPB
+
+% \naturalparbox[<max width>][<max height>]{<contents>} will (try to)
+% automatically calculate the `best' width of a \parbox to contain
+% <contents> and then set <contents> into a \parbox of this width.
+%
+% The optional parameters <max width> (default \linewidth) and <max
+% height> (default \textheight) limit the growth of the box. If not
+% both can be respected, <max width> will be respected and <max
+% height> violated.
+%
+% Owing to limitations set by TeX, there are certain limits to the
+% sophistication of the procedure for finding the `optimal' width. For
+% instance, any `whatsits' (specials (like color changes), file
+% accesses (like \label), or hyper anchors) or rules which are
+% inserted directly in the vertical list of the parbox `block' the
+% analysis, so the procedure can't `see' past them (starting at the
+% bottom of the box) when analysing the contents of the parbox. The
+% user should make sure such items are set in horizontal mode (by
+% using \leavevmode or enclosing stuff in boxes). Furthermore, only
+% overfull and underfull hboxes which occur while setting the parbox
+% are considered when judging which width is `best'. This will
+% reliably make the width large enough to contain `wide' objects like
+% tabulars or included graphics, but might not give optimal results
+% for justified text.
+% vboxes occurring directly in the parbox are ignored.
+% Note further that hboxes with fixed width (made by \hbox to...)
+% which occur directly in the vbox may disturb the procedure, because
+% the fixed width cannot be recovered. These hboxes will be
+% reformatted with the width of the vbox, generating an extremely
+% large badness, unsettling the calculation of maximum badness. To
+% avoid this such hboxes should be either contained in a vbox or set
+% in horizontal mode with appropriate glue at the end.
+\newcommand{\naturalparbox}[1][\linewidth]{\def\maxwidth@NPB{#1}\@naturalparbox}
+
+\newcommand{\@naturalparbox}[2][\textheight]
+{%
+% Calculate `best' width of a parbox. The current algorithm will set the textual contents into parboxes of increasing
+% width, starting from 0pt and ending with the maximum width given, in \optwidthsteps steps. The `badness' of every
+% parbox is measured. If it is below the threshold defined by \optwidthlinetolerance, the process is stopped and the
+% found width accepted. If this doesn't happen, the width of the parbox with the least badness is returned.
+ \setcounter{probe@NPB}{0}% Initialize `probe counter' for box width.
+ \let\best@cnt@NPB=\empty% Initialize number of best `probe' so far.
+ \def\bestbadness@NPB{1000000}% Initialize badness of best `probe'.
+ \setboolean{carryon@NPB}{true}% Flag for breaking out of loop.
+ \setlength{\maxheight@NPB}{#1}% Store maximal box height.
+ \whiledo
+ {\value{probe@NPB}<\optwidthsteps\and\boolean{carryon@NPB}}% Probes done or break of loop?
+ {%
+ \stepcounter{probe@NPB}% Start next probe.
+ \setbox\@tempboxa=\vbox% The trick with vbox/lastbox is to get the vbox
+ {% produced by \parbox `immediately' into a box register.
+ \parbox[b]{(\maxwidth@NPB)/\optwidthsteps*\value{probe@NPB}}% Make the next parbox.
+ {\hfuzz\maxdimen\hbadness\@M\relax#2}%
+ \global\setbox\tempbox@NPB=\lastbox% ... and assign \tempbox@NPB to it.
+ }%
+ \setlength{\tempdima@NPB}{\ht\tempbox@NPB+\dp\tempbox@NPB}% Measure total height.
+ \ifthenelse{\lengthtest{\tempdima@NPB>\maxheight@NPB}}% If it exceeds the maximum height given, the box isn't
+ {}% acceptable anyway.
+ {%
+ \calcmaxbadness@NPB{\maxbadness@NPB}{\tempbox@NPB}% Calculate `worst badness' of any hbox appearing in parbox.
+ \ifthenelse{\not\maxbadness@NPB>\optwidthlinetolerance}% Below Threshold?
+ {% Yes. Accept this width.
+ \edef\best@cnt@NPB{\theprobe@NPB}% Store this probe number.
+ \setboolean{carryon@NPB}{false}% Break loop.
+ }
+ {% No. Carry on.
+ \ifthenelse{\maxbadness@NPB<\bestbadness@NPB}% Below lowest badness found so far?
+ {% Yes. Store probe number.
+ \edef\bestbadness@NPB{\number\maxbadness@NPB}% Store badness value.
+ \edef\best@cnt@NPB{\theprobe@NPB}% Store probe number.
+ }
+ {}% No. Try next probe.
+ }% matches second argument of \ifthenelse{\not\maxbadness@NPB>\optwidthlinetolerance}%
+ }% matches second argument of \ifthenelse{\lengthtest{\tempdima@NPB>\maxheight@NPB}}%
+ }% matches \whiledo{\value{probe@NPB}<\optwidthsteps\and\boolean{carryon@NPB}}{%
+ \ifx\best@cnt@NPB\empty% Was _any_ badness below the initialization value found?
+ \setlength{\optwidth@NPB}{\maxwidth@NPB}% No; return max width.
+ \else
+ \setlength{\optwidth@NPB}{(\maxwidth@NPB)/\optwidthsteps*\best@cnt@NPB}% Yes; return width of best probe.
+ \fi
+ \parbox{\optwidth@NPB}{#2}%
+ }
+
+% Calculate maximal badness of any hbox occurring in a vbox.
+\newcommand{\calcmaxbadness@NPB}[2]
+{%
+ \let\@resultcnt@NPB=#1% Here we store the result.
+ \global\@resultcnt@NPB=\z@\relax% Just in case no hbox occurs...
+ \setlength{\@tempdima}{\wd#2}% This is the width to which every hbox is stretched for finding its badness.
+ \setbox\@tempboxa=\vbox% A dummy vbox for recursively analysing the vbox contents using \lastbox
+ {%
+ \hfuzz\maxdimen\hbadness\@M
+ \unvbox#2% `free' the contents of the vbox.
+ \measureboxes@NPB% Analyse `tail to head' using \lastbox.
+ }%
+ }
+
+
+% Recursively analyse vertical list using \lastbox, to find maximum badness of any contained hbox.
+\newcommand{\measureboxes@NPB}%
+{%
+ \unskip\unpenalty\unkern% This is a kluge for TeX, because there is no certain way of finding out whether there's a
+ \unskip\unpenalty\unkern% penalty, glue or kern on the vertical list. \lastpenalty will give its value, but a
+ \unskip\unpenalty\unkern% value of 0 might mean there was none or there was one of value 0.
+ \unskip\unpenalty\unkern% This is different in eTeX. I might make a switch to a smarter solution.
+ \unskip\unpenalty\unkern
+ \unskip\unpenalty\unkern
+ \unskip\unpenalty\unkern
+ \unskip\unpenalty\unkern
+ \unskip\unpenalty\unkern
+ \unskip\unpenalty\unkern
+ \setbox\@tempboxa=\lastbox% Grab last box.
+ \ifhbox\@tempboxa% Was this an hbox?
+ \setbox0=\hb@xt@\@tempdima{\unhbox\@tempboxa}% Yes. Reformat with given width.
+ \ifnum\badness>\@resultcnt@NPB% Badness larger than largest recorded badness?
+ \global\@resultcnt@NPB=\badness% Yes. Memorize.
+ \fi
+ \expandafter\measureboxes@NPB% Recursive call.
+ \else
+ \ifvbox\@tempboxa% Was this a vbox?
+ \expandafter\expandafter\expandafter\measureboxes@NPB% Ignore, but execute recursive call.
+ \fi
+ \fi
+ }
diff --git a/macros/latex/contrib/rst/urml2latex.perl b/macros/latex/contrib/rst/urml2latex.perl
new file mode 100644
index 0000000000..f7f3170a90
--- /dev/null
+++ b/macros/latex/contrib/rst/urml2latex.perl
@@ -0,0 +1,385 @@
+#!/usr/bin/perl
+
+# create diagrams with the rst package in LaTeX from URML
+# args: urml2latex -i xmlfile docid analysis-id
+
+
+ # change this for relname replacements
+ sub replace_relname($)
+ {
+ my $rel = $_[0];
+
+ $rel =~ s/evaluation/eval/i;
+ $rel =~ s/elaboration/elab/i;
+ $rel =~ s/object/obj/i;
+ $rel =~ s/attribute/attr/i;
+ $rel =~ s/additional/addl/i;
+ return $rel;
+ }
+
+@args = ();
+$putSegmentsInTree=0;
+foreach(@ARGV)
+{
+ if (/\-i/i)
+ {
+ $putSegmentsInTree=1;
+ } else
+ {
+ push @args, $_;
+ }
+}
+
+$fn = $args[0];
+
+unless($fn)
+{
+ print "Converts a fully specified URML analysis to LaTeX rst format.\nUsage: urml2latex [-i] xmlfile [docid [analysis-id]]\n";
+ exit;
+}
+warn "loading $fn\n";
+
+{
+ local(*INPUT, $/);
+ open (INPUT, $fn) || die "can't open $fn: $!";
+ $f = <INPUT>;
+ close INPUT;
+}
+
+$docid = $args[1];
+$anaid = $args[2];
+
+if ($docid eq '')
+{
+
+print "printing all document ids: \n";
+
+while ($f =~ /\<document\s+id\s*=\s*(\"?)([^\">]+)(\"?)\s*>/isg)
+{
+ print $2."\n";
+}
+
+} else
+{
+
+ unless ($f =~ /<document\s+id\s*=\s*(\"?)$docid(\"?)\s*>(.*?)<\s*\/\s*document\s*>/is)
+ {
+ die "Document $docid not found.";
+
+ }
+
+
+ $doc = $3;
+
+
+
+ $docid =~ s/_//g;
+
+ # more than one analysis?
+ my $mdoc;
+
+ %ana = ();
+ while ($doc =~/<analysis\s+id\s*=\s*(\"?)(.*?)(\"?)\s*>(.*?)<\/\s*analysis\s*>/isg)
+ {
+ $ana{$2} = $4;
+
+ }
+ if (scalar keys %ana >1)
+ {
+ if ($anaid && exists($ana{$anaid}))
+ {
+ $mdoc = $ana{$anaid};
+ } else
+ {
+ print "Please specify the analysis of this document as argument. Printing all available analyses:\n";
+
+ foreach (keys %ana)
+ {
+ print $_."\n";
+ }
+ exit;
+
+ }
+
+ } else
+ {
+ $mdoc = $doc;
+ }
+ print $mdoc;
+ print "% rhetorical diagram\n";
+
+ # store all relations in a hash
+
+
+ while ($mdoc =~ /<\s*(relation|hypRelation|parRelation|segment)\s*(.*?)>(.*?)<\s*\/\1\s*>/isg)
+ {
+ my $relclass = $1;
+ my $relattr = $2;
+ my $relcontent = $3;
+
+
+ if ($relattr =~ /id\s*=\s*\"(.+?)\"/)
+ {
+ my $relid = $1;
+
+ # check relation
+ if ($relclass eq 'hypRelation' && !($relcontent =~ /<\s*nucleus/is))
+ {
+ warn "Node $relid is a $relclass, but has no nucleus -- ignoring that node!";
+ } else
+ {
+
+ $relid =~ s/_//g;
+
+ $relsxml{$relid} = $relcontent;
+ $relclass{$relid} = $relclass;
+
+ if ($relattr =~ /type\s*\=\s*\"(.*?)\"/is)
+ {
+ $reltype{$relid} = &replace_relname($1);
+ }
+ if ($relattr =~ /group\s*=\s*\"(.*?)\"/is)
+ {
+ $relgroup{$relid} = $1;
+ }
+
+
+ }
+
+
+ }
+ }
+
+ # bottom-up approach, start with segment
+
+ # assign labels
+ foreach(keys %relclass)
+ {
+ if ($relclass{$_} eq 'segment')
+ {
+ if ($putSegmentsInTree)
+ {
+ $rellatex{$_} = '\rstsegment{'.&conv_text($relsxml{$_}).'}';
+ } else
+ {
+ $rellatex{$_} = "\\rstsegment{\\refr{$_}}";
+ }
+ $complete{$_} = 1;
+ } else
+ {
+ $rellatex{$_} = $relsxml{$_};
+ $complete{$_} = 0;
+ }
+
+ }
+
+ # there is no top node, so we need to expand nodes sucessively.
+
+ while(1)
+ {
+ my $nodescompleted=0; # success count
+ my $uncompletenodes=0; # number of non-complete nodes in the chart
+
+ foreach(keys %relclass)
+ {
+ # if ($relclass{$_} eq 'segment')
+ # {
+ # my @parents = ();
+ # getParents($relid, \@parents);
+ #
+ # }
+ my $id = $_;
+ $rt = $reltype{$_};
+ $rc = $relclass{$_};
+ #only un-complete nodes
+ unless ($complete{$id})
+ {
+
+ $parentcomplete=1;
+ #print "before: $rellatex{$id} \n";
+ $rellatex{$id} =~ s/(<(satellite|nucleus|element)\s*(.*?)>)/&replaceDaughter($1,$2,$3);/isge;
+ #print "after: $rellatex{$id} \n";
+
+ $rellatex{$id} =~ s/^\s+//sg;
+ $rellatex{$id} =~ s/\s+$//sg;
+
+ if ($parentcomplete) # is complete after conv. of XML to LaTeX code
+ {
+ if ($rc eq 'hypRelation')
+ {
+ $rellatex{$id} = '\dirrel'.$rellatex{$id} ;
+ } elsif ($rc eq 'parRelation')
+ {
+ $rellatex{$id} = '\multirel{'.$rt.'}'.$rellatex{$id} ;
+ } else
+ {
+ warn "unspecified relation type: <relation> tag used!";
+ $rellatex{$id} = '\multirel'.$rellatex{$id} ;
+ }
+ $complete{$id} = 1;
+ $nodescompleted++;
+ }
+ $uncompletenodes++;
+ }
+
+
+ }
+ print "uncomp: $uncompletenodes compl: $nodescompleted\n";
+ last if ($uncompletenodes == 0);
+ if ($nodescompleted == 0)
+ {
+ warn "Not all nodes could be transformed to tree nodes -- circularities or undefined but referenced nodes in graph structure?\nPrinting largest existing analysis!";
+last;
+ }
+
+ }
+
+
+ #find biggest tree (with most nodes)
+
+ my $maxnodes=0;
+ my $largestnode = '';
+ foreach(keys %relclass)
+ {
+ if ($complete{$_})
+ {
+ #count nodes
+
+ my $nodes = 0;
+ while($rellatex{$_} =~ /\\(dir|multi)rel/isg)
+ {
+ $nodes++;
+ }
+ if ($nodes > $maxnodes)
+ {
+ $maxnodes = $nodes;
+ $largestnode = $_;
+ }
+ }
+ }
+
+ if($largestnode)
+ {
+ print $rellatex{$largestnode};
+ } else
+ {
+ warn "could not find largest node!";
+ foreach(keys %relclass)
+ {
+ if ($complete{$_})
+ {
+ print $rellatex{$_}."\n\n";
+ }
+
+ }
+ }
+
+ print "\n\n";
+
+ &pr_corpustext unless ($putSegmentsInTree);
+
+ exit;
+
+
+
+}
+
+sub replaceDaughter($$$$$)
+{
+ my $tag = $1;
+ my $role = $2;
+ my $attr = $3;
+# my $rc = $4; must be passed down as global vars
+# my $rt = $5;
+
+ #print "replace daughter tag=$tag role=$role attr=$attr \n";
+
+
+ if ($attr =~ /id\s*=\s*\"(.*?)\"/is)
+ {
+ my $did = $1; # daughter id
+ $did =~ s/_//g;
+ if ($complete{$did})
+ {
+ my $text = "";
+
+ if ($rc eq 'hypRelation')
+ {
+ if ($role eq 'satellite')
+ {
+ $text .= '{'.$rt.'}';
+ } else
+ {
+ $text .= '{}';
+ }
+
+ } else
+ {
+ $text .= '';
+ }
+
+ return $text.'{'.$rellatex{$did}.'}';
+ }
+ }
+
+ $parentcomplete=0; # parent is not complete because XML code returned
+ return $tag;
+}
+#
+# sub getParents($$)
+# {
+# my \@parents = $_[1];
+# my $id = $_[0];
+# foreach(keys %relclass)
+# {
+# if ($relcontent =~ /id\s*=\s*\"$id\"/)
+# {
+# push @parents, $id;
+# }
+# }
+#
+# }
+
+
+sub pr_corpustext
+{
+
+print '\begin{rhetoricaltext}'."\n";
+while($doc =~ /<segment\s+id\s*=\s*(\"?)([^\">]+)(\"?)[^>]*>(.*?)<\/\s*segment\s*>/isg )
+{
+ my $segid = $2;
+ my $seg = $4;
+
+ #$segid =~ s/$docid\.?//;
+ $segid =~ s/_//g;
+
+
+ $seg = &conv_text($seg);
+
+
+ if ($seg)
+ { print "\\unit[$segid]{$seg}\n";
+ }
+}
+print '\source{'."$docid}".'\end{rhetoricaltext}'."\n";
+return;
+
+}
+
+
+sub conv_text ($)
+{
+my $seg = $_[0];
+
+ $seg =~ s/\<\/?sign[^>]*>//isg;
+
+ $seg =~ s/(Ä|\&Auml;)/\\\"\{A\}/sg;
+ $seg =~ s/(Ö|\&Ouml;)/\\\"\{O\}/sg;
+ $seg =~ s/(Ü|\&Uuml;)/\\\"\{U\}/sg;
+ $seg =~ s/(ä|\&auml;)/\\\"\{a\}/sg;
+ $seg =~ s/(ö|\&ouml;)/\\\"\{o\}/sg;
+ $seg =~ s/(ü|\&uuml;)/\\\"\{u\}/sg;
+ $seg =~ s/(ß|\&szlig;)/\\\"\{ss\}/sg;
+ $seg =~ s/\$/\\\$/sg;
+ return $seg;
+}