以下是我遇到的問題的 MWE:
\documentclass{article}
\usepackage{hyperref}
\usepackage{unicode-math}
\setmathfont{Asana Math}
\begin{document}
\section{$2\times 2$}
$2 \times 2$
\end{document}
當使用 xelatex 編譯它時,出現以下錯誤:
! Improper alphabetic constant.
<to be read again>
\times
l.7 \section{$2\times 2$}
但是如果我刪除 hyperref 套件的包含,錯誤就會消失。
現在顯然我希望能夠在節標題中使用數學,並且使用 pdflatex 編譯效果很好(除了 hyperref 對書籤中數學的抱怨,這可以通過其他方式修復)。
那我對 xelatex 做錯了什麼嗎?
答案1
烏爾里克答案的更新。
使用 hyperref 2012/08/13 v6.83a 您可以將選項unicode
(或pdfencoding=auto
)與選項一起使用psdextra
:
\usepackage[unicode,psdextra]{hyperref}[2012/08/13]
然後可以識別包括在內的許多數學符號\times
。
答案2
您可以用來\texorpdfstring
告訴 hyperref 使用其他文字作為書籤:
\documentclass{article}
\usepackage{hyperref}
\usepackage{unicode-math}
\setmathfont{Asana Math}
\begin{document}
\section{\texorpdfstring{$2\times 2$}{2\texttimes2}}
$2 \times 2$
\end{document}