| 1 |
\documentclass{article} |
| 2 |
\usepackage[a4paper, margin=1in]{geometry} |
| 3 |
|
| 4 |
\usepackage[dvipsnames]{xcolor} |
| 5 |
|
| 6 |
%%% standard math packages for equations: |
| 7 |
\usepackage{amsmath} |
| 8 |
\usepackage{amssymb} |
| 9 |
\usepackage{mathtools} |
| 10 |
|
| 11 |
\usepackage{hyperref} |
| 12 |
\usepackage{cleveref} |
| 13 |
|
| 14 |
\usepackage{annotate-equations} |
| 15 |
|
| 16 |
%\usepackage{showexpl} % LTXexample |
| 17 |
\usepackage[skins,listings]{tcolorbox} |
| 18 |
\newtcblisting{LTXexample}[1][]{% |
| 19 |
colframe=black!20, |
| 20 |
colback=black!10, |
| 21 |
coltitle=red!50!yellow!3!white, |
| 22 |
bicolor,colbacklower=white, |
| 23 |
fonttitle=\sffamily\bfseries, |
| 24 |
% listing options={escapeinside=\`\`}, |
| 25 |
%sidebyside, |
| 26 |
text above listing, |
| 27 |
#1} |
| 28 |
|
| 29 |
\title{\texttt{annotate-equations.sty}, v.0.2.2} |
| 30 |
\author{ST John} |
| 31 |
\date{\url{https://github.com/st--/annotate-equations}} |
| 32 |
|
| 33 |
|
| 34 |
\begin{document} |
| 35 |
|
| 36 |
\maketitle |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
%\section{Introduction} |
| 41 |
|
| 42 |
This package is there to make it easier to make annotated equations in \LaTeX, such as in this example: |
| 43 |
\begin{LTXexample}[] |
| 44 |
\vspace{4em} |
| 45 |
\renewcommand{\eqnhighlightheight}{\vphantom{\hat{H}}\mathstrut} |
| 46 |
\begin{equation*} |
| 47 |
i \tikzmarknode{hbar}{\mathstrut\hbar} \frac{\partial}{\partial t} \eqnmarkbox[blue]{Psi1}{\Psi(x, t)} = \eqnmark[red]{Hhat}{\hat{H}} \eqnmarkbox[blue]{Psi2}{\Psi(x, t)} |
| 48 |
\end{equation*} |
| 49 |
\annotate[yshift=3em]{above}{hbar}{$\hbar = \frac{h}{2\pi}$, reduced Planck constant} |
| 50 |
\annotate[yshift=1em]{above}{Hhat}{Hamilton operator} |
| 51 |
\annotatetwo[yshift=-1em]{below}{Psi1}{Psi2}{Wave function} |
| 52 |
\vspace{1em} |
| 53 |
\end{LTXexample} |
| 54 |
There is still a bit of manual tweaking required (such as adding vertical space before/after the equation), but hopefully this package will already make it a bit more inviting to annotate your equations! |
| 55 |
|
| 56 |
Note that this package relies on TikZ's \texttt{remember picture} option and therefore you have to compile your \LaTeX{} document at least twice to get everything in the right place (or just use \texttt{latexmk}!). |
| 57 |
|
| 58 |
|
| 59 |
\tableofcontents |
| 60 |
|
| 61 |
|
| 62 |
\section{Marking annotation targets within your equation} |
| 63 |
|
| 64 |
\newcommand{\cmdoption}[1]{$\langle$\textit{#1}$\rangle$} |
| 65 |
|
| 66 |
Use |
| 67 |
\verb|\eqnmarkbox[|\cmdoption{color}\verb|]{|\cmdoption{node name}\verb|}{|\cmdoption{equation term(s)}\verb|}| |
| 68 |
or |
| 69 |
\verb|\eqnmark[|\cmdoption{color}\verb|]{|\cmdoption{node name}\verb|}{| \cmdoption{equation term(s)}\verb|}| |
| 70 |
to define the target of an annotation within your equation. \verb|\eqnmarkbox| adds background shading, whereas \verb|\eqnmark| changes the text color. |
| 71 |
(You can also use |
| 72 |
\verb|\tikzmarknode{|\cmdoption{node name}\verb|}{|\cmdoption{equation term(s)}\verb|}|, |
| 73 |
but this is likely to end up with the arrow tip too close to the target, so you may want to also pass the \texttt{outer ysep} option, see \cref{sec:outerysep}.) |
| 74 |
% |
| 75 |
\begin{LTXexample}[text outside listing,lefthand width=1in] |
| 76 |
\begin{equation*} |
| 77 |
\eqnmarkbox[blue]{node1}{e_q^n} |
| 78 |
\eqnmark[red]{node2}{f(x)} |
| 79 |
\tikzmarknode{node3}{kT} |
| 80 |
\end{equation*} |
| 81 |
\end{LTXexample} |
| 82 |
\noindent |
| 83 |
|
| 84 |
|
| 85 |
\section{Simple annotations} |
| 86 |
\label{sec:annotate} |
| 87 |
|
| 88 |
Once you have defined nodes within your equations, you can annotate them using |
| 89 |
\verb|\annotate[|\cmdoption{tikz options}\verb|]{|\cmdoption{annotate keys}\verb|}{|\cmdoption{node name[,\dots]}\verb|}{|\cmdoption{annotation text}\verb|}|. |
| 90 |
% |
| 91 |
\cmdoption{tikz options} is passed through to the options for the TikZ node defining the annotation; its most important use is to set the \texttt{yshift}. |
| 92 |
For \cmdoption{annotate keys}, see \cref{sec:annotate-keys}. |
| 93 |
\cmdoption{node name} is the same name you used to mark the node within the equation, e.g.\ using \verb|\eqnmarkbox|. |
| 94 |
\cmdoption{annotation text} is the text of the annotation itself. |
| 95 |
% |
| 96 |
\begin{LTXexample}[text outside listing,lefthand width=1in] |
| 97 |
\begin{equation*} |
| 98 |
\eqnmarkbox[blue]{node1}{e_q^n} |
| 99 |
\eqnmark[red]{node2}{f(x)} |
| 100 |
\tikzmarknode{node3}{kT} |
| 101 |
\end{equation*} |
| 102 |
\annotate[yshift=1em]{}{node1,node2}{my annotation text} |
| 103 |
\end{LTXexample} |
| 104 |
\noindent |
| 105 |
% |
| 106 |
\label{sec:tikz-options} |
| 107 |
You generally need to manually adjust the \texttt{yshift} to move the annotations to an appropriate distance above (or negative values for below) the equation. If you want an annotation below the equation, with negative \texttt{yshift}, remember to also pass the \texttt{below} option (see \cref{sec:annotate-keys}). |
| 108 |
(You can also adjust \texttt{xshift} if needed, also positive or negative.) |
| 109 |
|
| 110 |
The annotation picks the same text color as given to \verb|\eqnmarkbox| or \verb|\eqnmark|, but you can also override it using \texttt{color} option. |
| 111 |
|
| 112 |
One annotation can point to multiple targets, and multiple annotations can point to the same target. |
| 113 |
|
| 114 |
\subsection{Annotation options} |
| 115 |
\label{sec:annotate-keys} |
| 116 |
|
| 117 |
\cmdoption{annotate keys} can be empty, or contain one or more of: |
| 118 |
\begin{itemize} |
| 119 |
\item \texttt{above} (default) or \texttt{below}, |
| 120 |
\item \texttt{right} (default) or \texttt{left}, |
| 121 |
\item \texttt{label above} (default) or \texttt{label below}. |
| 122 |
|
| 123 |
Note: currently only works for \verb|\annotatetwo| (\cref{sec:annotatetwo}). |
| 124 |
\end{itemize} |
| 125 |
% |
| 126 |
\begin{LTXexample}[text outside listing,lefthand width=1in] |
| 127 |
\begin{equation*} |
| 128 |
\eqnmarkbox[blue]{node1}{e_q^n} |
| 129 |
\eqnmark[red]{node2}{f(x)} |
| 130 |
\tikzmarknode{node3}{kT} |
| 131 |
\end{equation*} |
| 132 |
\annotate[yshift=1em]{left}{node1}{my} |
| 133 |
\annotate[yshift=-0.5em]{below,left}{node2}{annotation} |
| 134 |
\annotate[yshift=-1em]{below, label below}{node3}{text} |
| 135 |
\end{LTXexample} |
| 136 |
\noindent |
| 137 |
% |
| 138 |
|
| 139 |
|
| 140 |
\section{Double annotations} |
| 141 |
\label{sec:annotatetwo} |
| 142 |
|
| 143 |
\verb|\annotatetwo[|\cmdoption{tikz options}\verb|]{|\cmdoption{annotate keys}\verb|}{|\cmdoption{first node name}\verb|}{|\cmdoption{second node name}\verb|}{|\cmdoption{annotation text}\verb|}|. |
| 144 |
\cmdoption{tikz options} and \cmdoption{annotate keys} are as described above in \cref{sec:tikz-options,sec:annotate-keys}. Note that \cmdoption{annotate keys} \texttt{left}/\texttt{right} have no effect in \verb|\annotatetwo|. |
| 145 |
|
| 146 |
\begin{LTXexample}[text outside listing,lefthand width=1in] |
| 147 |
\begin{equation*} |
| 148 |
\eqnmarkbox[red]{a1}{a} \eqnmarkbox[blue]{b1}{b} = \eqnmarkbox[green]{b2}{b} \eqnmarkbox{a2}{a} |
| 149 |
\end{equation*} |
| 150 |
\annotatetwo[yshift=1.5em]{above, label below}{a1}{a2}{var 1} |
| 151 |
\annotatetwo[yshift=0.5em]{above}{b1}{b2}{var 2} |
| 152 |
\annotatetwo[yshift=-0.5em]{below}{b2}{b1}{var 2} |
| 153 |
\end{LTXexample} |
| 154 |
\noindent |
| 155 |
% |
| 156 |
Color is picked from the first of the two nodes. |
| 157 |
|
| 158 |
|
| 159 |
\section{Package options} |
| 160 |
|
| 161 |
\subsection{Size of highlight: shrink to content or always full height} |
| 162 |
|
| 163 |
\verb|\eqnhighlightheight| is inserted into every \verb|\eqnhighlight|, \verb|\eqncolor|, \verb|\eqnmark|, and \verb|\eqnmarkbox| and by redefining it you can specify the minimum height for the corresponding box: |
| 164 |
% |
| 165 |
\begin{LTXexample}[text outside listing,lefthand width=0.5in] |
| 166 |
\renewcommand{\eqnhighlightheight}{} % package default |
| 167 |
|
| 168 |
\begin{equation*} |
| 169 |
\eqnmarkbox[red]{hbar}{\hbar} \eqnmarkbox[blue]{q}{q} |
| 170 |
\end{equation*} |
| 171 |
\end{LTXexample} |
| 172 |
\noindent |
| 173 |
% |
| 174 |
\begin{LTXexample}[text outside listing,lefthand width=0.5in] |
| 175 |
\renewcommand{\eqnhighlightheight}{\mathstrut} % 0-width "constant" height |
| 176 |
|
| 177 |
\begin{equation*} |
| 178 |
\eqnmarkbox[red]{hbar}{\hbar} \eqnmarkbox[blue]{q}{q} |
| 179 |
\end{equation*} |
| 180 |
\end{LTXexample} |
| 181 |
\noindent |
| 182 |
% |
| 183 |
\verb|\eqnhighlightheight| is used in math mode. |
| 184 |
|
| 185 |
|
| 186 |
Note that in some cases \verb|\mathstrut| might not be enough, as in the introductory example: |
| 187 |
% |
| 188 |
\begin{LTXexample}[text outside listing,lefthand width=0.5in] |
| 189 |
\renewcommand{\eqnhighlightheight}{\mathstrut} % 0-width "constant" height |
| 190 |
|
| 191 |
\begin{equation*} |
| 192 |
\eqnmarkbox[red]{Hhat}{\hat{H}} \eqnmarkbox[blue]{Psi}{\Psi} |
| 193 |
\end{equation*} |
| 194 |
\end{LTXexample} |
| 195 |
\noindent |
| 196 |
% |
| 197 |
You can create custom 0-width characters using \verb|\vphantom|: |
| 198 |
% |
| 199 |
\begin{LTXexample}[text outside listing,lefthand width=0.5in] |
| 200 |
\renewcommand{\eqnhighlightheight}{\vphantom{\hat{H}}\mathstrut} % custom 0-width height |
| 201 |
|
| 202 |
\begin{equation*} |
| 203 |
\eqnmarkbox[red]{Hhat}{\hat{H}} \eqnmarkbox[blue]{Psi}{\Psi} |
| 204 |
\end{equation*} |
| 205 |
\end{LTXexample} |
| 206 |
\noindent |
| 207 |
% |
| 208 |
(It looks more balanced if you still include the \verb|\mathstrut|.) |
| 209 |
|
| 210 |
\subsection{Amount of shading of mark highlight} |
| 211 |
|
| 212 |
\verb|\eqnhighlightshade| defines the percentage of the specified color to take: |
| 213 |
% |
| 214 |
\begin{LTXexample}[text outside listing,lefthand width=0.5in] |
| 215 |
\renewcommand{\eqnhighlightshade}{17} % package default |
| 216 |
|
| 217 |
\begin{equation*} |
| 218 |
\eqnmarkbox[red]{hbar}{\hbar} \eqnmarkbox[blue]{q}{q} |
| 219 |
\end{equation*} |
| 220 |
\end{LTXexample} |
| 221 |
\noindent |
| 222 |
% |
| 223 |
By redefining this command, you can change the ``alpha'' value of the highlight: |
| 224 |
% |
| 225 |
\begin{LTXexample}[text outside listing,lefthand width=0.5in] |
| 226 |
\renewcommand{\eqnhighlightshade}{47} % 0 is white, 100 is solid color |
| 227 |
|
| 228 |
\begin{equation*} |
| 229 |
\eqnmarkbox[red]{hbar}{\hbar} \eqnmarkbox[blue]{q}{q} |
| 230 |
\end{equation*} |
| 231 |
\end{LTXexample} |
| 232 |
\noindent |
| 233 |
|
| 234 |
\subsection{Default formatting of annotation labels} |
| 235 |
\label{sec:eqnannotationfont} |
| 236 |
|
| 237 |
\verb|\eqnannotationfont| sets the \texttt{font} field of the TikZ annotation label and can be re-set to change its formatting: |
| 238 |
\begin{LTXexample}[text outside listing,lefthand width=0.5in] |
| 239 |
\renewcommand{\eqnannotationfont}{\sffamily\footnotesize} % package default |
| 240 |
|
| 241 |
\begin{equation*} |
| 242 |
\eqnmarkbox[blue]{v}{v} |
| 243 |
\end{equation*} |
| 244 |
\annotate[yshift=-0.5em]{below}{v}{velocity} |
| 245 |
\vspace{1em} |
| 246 |
\end{LTXexample} |
| 247 |
\noindent |
| 248 |
% |
| 249 |
\begin{LTXexample}[text outside listing,lefthand width=0.5in] |
| 250 |
\renewcommand{\eqnannotationfont}{\bfseries\small} |
| 251 |
|
| 252 |
\begin{equation*} |
| 253 |
\eqnmarkbox[blue]{v}{v} |
| 254 |
\end{equation*} |
| 255 |
\annotate[yshift=-0.5em]{below}{v}{velocity} |
| 256 |
\vspace{1em} |
| 257 |
\end{LTXexample} |
| 258 |
\noindent |
| 259 |
% |
| 260 |
Alternatively, you can also change the style of \verb|annotate equations/text|: |
| 261 |
\begin{LTXexample}[text outside listing,lefthand width=0.5in] |
| 262 |
\tikzset{annotate equations/text/.style={font=\bfseries\small}} |
| 263 |
|
| 264 |
\begin{equation*} |
| 265 |
\eqnmarkbox[blue]{v}{v} |
| 266 |
\end{equation*} |
| 267 |
\annotate[yshift=-0.5em]{below}{v}{velocity} |
| 268 |
\vspace{1em} |
| 269 |
\end{LTXexample} |
| 270 |
\noindent |
| 271 |
|
| 272 |
\verb|\eqnannotationstrut| is defined to be a strut (zero-width height) to |
| 273 |
provide minimum distance between the text and the corresponding arrow line. By |
| 274 |
default it is \verb|\strut|, which has a similar effect to |
| 275 |
\verb|\mathstrut| in \verb|\eqnhighlightheight|. |
| 276 |
|
| 277 |
\begin{LTXexample}[text outside listing,lefthand width=0.5in] |
| 278 |
\renewcommand{\eqnannotationstrut}{\strut} % package default |
| 279 |
|
| 280 |
\begin{equation*} |
| 281 |
\eqnmarkbox[blue]{size}{s} |
| 282 |
\end{equation*} |
| 283 |
\annotate[yshift=-0.5em]{below}{size}{The size} |
| 284 |
\vspace{1em} |
| 285 |
\end{LTXexample} |
| 286 |
\noindent |
| 287 |
% |
| 288 |
\begin{LTXexample}[text outside listing,lefthand width=0.5in] |
| 289 |
\renewcommand{\eqnannotationstrut}{} |
| 290 |
|
| 291 |
\begin{equation*} |
| 292 |
\eqnmarkbox[blue]{size}{s} |
| 293 |
\end{equation*} |
| 294 |
\annotate[yshift=-0.5em]{below}{size}{The size} |
| 295 |
\vspace{1em} |
| 296 |
\end{LTXexample} |
| 297 |
|
| 298 |
|
| 299 |
\subsection{Customize style} |
| 300 |
|
| 301 |
You can change the style of the annotation arrow line by setting the style of \verb|annotate equations/arrow|: |
| 302 |
\begin{LTXexample}[text outside listing,lefthand width=0.5in] |
| 303 |
\tikzset{annotate equations/arrow/.style={color=ForestGreen, >=latex', very thick, dashed}} |
| 304 |
|
| 305 |
\begin{equation*} |
| 306 |
\eqnmarkbox[blue]{size}{s} = \eqnmarkbox[red]{other}{x} |
| 307 |
\end{equation*} |
| 308 |
\annotate[yshift=-0.5em]{below}{size}{The size} |
| 309 |
\annotatetwo[yshift=1em]{above}{size}{other}{the same} |
| 310 |
\end{LTXexample} |
| 311 |
\noindent |
| 312 |
Note that it applies to all \verb|\annotate| and \verb|\annotatetwo| arrows within the scope. |
| 313 |
|
| 314 |
You can also use this to change the arrow direction: |
| 315 |
\begin{LTXexample}[text outside listing,lefthand width=0.5in] |
| 316 |
\begin{equation*} |
| 317 |
\eqnmarkbox[blue]{size}{s} = \eqnmarkbox[red]{other}{x} |
| 318 |
\end{equation*} |
| 319 |
\tikzset{annotate equations/arrow/.style={->}} |
| 320 |
\annotatetwo[yshift=1em]{above}{size}{other}{one and} |
| 321 |
\tikzset{annotate equations/arrow/.style={<-}} |
| 322 |
\annotatetwo[yshift=-1em]{below, label below}{size}{other}{the same} % note that the "direction" of the arrow is from first to second mark |
| 323 |
\end{LTXexample} |
| 324 |
|
| 325 |
\section{Recommendations, tips \& tricks} |
| 326 |
|
| 327 |
\subsection{Use \texttt{\textbackslash{}colorlet} for consistent, easily changeable colors} |
| 328 |
|
| 329 |
|
| 330 |
\subsection{Relations such as ``$=$''} |
| 331 |
\label{sec:mathrel} |
| 332 |
|
| 333 |
Wrapping a mathematical relation symbol such as {\color{blue}$=$} in, for example, \texttt{\textbackslash{}tikzmarknode}, breaks how \TeX{} determines spacing in equations: |
| 334 |
\begin{LTXexample}[text outside listing,lefthand width=0.5in] |
| 335 |
\[ |
| 336 |
a \tikzmarknode{node1}{=} b |
| 337 |
\] |
| 338 |
\annotate[yshift=-1em]{below}{node1}{equality} |
| 339 |
\end{LTXexample} |
| 340 |
\noindent |
| 341 |
This can be fixed by wrapping the \texttt{\textbackslash{}tikzmarknode} in \texttt{\textbackslash{}mathrel}: |
| 342 |
\begin{LTXexample}[text outside listing,lefthand width=0.5in] |
| 343 |
\[ |
| 344 |
a \mathrel{\tikzmarknode{node1}{=}} b |
| 345 |
\] |
| 346 |
\annotate[yshift=-1em]{below}{node1}{equality} |
| 347 |
\end{LTXexample} |
| 348 |
|
| 349 |
\subsection{Extra spacing between \texttt{\textbackslash{}tikzmarknode} and arrow} |
| 350 |
\label{sec:outerysep} |
| 351 |
|
| 352 |
If you want more space between arrow tip and annotated term, you can pass the \texttt{outer ysep} option to \texttt{\textbackslash{}tikzmarknode}: |
| 353 |
\begin{LTXexample}[text outside listing,lefthand width=0.5in] |
| 354 |
\[ |
| 355 |
a \mathrel{\tikzmarknode[outer ysep=5pt]{node1}{=}} b |
| 356 |
\] |
| 357 |
\annotate[yshift=-1em]{below}{node1}{equality} |
| 358 |
\end{LTXexample} |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
\section{Known issues} |
| 363 |
|
| 364 |
\begin{itemize} |
| 365 |
\item Annotations of mathematical relations require some manual patching to get the correct surrounding spacing (see \cref{sec:mathrel}). |
| 366 |
|
| 367 |
\end{itemize} |
| 368 |
|
| 369 |
|
| 370 |
\section{Backwards-incompatible changes} |
| 371 |
|
| 372 |
\subsection*{v0.2.0} |
| 373 |
|
| 374 |
\subsubsection*{\texttt{\textbackslash{}eqnannotationtext} removed} |
| 375 |
|
| 376 |
To make it easier to format multiline annotations, version 0.2.0 introduced the \verb|\eqnannotationfont| and \verb|\eqnannotationstrut| (zero-argument) commands (see \cref{sec:eqnannotationfont}). |
| 377 |
|
| 378 |
In exchange, the \verb|\eqnannotationtext| (one-argument) command was removed. To upgrade, replace for example |
| 379 |
\begin{tcblisting}{listing only} |
| 380 |
\renewcommand{\eqnannotationtext}[1]{\sffamily\tiny#1\strut} |
| 381 |
\end{tcblisting} |
| 382 |
with |
| 383 |
\begin{tcblisting}{listing only} |
| 384 |
\renewcommand{\eqnannotationfont}{\sffamily\tiny} |
| 385 |
\renewcommand{\eqnannotationstrut}{\strut} |
| 386 |
\end{tcblisting} |
| 387 |
|
| 388 |
\end{document} |