I am using underarrows from amsmath
to decorate messages with their direction, as in $\underleftarrow{\mathsf{msg}}$
() and $\underrightarrow{\mathsf{msg}}$
(). I am looking for a better underarrow, in several senses:
- Smaller depth of entire construction. The underarrows add depth to the message names. I often use these in multiline constructions, such as
align*
, and the extra depth affects the apparent spacing. For example, compare the following versions that use underarrows and underlines.
Using\smash[b]
does eliminate the added depth but also, for some reason, shifts the arrow down:
- Shorter minimum arrow length. With the standard underarrows, message names that consist of a single letter are overpowered by the arrow. For example,
$\underleftarrow{\mathsf{p}}$
produces . - Smaller arrow head. To my eye, the arrow head looks too large for my use case.
Are there left and right underarrows that better meet these three criteria? Is there a way that I can construct my own underarrows?
Here is a MWE, in case it is useful:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
\begin{aligned}[t]
&\mathsf{bit_0} \bullet \underleftarrow{\mathsf{inc}} \\
&\mathsf{bit_1} \bullet \underleftarrow{\mathsf{p}}
\end{aligned}\quad
\begin{aligned}[t]
&\mathsf{bit_0} \bullet \smash[b]{\underleftarrow{\mathsf{inc}}} \\
&\mathsf{bit_1} \bullet \smash[b]{\underleftarrow{\mathsf{p}}}
\end{aligned}
\end{equation*}
\end{document}
Best Answer
I don’t know how much
amsmath
’s\underleftarrow
slows the compilation down or how it would with TikZ, but here is a solution that uses PGF and avoids the parsing process of TikZ.The proposed solution uses only one
\pgfpicture
which measured the under-arrowed math content after typesetting it in an box usingand later
where the saved font setting is set again, combined with
\mathpalette
which forwards the current math style to\@pgfunderleftarrow
.The box’s width is stored in
\pgfutil@tempdimb
which is then used in drawing the line (where we have used\wd\pgfutil@tempboxa
directly, too).This makes it possible to let TeX typeset the math content as it is but also measure it as precise as possible. As I realized later, even the original
\underleftarrow
doesn’t kepp the math family font settings (like\mathsf
) so maybe you want to change this again.This
\the\fam
trick was provided by egreg in a chat message from 2013-07-31:It seems also to work for more than one symbol.
The original definition of the
to
arrow isThe important part is the setup of
\pgfutil@tempdima
as the y value of the\pgfpathmoveto
coordinate is4\pgfutil@tempdima
which makes up the vertical height of the arrow.\pgfutil@tempdima
in the definition of\@pgfunderleftarrow
is used to calculate this height (we cannot extract it from some macro like the left and right extend).To let the arrow arc touch the bottom of the math content we would use:
The last line adds half the line width of the arrow line (which is set to
0.8\pgflinewidth
).So why did I do something differently, namely \pgfutil@tempdima=0.28pt% \advance\pgfutil@tempdima by.8\pgflinewidth% \pgfutil@tempdima-4\pgfutil@tempdima
Because I haven’t done it right (
.5
instead of.4
of the line width added and before the multiplication of the factor4
), but it looks right.Of course, you can change the factors and addition if you think it looks better.
The unstarred version of
\pgfunderleftarrow
doesn’t add any depth to the line (other than the depth of the math content itself). If this depth is needed (take a look at a\frac
tion), the starred version\pgfunderleftarrow*
can be used.Code
Output
Original
\underleftarrow
(last line uses\mathsf{\pgfunderleftarrow{f}}
)PGF version