使用accents套件時:表格標題中的低重音希臘符號會出現錯誤

使用accents套件時:表格標題中的低重音希臘符號會出現錯誤

我正在使用 Acces 包在數學符號下放置一個橫線。當在方程式中使用它時,以及在普通文本中(顯然仍然在數學環境 $...$ 中)時,這非常有效。但是,目前我正在創建一個帶有標題的表格,但它不想編譯。我最好不想使用 \underbar。


微量元素

\documentclass{article}

\usepackage{accents}
\newcommand{\ubar}[1]{\underaccent{\bar}{#1}}

\begin{document}

\begin{table}
\begin{tabular}{c}
a
\end{tabular}
\caption{$\ubar{\pi}$}
\end{table}

\end{document}

第一的錯誤在 WinEdt 8.0 和 MiKTeX 2.9 中使用 PDFTeXify 時(我實際上收到了 100 個錯誤)。

! Undefined control sequence.
\underaccent #1#2->\begingroup \def \cc@a
                                           {#2}\cc@palette \cc@underaccent {#...
1.12 \caption{$\ubar{\pi}$}

The control sequence at the end of the top line 
of your error message was never \def'ed. If you have 
misspelled it (e.g. `\hobx'), type `I' and the correct 
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

答案1

accents套件定義的命令並不健壯:例如我們發現

\newcommand\underaccent[2]{%
  \begingroup
    \def\cc@a{#2}% Stores the nucleous...
    \cc@palette\cc@underaccent{#1}% ...and the accent is passed
    #2%
  \endgroup}

像這樣的命令將無法在「移動參數」(\caption\chapter\section類似命令的參數)中找到。用術語\ubar來定義也具有同樣的脆弱性。\underaccent\ubar

這個包確實應該要做

\DeclareRobustCommand\underaccent[2]{%
  \begingroup
    \def\cc@a{#2}% Stores the nucleous...
    \cc@palette\cc@underaccent{#1}% ...and the accent is passed
    #2%
  \endgroup}

這樣問題就會消失。

有各種修復方法。第一個是\protect當指令出現在移動參數時放在指令前面:

\caption{$\protect\ubar{\pi}$}

更好的解決方法是提供保護你的命令

\DeclareRobustCommand{\ubar}[1]{\underaccent{\bar}{#1}}

而不是使用\newcommand.

更好的解決方法是修復以下故障accents

\documentclass{article}
\usepackage{fixltx2e}

\usepackage{accents}

\MakeRobust{\underaccent} % make \underaccent not fragile in moving arguments

\newcommand{\ubar}[1]{\underaccent{\bar}{#1}}

\begin{document}
\begin{figure}
\caption{$\ubar{\pi}$}
\end{figure}
\end{document}

您可以fixltx2e使用etoolbox

\usepackage{etoolbox}

\usepackage{accents}
\robustify{\underaccent}

會做同樣的事情(以不同的方式)。

相關內容