我正在尝试“详细”地试用可用的字体,并编写了一个小型 LaTeX 文档,以便直观地比较字体,并突出显示主要特征。我的方法有几个问题,因此我试图看看万能的 tex.SE 是否\deitys
有更好的主意。
请考虑以下不那么最小的 AWE(几乎可以工作的示例):
\documentclass[margin=20pt,varwidth=100cm,]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{calc}
\usetikzlibrary{calc, positioning}
\usepackage{lmodern}
\usepackage{venturis}
\usepackage{librebaskerville}
\newlength\caph\newlength\desc\newlength\xlen\newlength\mlen%
\newcommand*{\prlen}[1]{%
% round to 1 digit:
\pgfmathparse{round(10*#1)/10.0}%
\pgfmathresult
}
%
\newcommand{\showfont}[1]{%
\setlength{\caph}{\heightof{A}}%
\setlength{\desc}{\depthof{Q}}%
\setlength{\xlen}{1ex}%
\setlength{\mlen}{1em}%
\begin{tikzpicture}[
every node/.style={inner sep=0pt},
]
\path (0,0) node[anchor = south west] (A) {#1} ;
\draw[red] (A.base west) -- (A.base east);
\coordinate (Aex) at ($(A.base west)+(0,\xlen)$);
\draw[blue] (Aex) -- ($(A.base east)+(0,\xlen)$);
\coordinate (Adesc) at ($(A.base west)-(0,\desc)$);
\draw[blue] (Adesc) -- ($(A.base east)-(0,\desc)$);
\coordinate (Acaph) at ($(A.base west)+(0,\caph)$);
\draw[blue] (Acaph) -- ($(A.base east)+(0,\caph)$);
\draw[green!60!black, thick] (Adesc) rectangle ++(\mlen, \mlen)
coordinate (Amlen);
%%
\small\ttfamily
\node [left=1em of A.base west, anchor=east, ] {baseline};
\node [left=1em of Aex, anchor=east, ] {1ex=\prlen{\xlen} pt};
\node [left=1em of Adesc, anchor=east, ] {desc=\prlen{\desc} pt};
\node [left=1em of Acaph, anchor=east, ] {caph=\prlen{\caph} pt};
\node [above right =1em of Amlen, anchor=west, ] {1em=\prlen{\mlen} pt};
\end{tikzpicture}%
}
\begin{document}
\librebaskerville
\fontsize{100pt}{120pt}\selectfont
\showfont{Quora Aegis 3.14159}
\bigskip
\fontfamily{yvtj}\fontsize{100pt}{120pt}\selectfont
\showfont{Quora Aegis 3.14159}
\bigskip
\fontfamily{yvtd}\fontsize{100pt}{120pt}\selectfont
\showfont{Quora Aegis 3.14159}
\bigskip
\fontfamily{lmr}\fontsize{100pt}{120pt}\selectfont
\showfont{Quora Aegis 3.14159}
\end{document}
这使:
我的问题是:我曾经使用小写字母“p”的深度来查找后代,直到我找到了如示例中的小写字母字体,然后我切换到大写字母“Q”。但我知道这将取决于字体。
现在,我知道有\fontdimen
和:有没有办法以通用的方式找到字体x-height
的em
设计尺寸作为后代、大写高度?
如果需要的话,我不介意切换到xelatex
或luatex
。而且找到字体的轴也很好……
答案1
我不会去猜测字母,而是使用整个字母表。
\documentclass[margin=20pt,varwidth=100cm,]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{calc, positioning}
\usepackage{lmodern}
\usepackage{venturis}
\usepackage{librebaskerville}
\newlength\caph
\newlength\desc
\newlength\xlen
\newlength\mlen
\newcommand*{\prlen}[1]{%
% round to 1 digit:
\pgfmathparse{round(10*#1)/10.0}%
\pgfmathresult
}
\newcommand{\Alphabet}{ABCDEFGHIJKLMNOPQRSTUVWXYZ}
\newcommand{\alphabet}{abcdefghijklmnopqrstuvwxyz}
\newcommand{\showfont}[1]{%
\settoheight{\caph}{\Alphabet}%
\settodepth{\desc}{\Alphabet\alphabet}%
\setlength{\xlen}{1ex}%
\setlength{\mlen}{1em}%
\begin{tikzpicture}[
every node/.style={inner sep=0pt},
]
\path (0,0) node[anchor = south west] (A) {#1} ;
\draw[red] (A.base west) -- (A.base east);
\coordinate (Aex) at ($(A.base west)+(0,\xlen)$);
\draw[blue] (Aex) -- ($(A.base east)+(0,\xlen)$);
\coordinate (Adesc) at ($(A.base west)-(0,\desc)$);
\draw[blue] (Adesc) -- ($(A.base east)-(0,\desc)$);
\coordinate (Acaph) at ($(A.base west)+(0,\caph)$);
\draw[blue] (Acaph) -- ($(A.base east)+(0,\caph)$);
\draw[green!60!black, thick] (Adesc) rectangle ++(\mlen, \mlen)
coordinate (Amlen);
%%
\small\ttfamily
\node [left=1em of A.base west, anchor=east, ] {baseline};
\node [left=1em of Aex, anchor=east, ] {1ex=\prlen{\xlen} pt};
\node [left=1em of Adesc, anchor=east, ] {desc=\prlen{\desc} pt};
\node [left=1em of Acaph, anchor=east, ] {caph=\prlen{\caph} pt};
\node [above right =1em of Amlen, anchor=west, ] {1em=\prlen{\mlen} pt};
\end{tikzpicture}%
}
\begin{document}
\librebaskerville
\fontsize{100pt}{120pt}\selectfont
\showfont{Quora Aegis 3.14159}
\bigskip
\fontfamily{yvtj}\fontsize{100pt}{120pt}\selectfont
\showfont{Quora Aegis 3.14159}
\bigskip
\fontfamily{yvtd}\fontsize{100pt}{120pt}\selectfont
\showfont{Quora Aegis 3.14159}
\bigskip
\fontfamily{lmr}\fontsize{100pt}{120pt}\selectfont
\showfont{Quora Aegis 3.14159}
\end{document}
x 高度(字体基础为 1ex)不需要反映无升部的小写字母的高度;但通常情况下会反映。大写字母的高度可能与小写字母的升部不同,因此您可能需要区分这两者,至少对于具有此属性的字体而言。