summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/movement-arrows/movement-arrows.sty
blob: 48fe4b288ec1460891c48f21d32898370a7dbed8 (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
% 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
%
\def\MVA@version{1.0b}
\ProvidesPackage{movement-arrows}[2023/05/22 v \MVA@version]
\@ifpackageloaded{gb4e}{\noautomath}{}
\RequirePackage{tikz}
\usetikzlibrary{ext.paths.ortho}
\RequirePackage{etoolbox}
\RequirePackage{calc}
\NewDocumentCommand{\mkword}{om}{%
\IfNoValueTF{#1}
{\tikz[remember picture, baseline=(#2.base)] \node[anchor=base,inner sep=0pt, outer sep=0pt] (#2) {#2};}
{\tikz[remember picture, baseline=(#1.base)] \node[anchor=base,inner sep=0pt, outer sep=0pt] (#1) {#2};}
}
\tikzset{
    arrow/.style={->,shorten >=3pt,shorten <=3pt},
	circ/.style = {
  		draw,circle,solid,
  		node contents=#1,
  		fill=white,
  		inner xsep=.2em,
  		inner ysep=0pt
}
}
\newlength{\arrowheight}
\setlength{\arrowheight}{2.5ex}
\newlength{\extraexheight}
\setlength{\extraexheight}{1ex}
\newlength{\MVA@arrowht}
\setlength{\MVA@arrowht}{\arrowheight}
\newlength{\MVA@strutheight}
\newcommand*\MVA@arrowstrut{%
	\setlength{\MVA@strutheight}{\MVA@arrowht+\extraexheight}%
	{\vrule height 0pt depth \MVA@strutheight width 0pt}}
\let\arrowstrut\MVA@arrowstrut

\NewDocumentCommand{\arrow}{somm}{
\IfBooleanTF{#1}
{\setlength{\MVA@arrowht}{-\arrowheight}
\def\MVA@rightanchor{north}\let\MVA@leftanchor\MVA@rightanchor}
{\setlength{\MVA@arrowht}{\arrowheight}
\def\MVA@rightanchor{base}\let\MVA@leftanchor\MVA@rightanchor}
\IfNoValueTF{#2}
{
\begin{tikzpicture}[remember picture,overlay]
\draw[arrow] (#3.\MVA@rightanchor) r-du[du distance=\MVA@arrowht] (#4.\MVA@leftanchor);
\end{tikzpicture}
}
{\begin{tikzpicture}[remember picture,overlay]
\draw[arrow] (#3.\MVA@rightanchor)  r-du[du distance=\MVA@arrowht] node[#2] {}  (#4.\MVA@leftanchor);
\end{tikzpicture}}
\MVA@arrowstrut
\setlength{\MVA@arrowht}{0ex}
}

\AtBeginDocument{%
\ifdefined\eachwordone\preto{\eachwordone}{\MVA@arrowstrut}\renewcommand\glt{\vskip -1.2\arrowheight}
\let\trans=\glt
\fi}