Created
April 27, 2021 20:16
-
-
Save enricoflor/414da162e13983f8c9a235156a6be1eb to your computer and use it in GitHub Desktop.
Draw syntactic movement arrows in examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% movementarrows.tex - A LaTeX snippet with TikZ generated syntactic | |
% movement arrows | |
% Written in 2021 by Enrico Flor mail@enricoflor.net | |
% To the extent possible under law, the author(s) have dedicated all copyright | |
% and related and neighboring rights to this software to the public domain | |
% worldwide. This software is distributed without any warranty. | |
% You should have received a copy of the CC0 Public Domain Dedication along with | |
% this software. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>. | |
\documentclass{article} | |
\usepackage{tikz} | |
\usetikzlibrary{positioning,calc} | |
\newcommand{\anc}[2]{\tikz[remember picture,baseline,inner sep=0] | |
\node[anchor=base](#2) {{#1}\hspace{-1.5ex}\phantom{lf}};} | |
\NewDocumentCommand\moveabove{O{->}mmmO{}O{0cm}}% | |
{\tikz[remember picture,overlay] \node[above = #4 of #2.center] | |
(angle1) {}; | |
\tikz[remember picture,overlay] \path let \p1 = (#3), \p2 = (angle1) in | |
node (angle2) at (\x1,\y2) {}; | |
\tikz[remember picture,overlay,#1] \path[draw] (#2) -- (angle1.center) | |
-- (angle2.center) -- (#3); | |
\tikz[remember picture,overlay] \path (angle1) to node [above,xshift=#6]{\scriptsize | |
{#5}} (angle2); | |
} | |
\NewDocumentCommand\movebelow{O{->}mmmO{}O{0cm}}% | |
{\tikz[remember picture,overlay] \node[below = #4 of #2.center] (angle1) {}; | |
\tikz[remember picture,overlay] \path let \p1 = (#3), \p2 = (angle1) in | |
node (angle2) at (\x1,\y2) {}; | |
\tikz[remember picture,overlay,#1] \path[draw] (#2) -- (angle1.center) | |
-- (angle2.center) -- (#3); | |
\tikz[remember picture,overlay] \path (angle1) to node [below,xshift=#6]{\scriptsize | |
{#5}} (angle2); | |
} | |
\begin{document} | |
Let's \anc{see}{p1} how this little thing \anc{works}{p2} | |
\moveabove{p2}{p1}{1.5ex}[label] | |
\moveabove{p2}{p1}{2em}[label][-4ex] % you can move the label to the right | |
% or left | |
% The default shape is a simple arrow, but the first optional argument | |
% lets you customize just as much as TikZ lets you: | |
\movebelow[dashed,ultra thick,<->,color=gray]{p1}{p2}{2em}[a label to | |
the right][2em] | |
% It requires a recent version of LaTeX to work as is. | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment