# Depth and height confusion

I create two equations:

1. $x \notin \mathbb{N}$; and
2. $x \in \mathbb{N}$.

As it turns out, both have the same depth value:

1. Depth = 0.39098pt
Height = 7.5pt

2. Depth = 0.39098pt
Height = 6.88889pt

Clearly the first equation should have a larger depth than the second one, because the \notin sign goes deeper.

How can this be?

This is the code that is used to generate the two:

\documentclass[10pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[usenames]{color}

\pagestyle{empty}
\newsavebox{\eqbox}
\newlength{\width}
\newlength{\height}
\newlength{\depth}

\begin{lrbox}{\eqbox}
{$x \notin \mathbb{N}$}
\end{lrbox}

\settowidth {\width}  {\usebox{\eqbox}}
\settoheight{\height} {\usebox{\eqbox}}
\settodepth {\depth}  {\usebox{\eqbox}}
\newwrite\file
\immediate\openout\file=\jobname.bsl
\immediate\write\file{Depth = \the\depth}
\immediate\write\file{Height = \the\height}
\addtolength{\height} {\depth}
\immediate\write\file{TotalHeight = \the\height}
\immediate\write\file{Width = \the\width}
\closeout\file
\begin{document}
\usebox{\eqbox}
\end{document}


Could anyone tell me why that is?

• The official dimensions of a TeX box does not have to correspond to the printed area. It can be larger or smaller if required. Jul 20, 2013 at 17:45
• Jul 20, 2013 at 17:45

## 4 Answers

Not always. The best way to look at this would be from a bounding-box perspective:

\documentclass[10pt]{article}
\usepackage{amssymb,xcolor}% http://ctan.org/pkg/{amslatex,xcolor}
\newcommand{\showbb}[1]{{\color{red!50}\leavevmode\rlap{\fbox{\phantom{#1}}}}#1}
\begin{document}

\setlength{\fboxsep}{-\fboxrule}
\showbb{$x \notin \mathbb{N}$} \quad
\showbb{$x \in \mathbb{N}$}
\end{document}


As mentioned, it's clear that the both have the same depth, but not height. Why? This is decided in the font specification for each of the symbols by the font designer. In some cases, the bounding box of a character/symbol depends on what follows it (like V followed by A, for example). In this case (or most likely) the depth of the symbol is set so that it doesn't influence the baseline skip.

One way to check this would be if you were to have two \notin symbols on two successive lines. If the symbol had any greater depth, the line separation would make the output look awkward... in just one location. To avoid this, and knowing that the "\not" part of the symbol is a single (thin) rule, it should not influence the reader if it stretches down further than expected.

• Wow, very nice explanation, thank you! So I have to take into account that boxing bounds != actual printed area. Thank you for your immediate an nice visual explanation!!! Is there a "concept" of printed area, e.g. that would enable me to write out the acutal printing area? Jul 20, 2013 at 18:04
• I do not think, this is a "feature", but a side effect of the implementation using \ooalign. Correct box dimensions are important. I doubt, someone writes \notin and also wants to "cancel" the upper limit of a summation symbol a line below. Jul 20, 2013 at 18:24
• Ok, if this is rather a bug than a feature, then there is no reason for a "printing area". Jul 20, 2013 at 19:51

It is a side effect of the implementation of \notin. From fontmath.ltx (reformatted):

\DeclareRobustCommand\notin{%
\mathrel{%
\m@th
\mathpalette\c@ncel\in
}%
}
\def\c@ncel#1#2{%
% #1: math style
% #2: the symbol (here: \in)
\m@th
\ooalign{%
$\hfil#1\mkern1mu/\hfil$%
\crcr
$#1#2$%
}%
}


Simplified \notin makes a special table with one column. The first row contains a horizontally centered / shifted by 1mu to the right. The second row contains the symbol. However, you do not see two lines. The trick of \ooalign is to set the \baselineskip to zero. Thus both rows share the same baseline. The whole is put into a vertical box (\vtop). The height of the overall box comes from the height of the first box, the first line, the slash. Now a second box, the second line, follows, that means the depth of the first line does not count any more. Also the height of the second line is ignored, but the depth of the symbol in the second line becomes the depth of the overall box.

The following example compares the different variants:

• The first two boxes contain the single glyphs that shows that the character bounding boxes are correct.
• The third box \notin shows the composed symbol with the original definition as discussed above.
• The fourth box \NotIn uses a rewritten \c@ncel macro (\NewC@ncel) that takes both heights and depths into account.
• For comparison, the last box uses a different symbol \not and method for the negation.
\documentclass{article}

\usepackage{xcolor}

\makeatletter
\newcommand*{\NotIn}{%
\mathrel{%
\mathpalette\NewC@ncel\in
}%
}
\newcommand*{\NewC@ncel}[2]{%
% #1: math style
% #2: symbol
\sbox0{$#1#2\m@th$}%
\sbox2{$#1\mkern1mu/\m@th$}%
\ifdim\wd2>\wd0 %
\wd0=\wd2 %
\else
\setbox2=\hbox to \wd0{\hfil\unhcopy2\hfil}%
\fi
\rlap{\copy2}%
\copy0 %
}
\makeatother

\newcommand*{\test}[1]{%
\begingroup
\setlength{\fboxsep}{0pt}%
\setlength{\fboxrule}{.2pt}%
\sbox0{$#1$}%
\typeout{* [\detokenize{#1}: height=\the\ht0, depth=\the\dp0}%
\fcolorbox{blue}{white}{\copy0 } \texttt{\detokenize{#1}}%
\par
\endgroup
}

\begin{document}
\test{\in}
\test{/}
\test{\notin}
\test{\NotIn}
\test{\not\in}
\end{document}


If you want to used \notin (instead of the new macro \NotIn as in the example), then \c@ncel can be redefined:

\makeatletter
\newcommand*{\NewC@cncel}{...}% see above
\let\c@ncel\NewC@ncel
\makeatother


## Fixed suggestion for \ooalign

The following test file that can be used with plain TeX and LaTeX redefines \ooalign. The cell contents is first put into a box for measuring its height and depths, then the overall box is set to the maximum height and depth.

\ifx\documentclass\undefined
\nopagenumbers
\catcode\@=11 %
\else
\documentclass{article}
\pagestyle{empty}
\begin{document}
\makeatletter
\fi

\let\plain@ooalign\ooalign

%%% begin: \ooalign %%%
\newdimen\ooalign@height
\newdimen\ooalign@depth
% The implementation merges the original \ooalign'
% with the modified contents of \oalign'.
% The heights and depths are measured and the overall box
% is adjusted to get the maximum height and depth.
\def\ooalign#1{%
\leavevmode
\begingroup
\setbox\z@\vtop{%
\baselineskip\z@skip
\lineskip\z@ % might not be needed
\lineskiplimit=-\maxdimen
\global\ooalign@height\z@
\global\ooalign@depth\z@
\ialign{%
% the cell contents is measured and
% the maximum values for height and depth are remembered
\setbox\z@\hbox{##}%
\ifdim\ht\z@>\ooalign@height
\global\ooalign@height\ht\z@
\fi
\ifdim\dp\z@>\ooalign@depth
\global\ooalign@depth\dp\z@
\fi
\unhcopy\z@
\crcr
#1%
\crcr
}%
}%
\vtop{%
% update the height if needed
\ifdim\ooalign@height>\ht\z@
\hrule width\z@ height \ooalign@height depth\z@
\kern-\ht\z@
\fi
\unvcopy\z@
% update the depth if needed
\ifdim\ooalign@depth>\dp\z@
\kern-\dp\z@
\kern\ooalign@depth
\fi
}%
\endgroup
}
%%% end: \ooalign %%%

% for testing

\ifx\fbox\undefined
\newdimen\fboxrule
\newdimen\fboxsep
\newbox\@tempboxa
\newdimen\@tempdima

\long\def\fbox#1{%
\leavevmode
\setbox\@tempboxa\hbox{%
\begingroup
\kern\fboxsep{#1}\kern\fboxsep
\endgroup}%
\@frameb@x\relax
}%
\def\@frameb@x#1{%
\@tempdima\fboxrule
\advance\@tempdima\fboxsep
\advance\@tempdima\dp\@tempboxa
\hbox{%
\lower\@tempdima\hbox{%
\vbox{%
\hrule height\fboxrule
\hbox{%
\vrule width\fboxrule
#1%
\vbox{%
\vskip\fboxsep
\box\@tempboxa
\vskip\fboxsep}%
#1%
\vrule width\fboxrule}%
\hrule height\fboxrule
}%
}%
}%
}%
\fi
\fboxsep=0pt
\fboxrule=.1pt

\def\test{a\fbox{$\notin$}b\fbox{\copyright}c}

% original \ooalign
\begingroup
\let\ooalign\plain@ooalign
\test
\endgroup

% new \ooalign
\test

\ifx\enddocument\undefined
\def\next{\end}%
\else
\def\next{\end{document}}%
\fi
\next


• Thank you for clarifying. Using "\not \in" or your new macro does solve the "problem". Jul 20, 2013 at 19:54

\notin is defined as in plain tex, and carried along into latex. it doesn't require latex or amsfonts to demonstrate the absence of depth.

the relevant element is the use of \ooalign in the definition of \notin (via \c@ancel). \ooalign is defined thus (texbook, p.356):

\def\ooalign{\lineskiplimit-\maxdimen \oalign} % chars over each other


the \lineskiplimit effectively cancels out any height or depth of the components, as demonstrated by this little plain tex script:

\setbox0=\hbox{$/$}
\setbox1=\hbox{\ooalign{.\crcr/\crcr}
\showthe\dp0
\showthe\dp1
\bye


the output (to the screen) is these values:

> 2.5pt.
l.7 \showthe\dp0
?
> 0.0pt.
l.8 \showthe\dp1


\showthe\ht1 will also report a value of 0.0pt.

whether this has caused problems for anyonw is an open question; however, it hasn't bothered anyone enough in 30+ years to have reported it as a bug.

• The symbol \copyright of plain.tex also uses \ooalign. Here the insufficient implementation of \ooalign shows the problem in the other direction. The height is too small, because the height of the symbol for the circle is ignored. Jul 20, 2013 at 18:45
• @HeikoOberdiek -- i've checked the archive. if you would like to report this as a bug (or, more likely, misfeature), send it in with a compelling example, and i'll forward it to don when he asks for the reports later this year. he may reply that it should now be considered a feature, but it will get an explanation and go on the record. Jul 20, 2013 at 19:00
• I have written an email to you with the problem report. Also I have made a LaTeX bug report as well: latex/4322. Jul 20, 2013 at 21:22

An easier implementation of a \dpnotin which has the depth of the slash:

\documentclass{article}
\makeatletter
\DeclareRobustCommand{\dpnotin}{%
\mathrel{\m@th\mathpalette\c@ncel{{\in}\vphantom{/}}}%
}
\makeatother

\begin{document}
\fboxsep=0pt
\fbox{$x\notin N$}\,\fbox{$x\dpnotin N$}

\fbox{$x\notin N$}\,\fbox{$x\notin N$}
\end{document}


We pass \c@ncel the argument {\in}\vphantom{/}`, so the phantom will set the depth of the construction in the correct way. The second line in the example is just to check that the horizontal size doesn't change; the third and fourth line are for checking the symbol in subscripts.