希臘文標題中的字母常數錯誤:LuaLaTeX 中 unicode-math 和 hyperref 的錯誤

希臘文標題中的字母常數錯誤:LuaLaTeX 中 unicode-math 和 hyperref 的錯誤

unicode-math這是或hyperref中的錯誤嗎LuaLaTeX

    % !TeX program = lualatex                                   
    % !TeX encoding = utf8
    
    \documentclass[14pt]{extarticle}
    
    \usepackage{fontspec}
    \usepackage{amsmath}
    \setsansfont{CMU Sans Serif}
    \setmainfont{CMU Serif}
    \setmonofont{CMU Typewriter Text}
    \usepackage{unicode-math} % this one DOES NOT cause error without hyperref
    \usepackage[english]{babel}
    \usepackage{hyperref} % this one DOES NOT cause error without unicode-math
    
    
    \begin{document}
    
    \section{title $\alpha$}
    
    \end{document}

我收到一個錯誤

不正確的字母常數。 \section{標題$\alpha$}

答案1

書籤只能包含相當簡單的文字。這意味著 hyperref 必須將 LaTeX 輸入轉換為有意義的內容。為此,它經常刪除或替換有問題的內容。一般來說,hyperref 非常好,至少可以避免此過程中的錯誤,但它無法處理已傳遞給 char 的命令:https://github.com/latex3/hyperref/issues/63。遺憾的是 unicode-math 在很多地方都這麼做了。

您可以使用\texorpdfstringhyperref 提供替代方案。例如,直接 unicode char U+1D6FC 適用於大多數 pdf 讀取器。可以直接輸入,也可以用^^符號輸入:

\documentclass[14pt]{extarticle}

    \usepackage{fontspec}
    \usepackage{amsmath}
    \setsansfont{CMU Sans Serif}
    \setmainfont{CMU Serif}
    \setmonofont{CMU Typewriter Text}
    \usepackage{unicode-math} % 
    \usepackage[english]{babel}
    \usepackage{hyperref} % 


    \begin{document}

    \section{title \texorpdfstring{$\alpha$}{

答案2

我相信您在指定 pdf 書籤的方式上遇到了一個基本缺點,而不是以下任一方面的unicode-math缺點hyperref 本身

\texorpdfstring裝置可以用來解決這個缺點。例如,在 LuaLaTeX 下,

\section{title \texorpdfstring{$\alpha$}{$\symit{alpha}$}}

將導致title alpha(注意:不是 title α) 顯示在書籤中。

在旁邊:即使x03B1Unicode 表中的插槽指向 α 並且 CMU Serif 字體在該插槽中具有正確的符號,

\section{title \texorpdfstring{$\alpha$}{\symbol{"03B1}}}

根本不起作用,正如書籤現在所說的那樣title "03B1。這肯定遠遠不如人意title alpha,不是嗎? (這也是為什麼我之前認為書籤的形成方式存在根本問題的原因。)

這個故事的寓意是什麼?也許,人們應該避免在顯示為 pdf 書籤的命令參數中使用數學模式希臘字母。

相關內容