diff options
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/tikz-dependency/tikz-dependency.sty | 209 |
1 files changed, 209 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/tikz-dependency/tikz-dependency.sty b/Master/texmf-dist/tex/latex/tikz-dependency/tikz-dependency.sty new file mode 100644 index 00000000000..6aa31c3c867 --- /dev/null +++ b/Master/texmf-dist/tex/latex/tikz-dependency/tikz-dependency.sty @@ -0,0 +1,209 @@ +\ProvidesPackage{tikz-dependency}[2011/01/08 v1.0 Macros to draw dependency trees] +\NeedsTeXFormat{LaTeX2e}[1999/12/01] + +\RequirePackage{tikz,environ} +\usetikzlibrary{matrix,arrows,backgrounds,calc,patterns,positioning,fit} + +\pgfdeclarelayer{depgroups} +\pgfsetlayers{depgroups,main} + +\newcounter{dt@labelid} +\newif\ifdt@linkbelow +\tikzset{ + /depgraph/.cd, + /depgraph/.search also = {/tikz}, + dep id/.code = {\def\dt@depid{#1}}, + dep id = dependency, + % the distant of the horizontal line of the edge style for two adjacent words + edge unit distance/.code = {\pgfmathsetlengthmacro{\dt@linkstep}{#1}}, + edge unit distance = 3ex, + % the horizontal offset defining the trapezoidal look + edge slant/.code = {\pgfmathsetlengthmacro{\dt@linkslant}{#1}}, + edge slant = 3pt, + % the horizontal offset defining the starting/ending position of the edge style + edge horizontal padding/.code = {\pgfmathsetlengthmacro{\dt@linkoffset}{#1}}, + edge horizontal padding = 4pt, + % vertical offset of the edge style from the word + edge vertical padding/.code = {\pgfmathsetlengthmacro{\dt@linkdist}{#1}}, + edge vertical padding = 0ex, + % should links be placed above or below the sentence + edge below/.is if = dt@linkbelow, + edge below/.default=true, + edge above/.code = {\dt@linkbelowfalse}, + % the layer that links should connect + % (should be set to "1" for edge above, and to the number of rows + % in the matrix for edge below) + target layer/.store in = \dt@tgtlayer, + target layer/.default = 0, + target layer = 0, + % styling options + reserved/edge style/.style = {->, >=stealth, black, solid, rounded corners = 2, line cap = round}, + edge style/.style = {reserved/edge style/.append style = {#1}}, + reserved/label style/.style = { + anchor = mid, + draw, solid, + black, + scale = .7, + text height = 1.5ex, text depth = 0.25ex, % needed to center text vertically + inner sep=.5ex, + outer sep = 0pt, + rounded corners = 2pt, + text = black, + fill = white}, + label style/.style = {reserved/label style/.append style = {#1}}, + hide label/.style = {reserved/label style/.append style = {opacity = 0, text opacity = 0}}, + show label/.style = {reserved/label style/.append style = {opacity = 1, text opacity = 1}}, + reserved/text style/.style = { + text height=1.5ex, text depth = 0.25ex, % needed to center text vertically + inner sep = .5ex}, + text style/.style = {reserved/text style/.append style = {#1}}, + reserved/group style/.style = { + inner sep = 0, + draw, solid, + outer sep = .5ex, + rounded corners = 2pt}, + group style/.style = {reserved/group style/.append style = {#1}}, +} + +\newenvironment{dependency}[1][]{% + \begin{tikzpicture} + \begin{scope}[/depgraph/.cd, #1] +}{% + \end{scope}% + \end{tikzpicture}% +} + +\NewEnviron{deptext}[1][]{% + \begin{scope} + \matrix (\dt@depid)[% + nodes = {/depgraph/reserved/text style}, + column sep = 0, + row sep = -.5ex, + matrix of nodes, + ampersand replacement = \&, + nodes in empty cells, + #1] { + \BODY% + };% + \pgfmathtruncatemacro\dt@tmp{\pgfmatrixcurrentrow} + \xdef\dt@numrows{\dt@tmp} + \end{scope}% +} + +\newcommand{\depkeys}[1]{\tikzset{/depgraph/.cd, #1}} + +\newcommand{\settgtlayer}{% + \ifnum\dt@tgtlayer=0% + \ifdt@linkbelow% + \pgfmathtruncatemacro{\dt@tgtlayer}{\dt@numrows}% + \else% + \pgfmathtruncatemacro{\dt@tgtlayer}{1}% + \fi% + \fi% +} + +\newcommand{\deproot}[3][]{% options, root offset, root reserved/label style + \begin{scope} + \depkeys{#1} + \pgfmathsetmacro{\offa}{#2} + \settgtlayer + \def\anchorpoint{north} + \ifdt@linkbelow + \def\anchorpoint{south} + \fi + \def\source{\dt@depid-\dt@tgtlayer-#2} + \pgfmathsetmacro{\distance}{\dt@linkstep * 4} + \pgfmathsetlengthmacro{\dt@startdist}{\dt@linkdist} + \ifdt@linkbelow + \pgfmathsetmacro{\distance}{-(\dt@linkstep * 4)} + \pgfmathsetlengthmacro{\dt@startdist}{-\dt@startdist} + \fi + \node at (\source) (\rootref) [yshift=\distance, /depgraph/.cd, reserved/label style, #1] {#3}; + \draw [/depgraph/.cd, reserved/edge style, #1] (\rootref) -- ($(\source.\anchorpoint) + (0, \dt@startdist)$); + \end{scope} +} + +\newcommand{\depedge}[4][]{% options, source offset, target offset, dep name + \begin{scope} + \depkeys{#1} + \pgfmathsetmacro{\offa}{#2} + \pgfmathsetmacro{\offb}{#3} + \settgtlayer + \def\source{\wordref{\dt@tgtlayer}{#2}} + \def\dest{\wordref{\dt@tgtlayer}{#3}} + \def\depname{#4} + \pgfmathsetlengthmacro{\distance}{abs(\offb - \offa)*\dt@linkstep} + \groupedge[#1]{\source}{\dest}{\depname}{\distance} + \end{scope}} + +\newlength{\xca} +\newlength{\yca} +\newlength{\xcb} +\newlength{\ycb} + +\newcommand{\wordref}[2]{\dt@depid-#1-#2} + +\newcommand{\rootref}{\dt@depid-root} + +\newcommand{\matrixref}{\dt@depid} + +% \storelabelnode +% +% \edef#1 the name of the last reserved/label style, stored in \dt@lastlabel +% +% #1 - a macro +\newcommand{\storelabelnode}[1]{\edef#1{\dt@lastlabel}} + +\newcommand{\storefirstcorner}[1]{\edef#1{\dt@lastlabel-edge-first-corner}} +\newcommand{\storesecondcorner}[1]{\edef#1{\dt@lastlabel-edge-second-corner}} + +\newcommand{\wordgroup}[5][]{% options, layer, col-start, col-end, identifier + \begin{scope}[/depgraph/.cd, #1] + \pgfonlayer{depgroups} + \node (#5) [fit = (\wordref{#2}{#3}) (\wordref{#2}{#4}), /depgraph/.cd, reserved/group style, #1] {}; + \endpgfonlayer + \end{scope} +} + +\newcommand{\groupedge}[5][]{% options, source, target, depname, distance + \begin{scope}[/depgraph/.cd, #1] + \def\anchorpoint{north} + \ifdt@linkbelow + \def\anchorpoint{south} + \fi + \pgfextractx{\xca}{\pgfpointanchor{#2}{\anchorpoint}} + \pgfextractx{\xcb}{\pgfpointanchor{#3}{\anchorpoint}} + \pgfextracty{\yca}{\pgfpointanchor{#2}{\anchorpoint}} + \pgfextracty{\ycb}{\pgfpointanchor{#3}{\anchorpoint}} + \pgfmathsetlengthmacro{\ydiff}{abs(\yca-\ycb)} + \ifdim\xca>\xcb + \pgfmathsetlengthmacro{\doff}{-\dt@linkoffset} + \pgfmathsetlengthmacro{\dslant}{-\dt@linkslant} + \else + \pgfmathsetlengthmacro{\doff}{\dt@linkoffset} + \pgfmathsetlengthmacro{\dslant}{\dt@linkslant} + \fi + \addtocounter{dt@labelid}{1} + \xdef\dt@lastlabel{\dt@depid-\the\value{dt@labelid}} + \pgfmathsetlengthmacro{\dt@startdist}{\dt@linkdist} + \pgfmathsetlengthmacro{\dt@enddist}{#5} + \ifdt@linkbelow + \pgfmathsetlengthmacro{\dt@startdist}{-\dt@startdist} + \pgfmathsetlengthmacro{\dt@enddist}{-\dt@enddist} + \fi + \node (\dt@lastlabel-edge-origin) [coordinate] at ($(#2.\anchorpoint) + (\doff,\dt@startdist)$) {}; + \node (\dt@lastlabel-edge-first-corner) [coordinate] at ($(\dt@lastlabel-edge-origin) + (\dslant,\dt@enddist)$) {}; + \node (\dt@lastlabel-edge-second-corner) [coordinate] at ($(#3.\anchorpoint) + (-\dslant,\dt@enddist+\dt@startdist+\ydiff)$) {}; + \node (\dt@lastlabel-edge-endpoint) [coordinate] at ($(#3.\anchorpoint) + (0,\dt@startdist)$) {}; + + \draw [/depgraph/.cd, reserved/edge style, rounded corners = #5/5, #1] + (\dt@lastlabel-edge-origin) -- + (\dt@lastlabel-edge-first-corner) -- + (\dt@lastlabel-edge-second-corner) -- + (\dt@lastlabel-edge-endpoint); + \node (\dt@lastlabel) [/depgraph/.cd, #1, reserved/label style] at + ($ .5*(\dt@lastlabel-edge-second-corner) + .5*(\dt@lastlabel-edge-first-corner) $) + {#4}; + \end{scope} +} + |