Como imprimir várias métricas relacionadas ao tipo

Como imprimir várias métricas relacionadas ao tipo

Na resposta de @Johan_E paraQuais unidades de medida devem ser usadas no LaTeX?, existem gráficos úteis que mostram o tamanho, em pontos, de 1em, a largura de um M, 1ex e a altura de um x. Como posso produzir esse gráfico? Mais útil seria um exemplo de como produzir a primeira linha para ilustrar os comandos de medição e/ou uma outra linha (digamos bf, it) para ilustrar como a seleção da fonte é feita. (Eu sei como conseguir um bf,it M, mas como faço para conseguir um bf,it 1em?)

Estou sempre tentando dimensionar o zlmtt para corresponder à minha fonte, ampliando a tela do visualizador de PDF e observando-o. Ter medições reais tornaria esse dimensionamento muito mais fácil.

Seguindo o conselho de @jfbu no comentário abaixo, extraí o seguinte do loop xintools, que parece funcionar.

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

Responder1

Aqui você vai:

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

( \normalsizeadicionado na edição, porque toda a tabela foi produzida anteriormente em \smallregime, incluindo cálculo de dimensões).

insira a descrição da imagem aqui


Atenção que na tabela acima há uma série de substituições de fontes acontecendo:

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.

Pensei, por exemplo, em desenhar uma linha riscada em toda a linha, mas fazer isso automaticamente traz complicações. Como este não é o foco principal do OP, deixo como está.


Para determinação automática, copiando descaradamente a resposta do egreg para outra sintaxe. Observe que xinttoolso usado acima é um pacote separado do xintfracusado abaixo.

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

insira a descrição da imagem aqui

Você encontrará no registro:

zlmtt scaling factor: 0.9143980556305698

Isso difere no último dígito do cálculo do l3fp, mas não é muito relevante tipograficamente...

(experimente, \xintPFloat [32]...por exemplo, se você quiser mais dígitos --irrelevant--, bem, ok, consegui:

zlmtt scaling factor: 0.91439805563056980826357007831488

Eu realmente precisaria de um fator de escala 0.1para esconder minhas brincadeiras irrelevantes aqui)

Responder2

Posso oferecer uma macro para decidir o fator de escala da forma mais automática possível:

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

insira a descrição da imagem aqui

Se eu mudar a chamada para \scalezlmtt{a},

\AtBeginDocument{\scalezlmtt{a}}

\begin{document}

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

\end{document}

eu recebo

insira a descrição da imagem aqui

Há também um “fator de correção”

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

\begin{document}

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

\end{document}

insira a descrição da imagem aqui

Isso deve ser flexível o suficiente para evitar pesquisas em tabelas ou observações. Ao fazer o trabalho \AtBeginDocument, a chamada \normalfontserá a correta. Basta carregar outros pacotes de fontes antes desta instrução, pois alguns deles também realizam ações no início do documento.

O truque é usar lmttpara a medição, para que isso ainda não acione o carregamento do arquivo <encoding>zlmtt.fd.

No arquivo de log você verá algo como

zlmtt scaling: 0.9143980556305699

(este é o valor usado no último exemplo) e você pode querer arredondá-lo e usá-lo na opção de pacote quando tiver certeza de que será adequado para você.

informação relacionada