summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/annotate-equations
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2022-03-30 03:00:41 +0000
committerNorbert Preining <norbert@preining.info>2022-03-30 03:00:41 +0000
commit48cfcb505ab1aa2632eaf1985d2fee72691e21d0 (patch)
tree217ec64397e06d47cf05f029c98f76b436829955 /macros/latex/contrib/annotate-equations
parentfed9dbe9efe10955aefb7687a15de45404cc76f4 (diff)
CTAN sync 202203300300
Diffstat (limited to 'macros/latex/contrib/annotate-equations')
-rw-r--r--macros/latex/contrib/annotate-equations/LICENSE21
-rw-r--r--macros/latex/contrib/annotate-equations/README.md73
-rw-r--r--macros/latex/contrib/annotate-equations/annotate-equations.pdfbin0 -> 124665 bytes
-rw-r--r--macros/latex/contrib/annotate-equations/annotate-equations.sty188
-rw-r--r--macros/latex/contrib/annotate-equations/annotate-equations.tex282
5 files changed, 564 insertions, 0 deletions
diff --git a/macros/latex/contrib/annotate-equations/LICENSE b/macros/latex/contrib/annotate-equations/LICENSE
new file mode 100644
index 0000000000..8a43681753
--- /dev/null
+++ b/macros/latex/contrib/annotate-equations/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2022 ST John, https://github.com/st--/
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/macros/latex/contrib/annotate-equations/README.md b/macros/latex/contrib/annotate-equations/README.md
new file mode 100644
index 0000000000..ca25cd8b0b
--- /dev/null
+++ b/macros/latex/contrib/annotate-equations/README.md
@@ -0,0 +1,73 @@
+# Annotate equations in LaTeX using TikZ
+
+This package provides commands that make it easy to highlight terms in equations & add annotation labels (based on TikZ).
+Should work with pdflatex as well as lualatex.
+
+Inspired by Sibin Mohan's https://github.com/synercys/annotated_latex_equations/
+
+Please report any bugs, issues, contribute changes & improvements on https://github.com/st--/annotate-equations/ :)
+
+Package author: ST John, http://www.infinitecuriosity.org/
+
+License: [MIT](LICENSE)
+
+[Documentation](annotate-equations.pdf)
+
+## A package with reusable commands
+
+![rendering of annotated equation](examples/example_annotation_package.png)
+
+Using [`annotate-equations.sty`](https://github.com/st--/annotate-equations/blob/main/annotate-equations.sty), an equation can easily be annotated as follows:
+```latex
+\begin{equation*}
+ \mathcal{O}\big(
+ (
+ \eqnmarkbox[NavyBlue]{p1}{p}
+ \eqnmarkbox[OliveGreen]{k1}{\kappa}^3 % note that we have the ^3 outside the \eqnmark/\tikzmarknode arguments
+ )
+ \eqnmarkbox[WildStrawberry]{T1}{T}
+ +
+ (
+ \eqnmarkbox[NavyBlue]{p2}{p} % tikz nodes need distinct names!
+ \eqnmark[OliveGreen]{k2}{\kappa}
+ )
+ (
+ \eqnmarkbox[WildStrawberry]{T2}{T}^2
+ \tikzmarknode{Is}{|\mathcal{I}^*|} % manual \tikzmarknode works, too
+ \eqnmarkbox[Plum]{Nb}{N_b}
+ \eqnmark[RoyalPurple]{M}{M}
+ )
+ \big)
+\end{equation*}
+\annotatetwo[yshift=1em]{above}{p1}{p2}{\# of nodes}
+\annotatetwo[yshift=-1em,xshift=0.2ex]{below}{T1}{T2}{\# of graphs in $\hat{\mathcal{G}}_T$}
+\annotatetwo[yshift=-2em]{below}{k1}{k2}{max.\ indegree in $\hat{\mathcal{G}}_T$}
+\annotate[yshift=3em]{above,left}{Is}{size of set of allowed interventions}
+\annotate[yshift=1em]{above}{Nb}{\# of samples per batch}
+\annotate[yshift=-1em]{below}{M}{\# of samples for $\mathbb{E}_y$}
+```
+
+More details are in the [user manual](annotate-equations.pdf).
+Should work with both pdflatex and lualatex.
+
+## How to do it from scratch: annotated examples
+
+![rendering of annotated equation](examples/example_annotation.png)
+
+Inspired by Sibin Mohan's https://github.com/synercys/annotated_latex_equations/, but with significantly simplified TikZ code, and with lots of comments to explain what is going on.
+
+Two versions, one [as Beamer slides with transitions](https://github.com/st--/annotate-equations/blob/main/examples/demo_manual_annotate_beamer.tex), one [as an article](https://github.com/st--/annotate-equations/blob/main/examples/demo_manual_annotate_article.tex). For further examples, see https://github.com/synercys/annotated_latex_equations/.
+
+### Giving all highlight boxes the same height
+
+Simply add a `\mathstrut` within the colorbox:
+```diff
+-\newcommand{\highlight}[2]{\colorbox{#1!17}{$#2$}}
++\newcommand{\highlight}[2]{\colorbox{#1!17}{$\mathstrut #2$}}
+```
+
+![rendering of annotated equation with equal-height highlights](examples/example_annotation_equal_height.png)
+
+## Much more information...
+
+...in the answers to [this TeX StackExchange question](https://tex.stackexchange.com/q/254844/171664).
diff --git a/macros/latex/contrib/annotate-equations/annotate-equations.pdf b/macros/latex/contrib/annotate-equations/annotate-equations.pdf
new file mode 100644
index 0000000000..984daaf8ad
--- /dev/null
+++ b/macros/latex/contrib/annotate-equations/annotate-equations.pdf
Binary files differ
diff --git a/macros/latex/contrib/annotate-equations/annotate-equations.sty b/macros/latex/contrib/annotate-equations/annotate-equations.sty
new file mode 100644
index 0000000000..a5dbf002f3
--- /dev/null
+++ b/macros/latex/contrib/annotate-equations/annotate-equations.sty
@@ -0,0 +1,188 @@
+% Annotate LaTeX Equations
+%
+% (c) 2022 by ST John, https://github.com/st--/
+% Licensed under MIT License
+%
+\NeedsTeXFormat{LaTeX2e}[1994/06/01]
+\ProvidesPackage{annotate-equations}
+ [2022/03/29 v0.1.0 easily annotate equations using TikZ]
+
+%%% lualatex compatibility, from https://tex.stackexchange.com/a/351520/171664
+\RequirePackage{ifluatex}
+\ifluatex
+\RequirePackage{luatex85}
+\RequirePackage{pdftexcmds}
+ \makeatletter
+ \let\pdfstrcmp\pdf@strcmp
+ \let\pdffilemoddate\pdf@filemoddate
+ \makeatother
+\fi
+%%%
+
+\RequirePackage{tikz}
+\RequirePackage{xcolor}
+
+\usetikzlibrary{backgrounds}
+\usetikzlibrary{arrows,shapes}
+\usetikzlibrary{tikzmark} % for \tikzmarknode
+\usetikzlibrary{calc} % for computing the midpoint between two nodes, e.g. at ($(p1.north)!0.5!(p2.north)$)
+
+
+%%%%% SETTINGS %%%%%
+
+\newcommand{\eqnhighlightheight}{} % colorbox will shrink to content
+\renewcommand{\eqnhighlightheight}{\mathstrut} % colorbox will always have full height
+
+\newcommand{\eqnhighlightshade}{17} % light
+%\renewcommand{\eqnhighlightshade}{47} % dark
+
+\newcommand{\eqnannotationtext}[1]{\sffamily\footnotesize#1\strut} %%% TODO remove textsf/footnotesize/strut?
+
+
+\providecommand\EAmarkanchor{north} % default set to "above"
+\providecommand\EAwesteast{east} % default set to "right"
+\providecommand\EAlabelanchor{south} % default set to "label above"
+% for pgfkeys, see https://tex.stackexchange.com/a/34318/171664
+% for no-value keys, see https://tex.stackexchange.com/a/401848/171664
+\pgfkeys{
+ /eqnannotate/.is family, /eqnannotate,
+ above/.code = {\renewcommand\EAmarkanchor{north}},
+ below/.code = {\renewcommand\EAmarkanchor{south}},
+ left/.code = {\renewcommand\EAwesteast{west}},
+ right/.code = {\renewcommand\EAwesteast{east}},
+ label above/.code = {\renewcommand\EAlabelanchor{south}},
+ label below/.code = {\renewcommand\EAlabelanchor{north}},
+}
+
+%%%%% %%%%%%%% %%%%%
+
+
+\newcommand*{\eqnhighlightcolorbox}[2]{%
+% \colorbox sets the second argument in text mode, so for use within equations we wrap it in $ $ again
+ \mathchoice% to get right font size in each mode:
+ {\colorbox{#1}{$\displaystyle #2$}}%
+ {\colorbox{#1}{$\textstyle #2$}}%
+ {\colorbox{#1}{$\scriptstyle #2$}}%
+ {\colorbox{#1}{$\scriptscriptstyle #2$}}%
+}
+
+%%% the fbox with 0pt rule fixes the height of eqnmark vs eqnmarkbox issue
+\newcommand*{\eqnhighlightfbox}[2]{%
+% \fbox sets the second argument in text mode, so for use within equations we wrap it in $ $ again
+ \mathchoice% to get right font size in each mode:
+ {\begingroup\setlength{\fboxrule}{0pt}\fbox{$\displaystyle\color{#1}#2$}\endgroup}%
+ {\begingroup\setlength{\fboxrule}{0pt}\fbox{$\textstyle\color{#1}#2$}\endgroup}%
+ {\begingroup\setlength{\fboxrule}{0pt}\fbox{$\scriptstyle\color{#1}#2$}\endgroup}%
+ {\begingroup\setlength{\fboxrule}{0pt}\fbox{$\scriptscriptstyle\color{#1}#2$}\endgroup}%
+}
+
+% . is the current color
+
+\newcommand*{\eqnhighlight}[2]{\begingroup\colorlet{currentcolor}{.}\eqnhighlightcolorbox{#1!\eqnhighlightshade}{\eqnhighlightheight #2}\endgroup}
+\newcommand*{\eqncolor}[2]{\begingroup\colorlet{currentcolor}{.}\eqnhighlightfbox{#1}{\eqnhighlightheight #2}\endgroup}
+
+%%% Arguments to \eqnmark[box]: [highlight color]{node name}{term to highlight}
+\newcommand*{\eqnmarkbox}[3][currentcolor]{\addvalue{#2}{#1}\tikzmarknode{#2}{\eqnhighlight{#1}{#3}}}
+\newcommand*{\eqnmark}[3][currentcolor]{\addvalue{#2}{#1}\tikzmarknode{#2}{\eqncolor{#1}{#3}}}
+
+% Store current color in a dictionary (lookup table),
+% from https://tex.stackexchange.com/a/48931/171664 :
+\def\addvalue#1#2{\expandafter\gdef\csname eqnannotate@data@#1\endcsname{#2}}
+\def\usevalue#1{%
+ \ifcsname eqnannotate@data@#1\endcsname
+ \csname eqnannotate@data@#1\expandafter\endcsname
+ \else
+ currentcolor%
+ \fi
+}
+
+
+%%%%% Helpers for swapping north/south / west/east / -/+ depending on above/below / left/right etc.:
+\newcommand*{\swapNorthSouth}[1]{%
+ \ifnum\pdfstrcmp{#1}{south}=0 north\else south\fi
+}
+\newcommand*{\swapWestEast}[1]{%
+ \ifnum\pdfstrcmp{#1}{east}=0 west\else east\fi
+}
+\newcommand*{\EAxshift}[1]{%
+ \ifnum\pdfstrcmp{#1}{east}=0 -0.3ex\else 0.3ex\fi
+}
+%%%%%
+
+
+\newcounter{eqnannotatenode}
+\newcommand*{\eqnannotateCurrentNode}{eqnannotatenode\theeqnannotatenode}
+
+
+\newcommand{\annotatetwo}[5][]{%
+ \begingroup% %%% so we don't leak the \def's below
+ \stepcounter{eqnannotatenode}%
+ %%% #1: (optional) extra args for \node e.g. yshift=...
+ \pgfkeys{/eqnannotate, #2}% %%% all configuration options
+ \def\myEAmarkOne{#3}%
+ \def\myEAmarkTwo{#4}%
+ \colorlet{currentcolor}{.}
+ \def\myEAtext{#5}%
+ \def\myEAcolor{\usevalue{\myEAmarkOne}}%
+ \begin{tikzpicture}[overlay,remember picture,>=stealth,nodes={align=left,inner ysep=1pt},<-]
+ % default anchor is at center
+ \node[anchor=\swapNorthSouth{\EAmarkanchor},color=\myEAcolor!85,#1] % color blended with white to 85%, any (optional) extra args #1
+ (\eqnannotateCurrentNode) % use counter-based "local node"
+ at ($(\myEAmarkOne.\EAmarkanchor)!0.5!(\myEAmarkTwo.\EAmarkanchor)$) % centered between the two nodes
+ {\eqnannotationtext{\myEAtext}};
+ % double arrow to two uses within the equation:
+ \draw [<->,color=\myEAcolor] (\myEAmarkOne.\EAmarkanchor) |- ([yshift=0.1ex] \eqnannotateCurrentNode.\EAlabelanchor) -| (\myEAmarkTwo.\EAmarkanchor); % from node 1 via annotation to node 2, with anchor #6 each
+ \end{tikzpicture}%
+ \endgroup% %%% close group again
+}
+
+
+%%% \extractfirst from https://tex.stackexchange.com/a/115733/171664
+\RequirePackage{expl3}
+\RequirePackage{xparse}
+\ExplSyntaxOn
+\NewDocumentCommand{\extractfirst}{mm}
+ {
+ \tl_set:Nx #1 {\clist_item:Nn #2 { 1 } }
+ }
+\ExplSyntaxOff
+%%%
+
+\newcommand{\annotate}[4][]{%
+ \begingroup% %%% so we don't leak the \def's below
+ \stepcounter{eqnannotatenode}%
+ %
+ %
+ %
+ % #1: (optional) extra args for \node e.g. yshift=...
+ \pgfkeys{/eqnannotate, #2}
+ \def\myEAmarks{#3}%
+ \extractfirst\myEAmark\myEAmarks% %%% get first node for color and annotation
+ \def\myEAtext{#4}%
+ %
+ %
+ \colorlet{currentcolor}{.}
+ \def\myEAcolor{\usevalue{\myEAmark}}%
+ %
+ %
+ \def\myEAxshift{\EAxshift{\EAwesteast}}%
+ \begin{tikzpicture}[overlay,remember picture,>=stealth,nodes={align=left,inner ysep=1pt},<-]
+ \node[anchor=\swapNorthSouth{\EAmarkanchor} \swapWestEast{\EAwesteast},color=\myEAcolor!85,#1] % TODO for some reason, passing #1 through command doesn't work...
+ % anchor=west: align left edge of text on top of tikzmark in equation
+ % should be north west for below and south west for above ...
+ (\eqnannotateCurrentNode) at (\myEAmark.\EAmarkanchor) % \EAmarkanchor north: above the equation, south: below
+ {\eqnannotationtext{\myEAtext}};
+ \foreach \EAmark in \myEAmarks
+ \draw [color=\myEAcolor] (\EAmark.\EAmarkanchor) % arrow from the equation
+ % \EAmarkanchor north: above the equation, south: below
+ |- ([xshift=\myEAxshift,yshift=0.1ex] \eqnannotateCurrentNode.south \EAwesteast);
+ % - south east: we want line to end at bottom right of annotation text;
+ % - negative xshift makes it a little bit shorter;
+ % - yshift for aesthetics (\strut is ever so slightly too tall).
+ \end{tikzpicture}%
+ \endgroup% %%% close group again
+}
+
+\endinput
+%%
+%% End of file
diff --git a/macros/latex/contrib/annotate-equations/annotate-equations.tex b/macros/latex/contrib/annotate-equations/annotate-equations.tex
new file mode 100644
index 0000000000..2b492a36e4
--- /dev/null
+++ b/macros/latex/contrib/annotate-equations/annotate-equations.tex
@@ -0,0 +1,282 @@
+\documentclass{article}
+\usepackage[a4paper, margin=1in]{geometry}
+
+\usepackage[dvipsnames]{xcolor}
+
+%%% standard math packages for equations:
+\usepackage{amsmath}
+\usepackage{amssymb}
+\usepackage{mathtools}
+
+\usepackage{hyperref}
+\usepackage{cleveref}
+
+\usepackage{annotate-equations}
+
+%\usepackage{showexpl} % LTXexample
+\usepackage[skins,listings]{tcolorbox}
+\newtcblisting{LTXexample}[1][]{%
+ colframe=black!20,
+ colback=black!10,
+ coltitle=red!50!yellow!3!white,
+ bicolor,colbacklower=white,
+ fonttitle=\sffamily\bfseries,
+% listing options={escapeinside=\`\`},
+ %sidebyside,
+ text above listing,
+ #1}
+
+\title{\texttt{annotate-equations.sty}}
+\author{ST John}
+\date{\url{https://github.com/st--/annotate-equations}}
+
+\begin{document}
+
+\maketitle
+
+\section{Introduction}
+
+This package is there to make it easier to make annotated equations in \LaTeX, such as in this example:
+\begin{LTXexample}[]
+\vspace{4em}
+\renewcommand{\eqnhighlightheight}{\vphantom{\hat{H}}\mathstrut}
+\begin{equation*}
+ 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)}
+\end{equation*}
+\annotate[yshift=3em]{above}{hbar}{$\hbar = \frac{h}{2\pi}$, reduced Planck constant}
+\annotate[yshift=1em]{above}{Hhat}{Hamilton operator}
+\annotatetwo[yshift=-1em]{below}{Psi1}{Psi2}{Wave function}
+\vspace{1em}
+\end{LTXexample}
+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!
+
+\section{Marking annotation targets within your equation}
+
+\newcommand{\cmdoption}[1]{$\langle$\textit{#1}$\rangle$}
+
+Use
+\verb|\eqnmarkbox[|\cmdoption{color}\verb|]{|\cmdoption{node name}\verb|}{|\cmdoption{equation term(s)}\verb|}|
+or
+\verb|\eqnmark[|\cmdoption{color}\verb|]{|\cmdoption{node name}\verb|}{| \cmdoption{equation term(s)}\verb|}|
+to define the target of an annotation within your equation. \verb|\eqnmarkbox| adds background shading, whereas \verb|\eqnmark| changes the text color.
+(You can also use
+\verb|\tikzmarknode{|\cmdoption{node name}\verb|}{|\cmdoption{equation term(s)}\verb|}|,
+but this is likely to end up with the arrow tip too close to the target.)
+%
+\begin{LTXexample}[text outside listing,lefthand width=1in]
+\begin{equation*}
+ \eqnmarkbox[blue]{node1}{e_q^n}
+ \eqnmark[red]{node2}{f(x)}
+ \tikzmarknode{node3}{kT}
+\end{equation*}
+\end{LTXexample}
+\noindent
+
+\section{Simple annotations}
+\label{sec:annotate}
+
+Once you have defined nodes within your equations, you can annotate them using
+\verb|\annotate[|\cmdoption{tikz options}\verb|]{|\cmdoption{annotate keys}\verb|}{|\cmdoption{node name[,\dots]}\verb|}{|\cmdoption{annotation text}\verb|}|.
+%
+\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}.
+For \cmdoption{annotate keys}, see \cref{sec:annotate-keys}.
+\cmdoption{node name} is the same name you used to mark the node within the equation, e.g.\ using \verb|\eqnmarkbox|.
+\cmdoption{annotation text} is the text of the annotation itself.
+%
+\begin{LTXexample}[text outside listing,lefthand width=1in]
+\begin{equation*}
+ \eqnmarkbox[blue]{node1}{e_q^n}
+ \eqnmark[red]{node2}{f(x)}
+ \tikzmarknode{node3}{kT}
+\end{equation*}
+\annotate[yshift=1em]{}{node1,node2}{my annotation text}
+\end{LTXexample}
+\noindent
+%
+\label{sec:tikz-options}
+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.
+(You can also adjust \texttt{xshift} if needed, also positive or negative.)
+
+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.
+
+One annotation can point to multiple targets, and multiple annotations can point to the same target.
+
+\subsection{Annotation options}
+\label{sec:annotate-keys}
+
+\cmdoption{annotate keys} can be empty, or contain one or more of:
+\begin{itemize}
+ \item \texttt{above} (default) or \texttt{below},
+ \item \texttt{right} (default) or \texttt{left},
+ \item \texttt{label above} (default) or \texttt{label below}.
+
+ Note: currently only works for \verb|\annotatetwo| (\cref{sec:annotatetwo}).
+\end{itemize}
+%
+\begin{LTXexample}[text outside listing,lefthand width=1in]
+\begin{equation*}
+ \eqnmarkbox[blue]{node1}{e_q^n}
+ \eqnmark[red]{node2}{f(x)}
+ \tikzmarknode{node3}{kT}
+\end{equation*}
+\annotate[yshift=1em]{left}{node1}{my}
+\annotate[yshift=-0.5em]{below,left}{node2}{annotation}
+\annotate[yshift=-1em]{below}{node3}{text}
+\end{LTXexample}
+\noindent
+%
+
+\section{Double annotations}
+\label{sec:annotatetwo}
+
+\verb|\annotatetwo[|\cmdoption{tikz options}\verb|]{|\cmdoption{annotate keys}\verb|}{|\cmdoption{first node name}\verb|}{|\cmdoption{second node name}\verb|}{|\cmdoption{annotation text}\verb|}|.
+\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|.
+
+\begin{LTXexample}[text outside listing,lefthand width=1in]
+\begin{equation*}
+ \eqnmarkbox[red]{a1}{a} \eqnmarkbox[blue]{b1}{b} = \eqnmarkbox[green]{b2}{b} \eqnmarkbox{a2}{a}
+\end{equation*}
+\annotatetwo[yshift=1.5em]{above, label below}{a1}{a2}{var 1}
+\annotatetwo[yshift=0.5em]{above}{b1}{b2}{var 2}
+\annotatetwo[yshift=-0.5em]{below}{b2}{b1}{var 2}
+\end{LTXexample}
+\noindent
+%
+Color is picked from the first of the two nodes.
+
+\section{Package options}
+
+\subsection{Size of highlight: shrink to content or always full height}
+
+\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:
+%
+\begin{LTXexample}[text outside listing,lefthand width=0.5in]
+\renewcommand{\eqnhighlightheight}{} % package default
+\begin{equation*}
+ \eqnmarkbox[red]{hbar}{\hbar} \eqnmarkbox[blue]{q}{q}
+\end{equation*}
+\end{LTXexample}
+\noindent
+%
+\begin{LTXexample}[text outside listing,lefthand width=0.5in]
+\renewcommand{\eqnhighlightheight}{\mathstrut} % 0-width "constant" height
+\begin{equation*}
+ \eqnmarkbox[red]{hbar}{\hbar} \eqnmarkbox[blue]{q}{q}
+\end{equation*}
+\end{LTXexample}
+\noindent
+%
+\verb|\eqnhighlightheight| is used in math mode.
+
+
+Note that in some cases \verb|\mathstrut| might not be enough, as in the introductory example:
+%
+\begin{LTXexample}[text outside listing,lefthand width=0.5in]
+\renewcommand{\eqnhighlightheight}{\mathstrut} % 0-width "constant" height
+\begin{equation*}
+ \eqnmarkbox[red]{Hhat}{\hat{H}} \eqnmarkbox[blue]{Psi}{\Psi}
+\end{equation*}
+\end{LTXexample}
+\noindent
+%
+You can create custom 0-width characters using \verb|\vphantom|:
+%
+\begin{LTXexample}[text outside listing,lefthand width=0.5in]
+\renewcommand{\eqnhighlightheight}{\vphantom{\hat{H}}\mathstrut} % custom 0-width height
+\begin{equation*}
+ \eqnmarkbox[red]{Hhat}{\hat{H}} \eqnmarkbox[blue]{Psi}{\Psi}
+\end{equation*}
+\end{LTXexample}
+\noindent
+%
+(It looks more balanced if you still include the \verb|\mathstrut|.)
+
+\subsection{Amount of shading of mark highlight}
+
+\verb|\eqnhighlightshade| defines the percentage of the specified color to take:
+%
+\begin{LTXexample}[text outside listing,lefthand width=0.5in]
+\renewcommand{\eqnhighlightshade}{17} % package default
+\begin{equation*}
+ \eqnmarkbox[red]{hbar}{\hbar} \eqnmarkbox[blue]{q}{q}
+\end{equation*}
+\end{LTXexample}
+\noindent
+%
+By redefining this command, you can change the ``alpha'' value of the highlight:
+%
+\begin{LTXexample}[text outside listing,lefthand width=0.5in]
+\renewcommand{\eqnhighlightshade}{47} % 0 is white, 100 is solid color
+\begin{equation*}
+ \eqnmarkbox[red]{hbar}{\hbar} \eqnmarkbox[blue]{q}{q}
+\end{equation*}
+\end{LTXexample}
+\noindent
+
+\subsection{Default formatting of annotation labels}
+
+\verb|\eqnannotationtext| is a one-argument command that gets the annotation text as an argument and can be used to have consistent formatting:
+\begin{LTXexample}[text outside listing,lefthand width=0.5in]
+% package default:
+\renewcommand{\eqnannotationtext}[1]{\sffamily\footnotesize#1\strut}
+
+\begin{equation*}
+ \eqnmarkbox[blue]{v}{v}
+\end{equation*}
+\annotate[yshift=-0.5em]{below}{v}{velocity}
+\vspace{1em}
+\end{LTXexample}
+\noindent
+%
+(The \verb|\strut| has a similar effect to \verb|\mathstrut| in \verb|\eqnhighlightheight|.)
+%
+\begin{LTXexample}[text outside listing,lefthand width=0.5in]
+\renewcommand{\eqnannotationtext}[1]{\bfseries\small#1}
+
+\begin{equation*}
+ \eqnmarkbox[blue]{v}{v}
+\end{equation*}
+\annotate[yshift=-0.5em]{below}{v}{velocity}
+\vspace{1em}
+\end{LTXexample}
+\noindent
+%
+
+\section{Recommendations, tips \& tricks}
+
+\subsection{Use \texttt{\textbackslash{}colorlet} for consistent, easily changeable colors}
+
+\subsection{Line breaks within annotations}
+\label{sec:multiline}
+
+Possible, but a bit annoying. By default, the formatting only covers the first line:
+%
+\begin{LTXexample}[text outside listing,lefthand width=0.5in]
+\begin{equation*}
+ \eqnmarkbox[blue]{h}{h}
+\end{equation*}
+\annotate[yshift=-0.5em]{below}{h}{Planck\\constant}
+\vspace{1em}
+\end{LTXexample}
+\noindent
+%
+Here is a manual work-around:
+%
+\begin{LTXexample}[text outside listing,lefthand width=0.5in]
+\begin{equation*}
+ \eqnmarkbox[blue]{h}{h}
+\end{equation*}
+\annotate[yshift=-0.5em]{below}{h}{Planck\\\sffamily\footnotesize constant}
+\vspace{1em}
+\end{LTXexample}
+\noindent
+
+\section{Known issues}
+
+\begin{itemize}
+ \item \texttt{label above}/\texttt{label below} not implemented for \verb|\annotate|.
+
+ \item Formatting only covers first line in multi-line annotation texts (see \cref{sec:multiline}).
+\end{itemize}
+
+\end{document}