0

There are already several questions about absolute signs, like this one. My question is different in that I'm not satisfied with the typesetting of the absolute sign offered by any of the options I know about. Consider the following MWE, which illustrates the problem for the letter "G":

\documentclass[crop,varwidth]{standalone}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{tikz}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\newcommand\myslash{\char`\\}
\begin{document}
\texttt{|G|}: $|G|$

\texttt{\myslash left G\myslash right}: $\left|G\right|$

\texttt{\myslash lvert G\myslash rvert}: $\lvert G\rvert$

\texttt{\myslash abs\{G\}}: $\abs{G}$
\end{document}

All four options produce absolute signs that go too far below the baseline (for my taste):

enter image description here

With a new command:

\documentclass[crop,varwidth]{standalone}
\usepackage{tikz}

\newlength{\myht}
\newlength{\mydp} 

\newcommand{\myabs}[1]{%
  \settoheight{\myht}{#1}%
  \settodepth{\mydp}{#1}%
  \tikz[anchor=base, baseline=0pt] \draw[line cap=round] (0pt,-\mydp-0.2pt) -- (0pt,\myht+0.3pt);%  
  $\mkern0.6mu #1\mkern1.0mu$%
  \tikz[anchor=base, baseline=0pt] \draw[line cap=round] (0pt,-\mydp-0.2pt) -- (0pt,\myht+0.3pt);%
}

\begin{document}

\myabs{G} = 2

\myabs{g} = 3

\end{document}

I get what I think are better-looking absolute signs:

enter image description here

Of course, one can quibble about some of the spacing between the absolute signs and the letters as well as the distances above and below the letters; I did not try to tune these yet.

However, this is clearly not good enough because when you typeset a scalar product, we have two absolute values side-by-side.

enter image description here

The only solution I can see (other than using symbols in the dot product that have similar height and depths) is to allow a user to influence the typesetting of the absolute signs, for example like this:

\documentclass[crop,varwidth]{standalone}
\usepackage{tikz}
\usepackage{xifthen}

\newlength{\myht}
\newlength{\mydp} 

\newcommand{\myabs}[3]{%
  \settoheight{\myht}{#2}%
  \settodepth{\mydp}{#3}%
  \tikz[anchor=base, baseline=0pt] \draw[line cap=round] (0pt,-\mydp-0.2pt) -- (0pt,\myht+0.3pt);%  
  \ensuremath{\mkern0.6mu {#1}\mkern1.0mu}%
  \tikz[anchor=base, baseline=0pt] \draw[line cap=round] (0pt,-\mydp-0.2pt) -- (0pt,\myht+0.3pt);%
  \ensuremath{\mkern2.0mu}%final space
}

\begin{document}

\myabs{G}{G}{g}\myabs{g}{G}{g}

\end{document}

I'm interested in getting feedback on the new command, both from a typesetting point of view as well as from an implementation point of view.

user1362373
  • 2,859
  • 2
    a generally shorter | might be fine, that's just a matter of the font design, but moving the | down for g would be really weird. Having a default | that works for G and g is of course what leads to the relatively deep | that is the default cm design. – David Carlisle Oct 11 '19 at 11:42
  • @David Carlisle: I agree that moving the | for the g looks a little weird, but so does moving it up so it works for both G and g, in my opinion. In retrospect, it seems a bit odd that the absolute signs do not adapt to their "content" in the way the square-root sign does. – user1362373 Oct 11 '19 at 13:09
  • they do adapt if used with \left \right, although generally using fixed sizes rather than \left\right s recommended (not just here but for () as well) – David Carlisle Oct 11 '19 at 13:24
  • 1
    personally of the suggestions on offer I'd go with the default | it is tall enough for G and deep enough for g. but using a font with a shorter | would also work, I don't think anything that makes G and g have different | would be usable. – David Carlisle Oct 11 '19 at 13:27

0 Answers0