不同字体的 x 高度校正

不同字体的 x 高度校正

Boondox 书法数学字体和 Arev 数学字体的大写字母和小写字母的高度不一样。

调整答案使用 XeTeX/fontspec 伪造小型大写字母?,我过去常常scalebox定义和校正高度,使它们与大写字母和小写字母相匹配。请参阅下文包含高度校正的新宏的实现以及排除校正的\mathcalbd基本宏。\mathcalbdnocorr

出现了两个问题:

  • 不支持下标和上标
  • 与包有冲突bm
\documentclass{article}

\usepackage{graphicx}
\usepackage{arevmath}
\usepackage{amsmath}
% \usepackage{bm}

\DeclareFontFamily{U}{BOONDOX-calo}{\skewchar\font=45}
\DeclareFontShape{U}{BOONDOX-calo}{m}{n}{<-> BOONDOX-r-calo}{}
\DeclareFontShape{U}{BOONDOX-calo}{b}{n}{<-> BOONDOX-b-calo}{}
\makeatletter
\DeclareMathAlphabet{\m@thcalbd}{U}{BOONDOX-calo}{m}{n}
\SetMathAlphabet{\m@thcalbd}{bold}{U}{BOONDOX-calo}{b}{n}
% https://tex.stackexchange.com/questions/55664/
\def\calfont@helper#1 #2\relax{%
  \@calfont@helper#1\relax\relax%
  \if\relax#2\relax\else\ \@calfont@helper#2\relax\fi}
\def\@calfont@helper#1#2\relax{%
  \ifcat\relax#1#1% for escape sequences
  \else%
    \ifnum`#1=\lccode`#1\relax%
      \mathchoice%
        {\scalebox{1.20529}{$\m@th\m@thcalbd{#1}$}}%
        {\scalebox{1.20529}{$\m@th\m@thcalbd{#1}$}}%
        {\scalebox{.90396}{$\m@th\mkern-1.5mu\m@thcalbd{#1}$}}%
        {\scalebox{.70308}{$\m@th\mkern-1.1mu\m@thcalbd{#1}$}}%      
    \else\m@thcalbd{#1}\fi%
  \fi%
  \ifx\relax#2\relax\else\@calfont@helper#2\relax\fi}
\newcommand*{\mathcalbd}[1]{\bgroup\calfont@helper#1 \relax\relax\egroup}
\newcommand*{\mathcalbdnocorr}[1]{\m@thcalbd{#1}}
\makeatother

\begin{document}

Without height correction: $A\mathcalbdnocorr{A} a\mathcalbdnocorr{a}$

With height correction: $A\mathcalbd{A} a\mathcalbd{a}$

\bigskip

Two problems with the \verb+\mathcalbd+ macro:
\begin{enumerate}
\item \verb+\mathcalbd{A_a}+ does not work while
  \verb+\mathcalbdnocorr{A_a}+ does ($\mathcalbdnocorr{A_a}$). Same is
  true for superscripts.

\item \verb+\boldsymbol{\mathcalbd{A}}+ ($\boldsymbol{\mathcalbd{A}}$)
  does not work if package \texttt{bm} is loaded
\end{enumerate}


\end{document}

在此处输入图片描述

答案1

您可以使用两种字体系列,分别为大写和小写设置不同的缩放比例。

\documentclass{article}

\usepackage{arevmath}
\usepackage{amsmath}
\usepackage{bm}

\DeclareFontFamily{U}{BOONDOX-calo}{\skewchar\font=45 }
\DeclareFontShape{U}{BOONDOX-calo}{m}{n}{<-> s*[1.1] BOONDOX-r-calo}{}
\DeclareFontShape{U}{BOONDOX-calo}{b}{n}{<-> s*[1.1] BOONDOX-b-calo}{}
\DeclareFontFamily{U}{BOONDOX-calo-scaled}{\skewchar\font=45 }
\DeclareFontShape{U}{BOONDOX-calo-scaled}{m}{n}{<-> s*[1.20529] BOONDOX-r-calo}{}
\DeclareFontShape{U}{BOONDOX-calo-scaled}{b}{n}{<-> s*[1.20529] BOONDOX-b-calo}{}
\DeclareMathAlphabet{\mathcalupper}{U}{BOONDOX-calo}{m}{n}
\SetMathAlphabet{\mathcalupper}{bold}{U}{BOONDOX-calo}{b}{n}
\DeclareMathAlphabet{\mathcallower}{U}{BOONDOX-calo-scaled}{m}{n}
\SetMathAlphabet{\mathcallower}{bold}{U}{BOONDOX-calo-scaled}{b}{n}

\ExplSyntaxOn
\NewDocumentCommand{\mathcalbd}{m}
 {{
  \tl_set:Nn \l_tmpa_tl { #1 }
  \regex_replace_all:nnN { [a-z] } { \{ \c{mathcallower}\{\0\} \} } \l_tmpa_tl
  \mathcalupper{ \tl_use:N \l_tmpa_tl }
 }}
\ExplSyntaxOff

\begin{document}


With height correction: $A\mathcalbd{A} a\mathcalbd{a}$

Subscript: $\mathcalbd{A_a} X_{a\mathcalbd{a}}$

Bold: $\bm{A} \bm{\mathcalbd{A}} \bm{a}\bm{\mathcalbd{a}}$

Bold with subscripts: $\bm{\mathcalbd{A_a}}$

\end{document}

在此处输入图片描述

相关内容