GeneralMismatch between \settoheight and \ht

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
shoening
Posts: 1
Joined: Mon Jan 06, 2025 3:54 pm

Mismatch between \settoheight and \ht

Post by shoening »

Hi,

for an issue with a LaTeX-Style (chess-problem-diagrams) I played around measuring the heights and depths of some chessfont.
I tried measuring by plain TeX means and by LaTeX means as follows:

plain-TeX:

Code: Select all

\documentclass{article}

\usepackage{ifthen}

\begin{document}

\font\chessfont=fselch12
\setlength{\fboxsep}{0pt}
\setlength{\parindent}{0mm}
\setlength{\parskip}{2ex}

\newbox\cfb
\newlength{\cfbheight}
\newlength{\cfbdepth}

\newcounter{piece}
\setcounter{piece}{0}
\whiledo{\value{piece} < 108}{%
    \setbox\cfb=\hbox{\chessfont\char\value{piece}}%
    \cfbheight=\ht\cfb{}%
    \cfbdepth=\dp\cfb{}%
    \arabic{piece}: \fbox{\box\cfb}\ \ --- \ \ % 
    height: \the\cfbheight\ \ --- \ \ % 
    depth: \the\cfbdepth\par
    \stepcounter{piece}%
}
\end{document}
Compiling this shows a character height of 12pt and a depth of 0pt for each character.

LaTeX:

Code: Select all

\documentclass{article}

\usepackage{ifthen}

\begin{document}

\font\chessfont=fselch12 
\setlength{\fboxsep}{0pt}
\setlength{\parindent}{0mm}
\setlength{\parskip}{2ex}

\newsavebox{\chessfontbox}
\newlength{\chessfontheight}
\newlength{\chessfontdepth}

\newcounter{piece}
\setcounter{piece}{0}
\whiledo{\value{piece} < 108}{%
    \savebox{\chessfontbox}{\chessfont\char\value{piece}}%
    \settoheight{\chessfontheight}{\chessfontbox}%
    \settodepth{\chessfontdepth}{\chessfontbox}%
    \arabic{piece}: \fbox{\usebox{\chessfontbox}}\ \ --- \ \ % 
    height: \the\chessfontheight\ \ --- \ \ % 
    depth: \the\chessfontdepth\par
    \stepcounter{piece}%
}
\end{document}
Compiling this using latex or pdflatex shows a height of 6.44444pt and a depth of 0pt for each of the 108 characters.

Why is there a different height when using \settoheight instead of plain-TeX \ht? (As the font is designed to be 12pt I assume that the plain-TeX result is the correct one.)

And for my final confusion: I tried to compile both using "lualatex" (instead of latex or pdflatex) in which case the height of the characters output as 6.66pt with a dept of 0.22pt when using the LaTeX method (\settoheight).

Is there anything wrong with my code?

Yours
Stefan

PS: First line of my log containing the pdfTeX version:
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/Debian) (preloaded format=pdflatex 2024.12.22) 5 JAN 2025 19:11

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
Post Reply