# Add Annotations and Remarks next to Equations

for a thesis I am currently writing on, I would like to highlight and explain some mathematical transformations inside the equations (to explain why the transformation holds). Of course, I could "interrupt" the mathematical proof and explain the transformation in a new line, but I think it is nicer if the annotations are written directly next to the lines they are related to. I already thought about creating a table or two minipages, but I wasn't sure if there is a nicer way to do it.

Attached you will find a simple example (the actual equation is more complicated), just in order to get an idea what I am thinking of. The arrows are not mandatory, but it would be nice if the annotation is written between the mathematical lines (but the spacing of the equation should not change because of the annotation). Thank you for your help!

\documentclass{scrartcl}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}

\begin{document}

\begin{equation*}
\begin{split}
\textrm{OPT} & = \textrm{OPTL} + \textrm{OPTR} \\
& = (x+y) + (y+z) \\
& \leq 2* (y+z) \\
& = \textrm{OPTR} + \textrm{OPTR}
\end{split}
\end{equation*}

\end{document}


The witharrows package can do something like this.

\documentclass{scrartcl}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{witharrows}

\WithArrowsOptions{tikz={font={\normalfont\small}}}

\begin{document}

\begin{equation*}
\begin{WithArrows}
\mathrm{OPT} & = \mathrm{OPTL} + \mathrm{OPTR}\Arrow{Definition of $\mathrm{OPT}$ and $\mathrm{OPTR}$} \\
& = (x+y) + (y+z)\Arrow{As $x \leq z$} \\
& \leq 2* (y+z)\Arrow{Definition of $\mathrm{OPTR}$} \\
& = \mathrm{OPTR} + \mathrm{OPTR}
\end{WithArrows}
\end{equation*}

\end{document}


There is a semi-automatic way to get line breaks in the text as well, you will need to specify a text width, then the label will be broken to fit into the horizontal space.

\mathrm{OPT} & = \mathrm{OPTL} + \mathrm{OPTR}
\Arrow[tikz={text width=5.3cm}]{Definition of $\mathrm{OPT}$ and $\mathrm{OPTR}$,
furthermore we use the well-known Unicorn theorem} \\


This solution is semi-automatic since you have to find a good value for text-width yourself meaning that for occasional use it is probably not faster than giving manual breaks with \\.

As soon as the text occupies multiple lines you run the risk of running into the labels above or below.

Version 1.9 of witharrows define a replacement environments for align in which labels can be wrapped automatically. Thanks to F. Pantigny for the hint in the comments.

\begin{DispWithArrows*}[wrap-lines]
\mathrm{OPT} & = \mathrm{OPTL} + \mathrm{OPTR}\Arrow{Definition of $\mathrm{OPT}$ and $\mathrm{OPTR}$,
and the Unicorn theorem} \\
& = (x+y) + (y+z)\Arrow{As $x \leq z$} \\
& \leq 2* (y+z)\Arrow{Definition of $\mathrm{OPTR}$} \\
& = \mathrm{OPTR} + \mathrm{OPTR}
\end{DispWithArrows*}

• Thank you all for your help. I first tried moewe's solution, but if I add very long annotations, they are longer than the normal textwidth of the page. Is there a way so that the annotation inside Arrow makes a line break automatically? See picture: imgur.com/a2cbJqH – Unicorn Jun 2 '18 at 19:08
• @Unicorn You can add a line break with \\, but then it gets a bit crowded. – moewe Jun 2 '18 at 19:10
• Yes I know, \\ should be fine too, just wanted to make sure that there was no way for the package to do the line break itself, so that I don't have to do it manually. – Unicorn Jun 2 '18 at 19:19
• With the last version of witharrows (version 1.9, 2018/08/18), there is a option wrap-lines for the environments DispWithArrows which breaks lines automatically. – F. Pantigny Aug 18 '18 at 9:58
• @F.Pantigny Thanks for the hint. I will check it out and edit the answer when MikTeX updates the package in the next few days and if I don't forget it. – moewe Aug 18 '18 at 10:34

I propose one of these two possibilities, based on alignat:

\documentclass{scrartcl}

\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{showframe}
\renewcommand{\ShowFrameLinethickness}{0.3pt}

\DeclareFontFamily{U}{mathb}{\hyphenchar\font45}
\DeclareFontShape{U}{mathb}{m}{n}{ <-6> mathab5 <6-7> mathb6 <7-8>
mathb7 <8-9> mathb8 <9-10> mathb9 <10-12> mathb10 <12-> mathb12 }{}
\DeclareSymbolFont{mathb}{U}{mathb}{m}{n}
%
\DeclareMathSymbol{\dlsh}{\mathrel}{mathb}{"EA}

\begin{document}

\begin{alignat*}{2}
\textrm{OPT} & = \textrm{OPTL} + \textrm{OPTR} \\
& = (x+y) + (y+z) & \hspace{4em}& \rlap{\footnotesize Definition of OPTL and OPTR}\\
& \leq 2* (y+z) & & \text{\footnotesize As $x \le z$}\\
& = \textrm{OPTR} + \textrm{OPTR} & &\rlap{\footnotesize Definition of OPTR}
\end{alignat*}

\begin{alignat*}{2}
\textrm{OPT} & = \textrm{OPTL} + \textrm{OPTR} \\[-1ex]
& = (x+y) + (y+z) \\[-1ex] %
& & & \dlsh \quad \text{\footnotesize As $x \le z$} \\[-1ex]
& \leq 2* (y+z) \\[-1ex]
& & & \dlsh\quad\text{\footnotesize Definition \rlap{of OPTR}} \\[-1ex]
& = \textrm{OPTR} + \textrm{OPTR}
\end{alignat*}

\end{document}


A variant of Bernard’s answer that rotates one of the amssymb arrows ninety degrees. This arrow is also in Unicode, so this code works out of the box with unicode-math as well.

\documentclass[varwidth, preview]{standalone}

\usepackage{mathtools}
\usepackage{amssymb} % or unicode-math
\usepackage{graphicx}

\newcommand\arrownext{\rotatebox[origin=c]{-90}{\ensuremath{\curvearrowright}}}
\newcommand\OPTL{\mathop{\mathrm{OPTL}}}
\newcommand\OPTR{\mathop{\mathrm{OPTR}}}
\newcommand\OPT{\mathop{\mathrm{OPT}}}

\begin{document}
\begin{alignat*}{2}
\OPT & = \OPTL + \OPTR \\[-1ex]
\text{\footnotesize Definition of $\OPTL$ and $\OPTR$} \\[-1ex]
& & &\arrownext\quad \text{\footnotesize As $$x \le z$$} \\[-1ex]
\text{\footnotesize Definition of $\OPTR$} \\[-1ex]