如何打印各种类型相关的指标

如何打印各种类型相关的指标

在@Johan_E的回答中在 LaTeX 中应该使用哪些测量单位?,有一些有用的图表显示 1em 的大小(以磅为单位)、 的宽度M、 1ex 和 的高度x。我如何制作这样的图表?最有用的是如何生成第一行以说明测量命令和/或另一行(例如 bf, it)以说明如何完成字体选择的示例。(我知道如何获取 bf,it M,但我如何获取 bf,it 1em?)

我总是尝试缩放 zlmtt 以匹配我的字体,在 pdf 查看器屏幕上放大并目测。实际测量会使这种缩放变得容易得多。

采用下面评论中@jfbu 的建议,我从 xintools 循环中提取了以下内容,这似乎有效。

\documentclass{article}
\usepackage[T1]{fontenc}

\newcommand\oneem{}
\newcommand\oneex{}
\newcommand\Mwidth{}
\newcommand\xheight{}
\newcommand\xwidth{}
\newcommand\xdepth{}

\begin{document}
\edef\oneem{\the\dimexpr 1em\relax}%
\edef\oneex{\the\dimexpr 1ex\relax}%
\setbox0\hbox{M}%
\edef\Mwidth{\the\wd0}%
\setbox0\hbox{x}%
\edef\xheight{\the\ht0}%
\edef\xwidth{\the\wd0}%
\edef\xdepth{\the\dp0}%
%
\begin{tabular}{lllllll}
  font & 1em    & M-width & 1ex    & x-height & x-width & x-depth \\
  rm   & \oneem & \Mwidth & \oneex & \xheight & \xwidth & \xdepth
\end{tabular}
\end{document}

答案1

干得好:

\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在编辑中添加,因为所有表格都是在\small制度下先前制作的,包括尺寸的计算)。

在此处输入图片描述


请注意,上表中正在进行大量字体替换:

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.

我考虑过例如在整行上画一条删除线,但这样做会很麻烦。由于这不是原帖的重点,所以我就保持原样。


为了自动确定,厚颜无耻地将 egreg 的答案复制到另一个语法中。请注意,xinttools上面的 used 是与下面的 used 不同的包xintfrac

\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}

在此处输入图片描述

您将在日志中发现:

zlmtt scaling factor: 0.9143980556305698

这与 l3fp 的计算在最后一位数字上有所不同,但这与印刷相关性不大……

(例如,如果您想要更多——不相关的——数字,请尝试一下\xintPFloat [32]...,好吧,我做到了:

zlmtt scaling factor: 0.91439805563056980826357007831488

我确实需要一个缩放因子来0.1隐藏我在这里不相关的玩弄)

答案2

我可以提供一个宏来尽可能自动地决定比例因子:

\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}

在此处输入图片描述

如果我将调用\scalezlmtt{a}改为

\AtBeginDocument{\scalezlmtt{a}}

\begin{document}

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

\end{document}

我明白了

在此处输入图片描述

还有一个“修正因素”

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

\begin{document}

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

\end{document}

在此处输入图片描述

这应该足够灵活,可以避免在表格中查找或目测。通过执行作业\AtBeginDocument,对的调用\normalfont将是正确的。只需在此指令之前加载其他字体包,因为其中一些也在开始文档时执行操作。

诀窍是用于lmtt测量,因此这不会触发的加载<encoding>zlmtt.fd

在日志文件中你会看到类似

zlmtt scaling: 0.9143980556305699

(这是最后一个例子使用的值)并且一旦您确定它适合您,您可能想要将其四舍五入并在包选项中使用它。

相关内容