| 1 |
# Annotate equations in LaTeX using TikZ |
| 2 |
|
| 3 |
( [Documentation](annotate-equations.pdf) | License: [MIT](LICENSE) | [CTAN](https://ctan.org/pkg/annotate-equations) ) |
| 4 |
|
| 5 |
This package provides commands that make it easy to highlight terms in equations & add annotation labels (based on TikZ). |
| 6 |
Tested with pdflatex and lualatex, but should work with most other LaTeX engines such as xelatex as well. |
| 7 |
|
| 8 |
Inspired by Sibin Mohan's https://github.com/synercys/annotated_latex_equations/ |
| 9 |
|
| 10 |
Please report any bugs, issues, contribute changes & improvements on https://github.com/st--/annotate-equations/ :) |
| 11 |
|
| 12 |
Package author: ST John, http://www.infinitecuriosity.org/ |
| 13 |
|
| 14 |
|
| 15 |
## A package with reusable commands |
| 16 |
|
| 17 |
 |
| 18 |
|
| 19 |
Using [`annotate-equations.sty`](https://github.com/st--/annotate-equations/blob/main/annotate-equations.sty), an equation can easily be annotated as follows: |
| 20 |
```latex |
| 21 |
\begin{equation*} |
| 22 |
\mathcal{O}\big( |
| 23 |
( |
| 24 |
\eqnmarkbox[NavyBlue]{p1}{p} |
| 25 |
\eqnmarkbox[OliveGreen]{k1}{\kappa}^3 % note that we have the ^3 outside the \eqnmark/\tikzmarknode arguments |
| 26 |
) |
| 27 |
\eqnmarkbox[WildStrawberry]{T1}{T} |
| 28 |
+ |
| 29 |
( |
| 30 |
\eqnmarkbox[NavyBlue]{p2}{p} % tikz nodes need distinct names! |
| 31 |
\eqnmark[OliveGreen]{k2}{\kappa} |
| 32 |
) |
| 33 |
( |
| 34 |
\eqnmarkbox[WildStrawberry]{T2}{T}^2 |
| 35 |
\tikzmarknode{Is}{|\mathcal{I}^*|} % manual \tikzmarknode works, too |
| 36 |
\eqnmarkbox[Plum]{Nb}{N_b} |
| 37 |
\eqnmark[RoyalPurple]{M}{M} |
| 38 |
) |
| 39 |
\big) |
| 40 |
\end{equation*} |
| 41 |
\annotatetwo[yshift=1em]{above}{p1}{p2}{\# of nodes} |
| 42 |
\annotatetwo[yshift=-1em,xshift=0.2ex]{below}{T1}{T2}{\# of graphs in $\hat{\mathcal{G}}_T$} |
| 43 |
\annotatetwo[yshift=-2em]{below}{k1}{k2}{max.\ indegree in $\hat{\mathcal{G}}_T$} |
| 44 |
\annotate[yshift=3em]{above,left}{Is}{size of set of allowed interventions} |
| 45 |
\annotate[yshift=1em]{above}{Nb}{\# of samples per batch} |
| 46 |
\annotate[yshift=-1em]{below}{M}{\# of samples for $\mathbb{E}_y$} |
| 47 |
``` |
| 48 |
|
| 49 |
More details are in the [user manual](annotate-equations.pdf). |
| 50 |
Should work with both pdflatex and lualatex. |
| 51 |
|
| 52 |
## How to do it from scratch: annotated examples |
| 53 |
|
| 54 |
 |
| 55 |
|
| 56 |
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. |
| 57 |
|
| 58 |
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/. |
| 59 |
|
| 60 |
### Giving all highlight boxes the same height |
| 61 |
|
| 62 |
Simply add a `\mathstrut` within the colorbox: |
| 63 |
```diff |
| 64 |
-\newcommand{\highlight}[2]{\colorbox{#1!17}{$#2$}} |
| 65 |
+\newcommand{\highlight}[2]{\colorbox{#1!17}{$\mathstrut #2$}} |
| 66 |
``` |
| 67 |
|
| 68 |
 |
| 69 |
|
| 70 |
## Much more information... |
| 71 |
|
| 72 |
...in the answers to [this TeX StackExchange question](https://tex.stackexchange.com/q/254844/171664). |