XCharter 困境:我必须在破解数学和伪代码显示之间做出选择吗?

XCharter 困境:我必须在破解数学和伪代码显示之间做出选择吗?

我正在尝试为包含数学和算法块的文档设置字体。我正在使用 XCharter 字体和软件包algorithm2e。出于某种原因,我无法正确排版。下面是 MWE 来演示我的问题。

\documentclass{article}

% \usepackage{XCharter} % needed for math fonts, uncommenting will break fonts in the algorithm environment 
\usepackage[xcharter,bigdelims,slantedGreek,vvarbb,scaled=1.07]{newtxmath} % math, iso 31-compliant(ish)
\usepackage[no-math]{fontspec}
\setmainfont{XCharter}

\usepackage{algorithm2e}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
    a + b = \int_0^{+\infty} \frac{\partial u}{\partial x} \times \alpha' \, \mathrm{d} \boldsymbol{l}
\end{equation*}

\begin{equation*}
    \alpha + \upbeta = \int_0^{+\infty} \frac{\partial \upPi}{\partial \Theta} \times \epsilon' \, \mathrm{d} \boldsymbol{\gamma}
\end{equation*}

\begin{algorithm}[H]
    \SetAlgoLined
    \KwData{this text}
    \KwResult{how to write algorithm with \LaTeX2e }
    initialization\;
    \While{not at end of this document}{
    read current\;
    \eIf{understand}{
    go to next section\;
    current section becomes this one\;
    }{
    go back to the beginning of current section\;
    }
    }
    \caption{How to write algorithms}
\end{algorithm}

\end{document}

如果我不使用该XCharter包,那么微分(使用 d)将使用 Computer Modern 排版。

差速器采用计算机现代排版

如果我确实使用它,微分会被正确排版,但算法块的渲染效果会很糟糕。

错误呈现的算法块

我究竟做错了什么?

答案1

由于字体设置不标准,需要您的帮助:

\documentclass{article}

\usepackage[xcharter,bigdelims,slantedGreek,vvarbb,scaled=1.07]{newtxmath} % math, iso 31-compliant(ish)
\usepackage{fontspec}
\setmainfont{XCharter}
\usepackage{amsmath}

\usepackage{algorithm2e}
\usepackage{metalogox}

\AtBeginDocument{%
  \DeclareSymbolFont{operators}{OT1}{XCharter-TLF}{m}{n}%
  \SetSymbolFont{operators}{bold}{OT1}{XCharter-TLF}{b}{n}%
}

\begin{document}

\begin{equation*}
    a + b = \int_0^{+\infty} \frac{\partial u}{\partial x} \times \alpha' \, \mathrm{d} \boldsymbol{l}
\end{equation*}

\begin{equation*}
    \alpha + \upbeta = \int_0^{+\infty} \frac{\partial \upPi}{\partial \Theta} \times \epsilon' \, \mathrm{d} \boldsymbol{\gamma}
\end{equation*}

\begin{algorithm}[H]
    \SetAlgoLined
    \KwData{this text}
    \KwResult{how to write algorithm with \LaTeXe}
    initialization\;
    \While{not at end of this document}{
    read current\;
    \eIf{understand}{
    go to next section\;
    current section becomes this one\;
    }{
    go back to the beginning of current section\;
    }
    }
    \caption{How to write algorithms}
\end{algorithm}

\end{document}

在此处输入图片描述

相关内容