2

pregroup grammar

I want to draw arches (possibly overlapping or nested) between variables, in an equation, and the line straight down. A replication of the image above.

If possible I would like the arches to have labels and words displayed above the variables.

I did not succeed with tikz.

1 Answers1

4

One idea, similar to the solutions at How to draw arrows between parts of an equation to show the Math Distributive Property (Multiplication)?

\documentclass{article}
\usepackage{tikz}
\tikzset{mtm/.style={
  remember picture,
  inner sep=0pt,
  outer ysep=0.1em,
}}
\newcommand\mtm[2]{\tikz[mtm] \node[anchor=base] (#1) {$#2\mathstrut$};}

\begin{document} Test text test text test text. Test text test text test text. Test text test text test text. Test text test text test text. \begin{equation} \mtm{n}{n} \quad \mtm{nr}{n^r} \mathbin{} \mtm{s}{s} \mathbin{} \mtm{nl}{n^l} \quad \mtm{n2}{n} \begin{tikzpicture}[thick,looseness=1.8,overlay,remember picture] \draw (n.south) to[out=-90,in=-90] (nr.south); \draw (s.south) -- ++(0,-2em); \draw (nl.south) to[out=-90,in=-90] (n2.south); \end{tikzpicture} \vspace{1.5em} % to allow space for the descending line \end{equation} Test text test text test text. Test text test text test text. Test text test text test text. Test text test text test text. \end{document}

enter image description here

Explanation of the code

\tikzset{mtm/.style={
  remember picture,
  inner sep=0pt,
  outer ysep=0.1em,
}}

A style to use throughout mtm ("math TikZ mark") nodes. remember picture is needed so the node names can be referred to later by our overall drawing. inner sep=0pt ensures that math spacing is not affected. outer ysep=0.1em adds a bit of padding between the line we draw later and the math variable.

\newcommand\mtm[2]{\tikz[mtm] \node[anchor=base] (#1) {$#2\mathstrut$};}

A macro to place our "math TikZ mark" nodes. It accepts 2 arguments. The first is the node name (which we'll use later). The second is the node contents to print, assuming we're in a math mode context. anchor=base and \mathstrut just to cover all bases for alignment with subscripts/superscripts/ascenders/descenders/etc.

\begin{equation}
  \mtm{n}{n} \quad \mtm{nr}{n^r} \mathbin{} \mtm{s}{s} \mathbin{} 
    \mtm{nl}{n^l} \quad \mtm{n2}{n}

Within the equation, we write things normally (I added manual spacing commands to approximate the spacing in your image; I assume you have a more formal way of specifying what these spaces should be). Except, wherever there is a variable we need to use in the drawing (for example n) we use \mtm{n}{n}. The node names must be unique, so for the second n, we use mtm{n2}{n} where n2 is the node name for this second n.

  \begin{tikzpicture}[thick,looseness=1.8,overlay,remember picture]
    \draw (n.south) to[out=-90,in=-90] (nr.south);
    \draw (s.south) -- ++(0,-2em);
    \draw (nl.south) to[out=-90,in=-90] (n2.south);
  \end{tikzpicture}

After we finish writing the equation, we add a tikzpicture to place the annotations. overlay,remember picture are required so the picture can be placed over the already-typeset mathematics and refer back to those node names.

  \vspace{1.5em} % to allow space for the descending line
\end{equation}

At the end of the equation, we have to add some extra space to leave room for the tikzpicture since it doesn't take up any "space" on the page.

Caveats

\displaystyle for fractions, operator limits, spacing, etc. will be lost, since I enter inline math inside the nodes. You could add this to the definition of \mtm if desired, though it doesn't matter for this use case.

The \vspace amount has to be tuned per picture—if the size of your annotations changes, the extra space will have to change as well.

Paul Gessler
  • 29,607