
如何在文字模式下使用「舊式」選項以及在數學模式下使用憲章字元(包括數字)來取得憲章?
建議的解決方案需要與 LuaLaTeX 一起使用(因為某些文字字元是非 ASCII 的,我更喜歡將這些非 ASCII 字元貼到原始檔案中,並將來源儲存為 UTF-8)。
編輯:為了以防萬一,我使用 MiKTeX v.2.9。我需要升級才能解決這個問題嗎?
我可以非常接近,但無法立即讓一切正常工作。
微量元素1:
\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{fontspec}
\setmainfont{XCharter} % see https://tex.stackexchange.com/a/205558
\usepackage[oldstyle]{xcharter}
% See https://tex.stackexchange.com/a/347574 for why this is needed.
\AtBeginDocument{%
\Umathcode`0="7 "0 `0
\Umathcode`1="7 "0 `1
\Umathcode`2="7 "0 `2
\Umathcode`3="7 "0 `3
\Umathcode`4="7 "0 `4
\Umathcode`5="7 "0 `5
\Umathcode`6="7 "0 `6
\Umathcode`7="7 "0 `7
\Umathcode`8="7 "0 `8
\Umathcode`9="7 "0 `9
}
\usepackage[charter]{newtxmath}
\begin{document}
Digits in plain text: 48/96=135/270.
$a=48, b=96, c=135, d=270\implies a/b=c/d.$ $8=5+3=9-1=2\times4=2^3.$
\end{document}
文字模式下的數字正是我想要的。此外,數學模式下的字母是憲章斜體,這是我想要的。然而,數學模式下的數字是計算機現代的,儘管我嘗試在這個答案,它回答了有關 Libertine 的類似問題。
兆瓦2
\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{fontspec}
\setmainfont{XCharter}[Numbers={OldStyle}] % see https://tex.stackexchange.com/a/205558
\usepackage[charter]{newtxmath}
% See https://tex.stackexchange.com/a/347574 for why this is needed.
\AtBeginDocument{%
\Umathcode`0="7 "0 `0
\Umathcode`1="7 "0 `1
\Umathcode`2="7 "0 `2
\Umathcode`3="7 "0 `3
\Umathcode`4="7 "0 `4
\Umathcode`5="7 "0 `5
\Umathcode`6="7 "0 `6
\Umathcode`7="7 "0 `7
\Umathcode`8="7 "0 `8
\Umathcode`9="7 "0 `9
}
\begin{document}
Digits in plain text: 48/96=135/270.
$a=48, b=96, c=135, d=270\implies ab=cd.$ $8=5+3=9-1=2\times4=2^3.$
\end{document}
現在我嘗試透過破解 \setmainfont 而不是 \usepackage{xcharter} 來在文字模式下取得舊式數字。但這似乎將參數oldstyleI(而非oldstyle)傳遞給\usepackage{xcharter}。不管怎樣,結果是文字模式有舊式數字,但小寫字母 I 代表 1。
如果文字和數學模式都可以使用舊式憲章數字,那就更好了。這樣我就可以將表格保留為數學模式下的陣列環境。必須進入表格中數字的文字模式需要將 例如 替換$\begin{array}{r} n \\ 1 \end{array}$
為\begin{tabular}{r} $n$ \\ 1 \end{tabular}
。
答案1
由於您使用的是 LuaLaTeX,因此您可以加載unicode-math
而不是newtxmath
,這存在相容性問題。使用 XCharter-Math 字體進行數學計算。
編輯:在註解中,您請求來自 的數字 1 [oldstyleI]
,它是 XCharter 的 OpenType 版本中的字元變體 01。修訂版本如下。
\documentclass[12pt,a4paper]{article}
\usepackage{unicode-math}
\defaultfontfeatures[XCharter]{ Numbers=OldStyle,
CharacterVariant=1, % Change the shape of 1 in text mode
UprightFont=*-Roman,
BoldFont=*-Bold,
ItalicFont=*-Italic,
SlantedFont=*-Slanted,
BoldItalicFont=*-BoldItalic,
BoldSlantedFont=*-BoldSlanted,
Extension=.otf }
\setmainfont{XCharter}
\setmathfont{XCharter-Math}
\begin{document}
Digits in plain text: 48/96=135/270.
$a=48, b=96, c=135, d=270\implies ab=cd.$ $8=5+3=9-1=2\times4=2^3.$
\end{document}
萬一您也想在數學模式下使用舊式數字,您可以新增以下指令:
\setmathfont{XCharter-Roman.otf}[range={up/num},
Numbers=OldStyle,
CharacterVariant=01] % Change the shape of 1 in math mode
這是一個在 PDFLaTeX 中運行的版本:
\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage[charter]{mathdesign}
\usepackage[oldstyle]{xcharter}
\begin{document}
Digits in plain text: 48/96=135/270.
$a=48, b=96, c=135, d=270\implies ab=cd.$ $8=5+3=9-1=2\times4=2^3.$
\end{document}
我建議您unicode-math
盡可能使用 LuaLaTeX,並在必要時使用帶有傳統 8 位元字體的 PDFLaTeX。但是,既然您說這裡的問題是無法讀取 Unicode,那麼如果您將文件儲存為 NFC(標準化預先組合)UTF-8 編碼,那麼您的文件很有可能可以正常工作。 PDFLaTeX 無法理解 Unicode 組合字符,但可以處理直接對應到 8 位元輸入編碼的任何 Unicode 字元。
編輯:
如果您確實想將 OpenType 文字字體與舊版 Type 1 數學字體一起使用,那麼這應該可行:
\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage[charter]{mathdesign}
\usepackage{fontspec}
\setmainfont{XCharter}[NFSSFamily=mdbch, Numbers=OldStyle]
\begin{document}
Digits in plain text: 48/96=135/270.
$a=48, b=96, c=135, d=270\implies ab=cd.$ $8=5+3=9-1=2\times4=2^3.$
\end{document}
答案2
如果您不想使用unicode-math
,則必須重新定義operators
字體才能使用帶有襯線數字的 XCharter。
\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{fontspec}
\usepackage[charter]{newtxmath}
\setmainfont{XCharter}[Numbers={OldStyle}] % see https://tex.stackexchange.com/a/205558
\newfontfamily{\XCharterLF}{XCharter}[NFSSFamily=xcharterlf]
\DeclareSymbolFont{operators}{TU}{xcharterlf}{m}{n}
\begin{document}
Digits in plain text: 48/96=135/270.
$a=48, b=96, c=135, d=270\implies ab=cd$.
$8=5+3=9-1=2\times4=2^3$.
$\sin x$
\end{document}