summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/movement-arrows/movement-arrows.sty
blob: 61147a87b20fc49edaf4a8f849da02e9723f595a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
% movement-arrows
% Draw movement arrows on example sentences including glossed sentences
% Copyright 2023 by Alan Munn <amunn@msu.edu>
% 
%
% This package may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This package has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this package is Alan Munn.
%%
% Version 1.0 2023-05-21 Initial release
% Version 1.0b 2023-05-22 Fixed documentation typo
% Version 2.0 2023-06-01 added \arrowgloss to fix strut problem
%						 made package more general, added \mvlink command, new styles
%					     renamed arrow command to be \mvarrow
%
%
%
\def\MVA@version{2.0}
\ProvidesPackage{movement-arrows}[2023/06/02 v \MVA@version]
\@ifpackageloaded{gb4e}{\noautomath}{}
\RequirePackage{tikz}
\usetikzlibrary{ext.paths.ortho}
\RequirePackage{etoolbox}
\RequirePackage{calc}
\newif\ifMVA@mmode
\NewDocumentCommand{\mkword}{om}{%
\ifmmode\MVA@mmodetrue\else\MVA@mmodefalse\fi
\IfNoValueTF{#1}
{\tikz[remember picture, baseline=(#2.base)] \node[anchor=base,inner sep=0pt, outer sep=0pt] (#2) {\ifMVA@mmode\ensuremath{#2}\else#2\fi};}
{\tikz[remember picture, baseline=(#1.base)] \node[anchor=base,inner sep=0pt, outer sep=0pt] (#1) {\ifMVA@mmode\ensuremath{#2}\else#2\fi};}
}
\tikzset{
	circ/.style = {
  		draw,circle,solid,
  		node contents=#1,
  		fill=white,
  		inner xsep=.2em,
  		inner ysep=0pt
},
    link/.style={#1,shorten >=3pt,shorten <=3pt},
    above/.style = {label=above:#1},
    below/.style = {label=below:#1}
}
\newlength{\arrowheight}
\newlength{\MVA@arrowstrutheight}
\setlength{\MVA@arrowstrutheight}{3ex}
\setlength{\arrowheight}{2.5ex}
\newlength{\extraexheight}
\setlength{\extraexheight}{1.5ex}
\newlength{\glarrowheight}
\setlength{\glarrowheight}{\arrowheight+\extraexheight}
\newlength{\MVA@arrowht}
\newlength{\MVA@extraht}
\setlength{\MVA@arrowht}{0ex}
\setlength{\MVA@extraht}{0ex}
\newcommand*\MVA@arrowstyle{->}
\newcommand*\setarrowstyle[1]{\gdef\MVA@arrowstyle{#1}}
\newif\ifMVA@arrowgloss
\newlength{\MVA@strutheight}
\newcommand*\MVA@arrowstrut{%
	\setlength{\MVA@strutheight}{\MVA@arrowht+\MVA@extraht}%
	{\vrule height 0pt depth \MVA@strutheight width 0pt}}

\newcommand*\arrowgloss{\setlength{\MVA@arrowht}{\arrowheight}\setlength{\MVA@extraht}{\extraexheight}\global\MVA@arrowglosstrue}
\newcommand*\arrowstrut{\vspace*{\MVA@arrowstrutheight}}

\NewDocumentCommand{\mvarrow}{somm}{%
\ifMVA@arrowgloss\else\arrowstrut\fi
\IfBooleanTF{#1}%
{\setlength{\MVA@arrowht}{-\arrowheight}
 \setlength{\MVA@extraht}{-\extraexheight}
\def\MVA@rightanchor{north}\let\MVA@leftanchor\MVA@rightanchor}
{\setlength{\MVA@arrowht}{\arrowheight}
\setlength{\MVA@extraht}{\extraexheight}
\def\MVA@rightanchor{base}\let\MVA@leftanchor\MVA@rightanchor}
\IfNoValueTF{#2}
{%
\begin{tikzpicture}[remember picture,overlay]
\draw[link=\MVA@arrowstyle] (#3.\MVA@rightanchor) r-du[du distance=\MVA@arrowht] (#4.\MVA@leftanchor);
\end{tikzpicture}
}
{\begin{tikzpicture}[remember picture,overlay]
\draw[link=\MVA@arrowstyle] (#3.\MVA@rightanchor)  r-du[du distance=\MVA@arrowht] node[#2] {}  (#4.\MVA@leftanchor);
\end{tikzpicture}}
\global\MVA@arrowglossfalse%
\setlength{\MVA@arrowht}{0ex}
\setlength{\MVA@extraht}{0ex}
}
\NewDocumentCommand{\mvlink}{somm}{%
\ifMVA@arrowgloss\else\arrowstrut\fi
\IfBooleanTF{#1}%
{\setlength{\MVA@arrowht}{-\arrowheight}
 \setlength{\MVA@extraht}{-\extraexheight}
\def\MVA@rightanchor{north}\let\MVA@leftanchor\MVA@rightanchor}
{\setlength{\MVA@arrowht}{\arrowheight}
\setlength{\MVA@extraht}{\extraexheight}
\def\MVA@rightanchor{base}\let\MVA@leftanchor\MVA@rightanchor}
\IfNoValueTF{#2}
{%
\begin{tikzpicture}[remember picture,overlay]
\draw[link] (#3.\MVA@rightanchor) r-du[du distance=\MVA@arrowht] (#4.\MVA@leftanchor);
\end{tikzpicture}
}
{\begin{tikzpicture}[remember picture,overlay]
\draw[link] (#3.\MVA@rightanchor)  r-du[du distance=\MVA@arrowht] node[#2] {}  (#4.\MVA@leftanchor);
\end{tikzpicture}}
\global\MVA@arrowglossfalse%
\setlength{\MVA@arrowht}{0ex}
\setlength{\MVA@extraht}{0ex}
}
\AtBeginDocument{%
\ifdefined\eachwordone\preto{\eachwordone}{\MVA@arrowstrut}
\fi}