
Estoy usando el paquete de acentos para colocar una barra debajo de los símbolos matemáticos. Esto funciona muy bien cuando se usa en ecuaciones y también en texto normal (obviamente todavía en el entorno matemático $...$). Sin embargo, actualmente estoy creando una tabla con un título y no quiere compilarse. Preferiblemente no quiero usar \underbar.
MWE
\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}
Primeroerrorcuando uso PDFTeXify en WinEdt 8.0 y MiKTeX 2.9 (de hecho, recibo 100 errores).
! 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.
Respuesta1
El accents
paquete define comandos que no son robustos: por ejemplo encontramos
\newcommand\underaccent[2]{%
\begingroup
\def\cc@a{#2}% Stores the nucleous...
\cc@palette\cc@underaccent{#1}% ...and the accent is passed
#2%
\endgroup}
Un comando como este no sobrevivirá si se encuentra en un "argumento en movimiento" (el argumento de , \caption
y comandos similares). Definir en términos de hace compartir la misma fragilidad.\chapter
\section
\ubar
\underaccent
\ubar
El paquete realmente debería funcionar.
\DeclareRobustCommand\underaccent[2]{%
\begingroup
\def\cc@a{#2}% Stores the nucleous...
\cc@palette\cc@underaccent{#1}% ...and the accent is passed
#2%
\endgroup}
entonces el problema desaparecería.
Hay varias soluciones. El primero es poner \protect
delante del comando cuando aparece en un argumento en movimiento:
\caption{$\protect\ubar{\pi}$}
Una mejor solución sería brindar protección asudominio
\DeclareRobustCommand{\ubar}[1]{\underaccent{\bar}{#1}}
En lugar de usar \newcommand
.
Una solución aún mejor sería solucionar el problema en 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}
En lugar de fixltx2e
puedes usar etoolbox
:
\usepackage{etoolbox}
\usepackage{accents}
\robustify{\underaccent}
haría lo mismo (de otra manera).