
我使用 lualatex 和 fontspec 以一種字體排版數學方程,並以另一種字體排版文字。在測試過程中,我發現排版文件中的數學看起來並不像我在網路上看到的一些樣本那麼好。經過進一步調查,我發現即使為數學選擇的字體(使用)具有所需的字形(如小寫“d”),lualatex 也會通過用在!\setmathfont
時加載的羅馬字體替換其中一些字形來組成數學。\setmathfont
請看下面兩張圖片中的小寫「d」。第一個是用「TeX Gyre Pagella Math」字體編譯數學,並使用預設字體(Latin Modern)作為主要文字。第二個是用“TeX Gyre Pagella Math”編譯的,數學部分是“TeX Gyre Pagella”,正文是“TeX Gyre Pagella”。附帶說明一下,我已經開始使用 Cambria Math 進行測試,它也有相同的問題。所以絕對不是字體相關的問題。
首先(沒有 TeX Gyre Pagella 作為正文,小寫「d」來自拉丁現代,其餘字形不是)
第二(以 TeX Gyre Pagella 為正文,小寫「d」可能來自 TeX Gyre Pagella 而不是來自 TeX Gyre Pagella Math;因為它們是相同的方程式看起來很好)
完整程式碼(請先閱讀註解\setmathfont
以了解如何重新產生這兩種情況):
% >> lualatex testmathfont.tex
\documentclass[notitlepage,letterpaper]{article}
%\usepackage{lua-visual-debug}
\usepackage[absolute]{textpos}
\usepackage[letterpaper,left=2in,right=2in,top=1in,bottom=0in]{geometry}
\usepackage[expansion=alltext,shrink=20,stretch=20]{microtype}
\usepackage{fontspec}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{unicode-math}
% NOTE:: Compile 1: keep following line commented, Compile 2: uncomment following line
%\setmainfont{TeX Gyre Pagella}
\setmathfont{TeX Gyre Pagella Math}
\usepackage{blindtext}
\begin{document}
\blindtext[1]\vspace*{\baselineskip}
$\displaystyle\int_a^b x^2\;\mathrm{d}x= \tfrac{1}{3} x^3 \Big|_a^b$\vspace*{\baselineskip}
\blindtext[1]\vspace*{\baselineskip}
$a_0+\cfrac{1}{a_1+\cfrac{1}{a_2+\cfrac{1}{a_3+\cdots}}}$\vspace*{\baselineskip}
\end{document}