How to print various type-related metrics

Here you go:

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[margin=1cm]{geometry}
\usepackage{xinttools}

\newcommand\WithFont [4]{%
   \csname text#1\endcsname {%
      \csname text#3\endcsname {%
         \csname text#2\endcsname {#4}}}}

\begin{document}
\begin{table}
  \centering
\Large\textbf{Computer Modern fonts (pdf\LaTeX) [10pt]}\\
\small
Selected using \detokenize{\textA{\textB{\textC{(some text)}}}},\\
with A in \detokenize{{rm, sf, tt}}; B in \detokenize{{md, bf}}; C in
\detokenize{{up, it, sl, sc}}\\
  \begin{tabular}{*{9}{l}}
    \bf Font&\bf 1em&&\bf M-width&\bf 1ex&&\bf x-height&\bf x-width&\bf x-depth\\
\hline
\xintForpair #1#2 in {(Roman,rm), (Sans,sf), (Typewriter,tt)} \do
{%
\xintFor #3 in {up, it, sl, sc}\do
  {%
    \xintFor #4 in {md, bf}\do
    {%
      \WithFont {#2}{#3}{#4}{#1, #3, #4\normalsize
                             \xdef\oneem{\the\dimexpr 1em\relax}%
                             \xdef\oneex{\the\dimexpr 1ex\relax}%
                             \setbox0\hbox{M}\xdef\Mwidth{\the\wd0}%
                             \setbox0\hbox{x}\xdef\xheight{\the\ht0}%
                                             \xdef\xwidth{\the\wd0}%
                                             \xdef\xdepth{\the\dp0}}%
      &\oneem&\WithFont{#2}{#3}{#4}{\normalsize\strut M}&\Mwidth
      &\oneex&\WithFont{#2}{#3}{#4}{\normalsize x}&\xheight&\xwidth&\xdepth
     \\
     }%
   }\hline
}\hline
  \end{tabular}
\end{table}
\end{document}

(\normalsize added in edit, because all the table was produced earlier under \small regime, including computation of dimensions).

enter image description here


Attention that in the table above, there are a number of font substitutions going on :

LaTeX Font Warning: Font shape `T1/cmss/m/sc' in size <9> not available
(Font)              Font shape `T1/cmr/m/sc' tried instead on input line 55.

LaTeX Font Warning: Font shape `T1/cmss/m/sc' in size <10> not available
(Font)              Font shape `T1/cmr/m/sc' tried instead on input line 55.

LaTeX Font Warning: Font shape `T1/cmss/bx/sc' undefined
(Font)              using `T1/cmss/bx/n' instead on input line 55.

LaTeX Font Info:    Font shape `T1/cmtt/bx/n' in size <9> not available
(Font)              Font shape `T1/cmtt/m/n' tried instead on input line 55.
LaTeX Font Info:    Font shape `T1/cmtt/bx/n' in size <10> not available
(Font)              Font shape `T1/cmtt/m/n' tried instead on input line 55.
LaTeX Font Info:    Font shape `T1/cmtt/bx/it' in size <9> not available
(Font)              Font shape `T1/cmtt/m/it' tried instead on input line 55.
LaTeX Font Info:    Font shape `T1/cmtt/bx/it' in size <10> not available
(Font)              Font shape `T1/cmtt/m/it' tried instead on input line 55.

LaTeX Font Warning: Font shape `T1/cmtt/bx/sl' undefined
(Font)              using `T1/cmtt/bx/n' instead on input line 55.

LaTeX Font Info:    Font shape `T1/cmtt/bx/sl' in size <10> not available
(Font)              Font shape `T1/cmtt/m/n' tried instead on input line 55.
LaTeX Font Info:    Font shape `T1/cmtt/bx/sl' in size <9> not available
(Font)              Font shape `T1/cmtt/m/n' tried instead on input line 55.

LaTeX Font Warning: Font shape `T1/cmtt/bx/sc' undefined
(Font)              using `T1/cmtt/bx/n' instead on input line 55.

LaTeX Font Info:    Font shape `T1/cmtt/bx/sc' in size <10> not available
(Font)              Font shape `T1/cmtt/m/n' tried instead on input line 55.
LaTeX Font Info:    Font shape `T1/cmtt/bx/sc' in size <9> not available
(Font)              Font shape `T1/cmtt/m/n' tried instead on input line 55.

I thought about for example drawing a strike-through line across the full row, but doing this automatically has complications. As this is not the main focus of the OP, I just leave standing as is.


For automatic determination, shamelessly copying over egreg's answer into another syntax. Notice that xinttools used above is a separate package from xintfrac used below.

\documentclass[border=4pt]{standalone}

\usepackage{zlmtt}
\usepackage{xintfrac}


\makeatletter
\newcommand{\scalezlmtt}[2][1]{%
   {\setbox0\hbox{\normalfont #2}%
    \setbox2\hbox{\fontfamily{lmtt}\selectfont #2}%
    \xdef\zlmtt@scale {\xintPFloat {\xintMul{#1}{\ht0/\ht2}}}%
    \typeout{zlmtt scaling factor: \zlmtt@scale}% 
   }%
}%
\makeatother

\AtBeginDocument{\scalezlmtt[.9]{a}}

\begin{document}

TT font scaled to 90\% lowercase: A\texttt{A}a\texttt{a}

\end{document}

enter image description here

You will find in the log:

zlmtt scaling factor: 0.9143980556305698

This differs in the last digit from l3fp's calculation, but that's not so much typographically relevant...

(try it with \xintPFloat [32]... for example if you want more --irrelevant-- digits, well ok I did it:

zlmtt scaling factor: 0.91439805563056980826357007831488

I would really need a scaling factor of 0.1 to hide my irrelevant toying here)


I can offer a macro for deciding the scale factor as automatically as possible:

\documentclass{article}

\usepackage{zlmtt}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\scalezlmtt}{O{1}m}
 {
  \hbox_set:Nn \l_tmpa_box { \normalfont #2 }
  \hbox_set:Nn \l_tmpb_box { \fontfamily{lmtt}\selectfont #2 }
  \tl_set:cx { zlmtt@scale }
   {
    \fp_eval:n
     {
      #1 *
      \dim_to_fp:n { \box_ht:N \l_tmpa_box } /
      \dim_to_fp:n { \box_ht:N \l_tmpb_box }
     }
   }
  \typeout{ zlmtt~scaling:~\tl_use:c { zlmtt@scale } }
 }
\ExplSyntaxOff

\AtBeginDocument{\scalezlmtt{A}}

\begin{document}

TT font scaled to uppercase: A\texttt{A}a\texttt{a}

\end{document}

enter image description here

If I change the call to \scalezlmtt{a},

\AtBeginDocument{\scalezlmtt{a}}

\begin{document}

TT font scaled to lowercase: A\texttt{A}a\texttt{a}

\end{document}

I get

enter image description here

There's also a “correction factor”

\AtBeginDocument{\scalezlmtt[.9]{a}}

\begin{document}

TT font scaled to 90\% lowercase: A\texttt{A}a\texttt{a}

\end{document}

enter image description here

This should be flexible enough for avoiding lookups in tables or eyeballing. By doing the job \AtBeginDocument, the call to \normalfont will be the right one. Just load other font packages before this instruction, because some of them do actions at begin document too.

The trick is to use lmtt for the measurement, so this doesn't yet trigger the loading of <encoding>zlmtt.fd.

In the log file you'll see something like

zlmtt scaling: 0.9143980556305699

(this is the value used for the last example) and you may be wanting to round it and use in the package option once you're sure it will suit you.