Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiline formatting bug #11

Merged
merged 4 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified annotate-equations.pdf
Binary file not shown.
14 changes: 9 additions & 5 deletions annotate-equations.sty
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
\newcommand{\eqnhighlightshade}{17} % light
%\renewcommand{\eqnhighlightshade}{47} % dark

\newcommand{\eqnannotationtext}[1]{\sffamily\footnotesize#1\strut} %%% TODO remove textsf/footnotesize/strut?
\newcommand{\eqnannotationstrut}{\strut} % Package default
\newcommand{\eqnannotationfont}{\sffamily\footnotesize}


\providecommand\EAmarkanchor{north} % default set to "above"
Expand Down Expand Up @@ -126,10 +127,12 @@
\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
\node[anchor=\swapNorthSouth{\EAmarkanchor},color=\myEAcolor!85,
font=\eqnannotationfont,#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}};
{\myEAtext\eqnannotationstrut};
% 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}%
Expand Down Expand Up @@ -167,11 +170,12 @@
%
\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...
\node[anchor=\swapNorthSouth{\EAmarkanchor} \swapWestEast{\EAwesteast},
color=\myEAcolor!85,font=\eqnannotationfont,#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}};
{\myEAtext\eqnannotationstrut};
\foreach \EAmark in \myEAmarks
\draw [color=\myEAcolor] (\EAmark.\EAmarkanchor) % arrow from the equation
% \EAmarkanchor north: above the equation, south: below
Expand Down
43 changes: 20 additions & 23 deletions annotate-equations.tex
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ \subsection{Amount of shading of mark highlight}

\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:
\verb|\eqnannotationfont| sets the \texttt{font} field of the TikZ annotation label and can be re-set to change its formatting:
\begin{LTXexample}[text outside listing,lefthand width=0.5in]
% package default:
\renewcommand{\eqnannotationtext}[1]{\sffamily\footnotesize#1\strut}
\renewcommand{\eqnannotationfont}{\sffamily\footnotesize}

\begin{equation*}
\eqnmarkbox[blue]{v}{v}
Expand All @@ -230,10 +230,8 @@ \subsection{Default formatting of annotation labels}
\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}
\renewcommand{\eqnannotationfont}{\bfseries\small}

\begin{equation*}
\eqnmarkbox[blue]{v}{v}
Expand All @@ -242,37 +240,37 @@ \subsection{Default formatting of annotation labels}
\vspace{1em}
\end{LTXexample}
\noindent
%

\verb|\eqnannotationstrut| is defined to be a strut (zero-width height) to
provide minimum distance between the text and the corresponding arrow line. By
default it is \verb|\strut|, which has a similar effect to
\verb|\mathstrut| in \verb|\eqnhighlightheight|.

\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]
\renewcommand{\eqnannotationstrut}{\strut} % package default
\begin{equation*}
\eqnmarkbox[blue]{h}{h}
\eqnmarkbox[blue]{size}{s}
\end{equation*}
\annotate[yshift=-0.5em]{below}{h}{Planck\\constant}
\annotate[yshift=-0.5em]{below}{size}{The size}
\vspace{1em}
\end{LTXexample}
\noindent
%
Here is a manual work-around:
%
\begin{LTXexample}[text outside listing,lefthand width=0.5in]
\renewcommand{\eqnannotationstrut}{}

\begin{equation*}
\eqnmarkbox[blue]{h}{h}
\eqnmarkbox[blue]{size}{s}
\end{equation*}
\annotate[yshift=-0.5em]{below}{h}{Planck\\\sffamily\footnotesize constant}
\annotate[yshift=-0.5em]{below}{size}{The size}
\vspace{1em}
\end{LTXexample}
\noindent


\section{Recommendations, tips \& tricks}

\subsection{Use \texttt{\textbackslash{}colorlet} for consistent, easily changeable colors}


\subsection{Relations such as ``$=$''}
\label{sec:mathrel}
Expand Down Expand Up @@ -311,7 +309,6 @@ \section{Known issues}
\begin{itemize}
\item \texttt{label above}/\texttt{label below} is not implemented for \verb|\annotate|.

\item Formatting only covers first line in multi-line annotation texts (see \cref{sec:multiline}).
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing it 🎉

\item Annotations of mathematical relations require some manual patching to get the correct surrounding spacing (see \cref{sec:mathrel}).

\end{itemize}
Expand Down