Add Annotations and Remarks next to Equations
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*}
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]
& &\quad &\dlsh\quad\text{\footnotesize Definition \rlap{of OPTL and 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]
& & &\arrownext\quad
\text{\footnotesize Definition of $\OPTL$ and $\OPTR$} \\[-1ex]
& = (x+y) + (y+z) \\[-1ex] %
& & &\arrownext\quad \text{\footnotesize As \(x \le z \)} \\[-1ex]
& \leq 2* (y+z) \\[-1ex]
& & & \arrownext\quad
\text{\footnotesize Definition of $\OPTR$} \\[-1ex]
& = \OPTR + \OPTR
\end{alignat*}
\end{document}