% 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}

