アクセントパッケージを使用する場合: 表のキャプションのギリシャ語記号がアクセントの下にくるとエラーが発生します

アクセントパッケージを使用する場合: 表のキャプションのギリシャ語記号がアクセントの下にくるとエラーが発生します

私はアクセント パッケージを使用して、数式記号の下にバーを配置しています。これは、方程式で使用する場合や、通常のテキストで使用する場合 (明らかに、数式環境 $...$ 内) では非常にうまく機能します。ただし、現在、キャプション付きの表を作成していますが、コンパイルされません。\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}

同じことを(別の方法で)行うでしょう。

関連情報