3

Basically what the title says: when I call an acronym for the first time in the document, and this happens to be in the tabu/longtabu environment, the acronym does not expand. Any ideas how to resolve this issue?

Here's a MWE:

\documentclass[]{article}
\usepackage{booktabs}
\usepackage{tabu}
\usepackage{longtable}
\usepackage[]{acronym}

\begin{document}

\acrodef{EIA}[EIA]{United States Energy Information Administration}

\begin{longtabu} to 0.9\linewidth{lX}
\toprule 
\textbf{Some header}  &  \\
\midrule 
\endfirsthead\\
\toprule
\textbf{Some header} \\
\midrule
\endhead
\bottomrule\\
\endfoot
\bottomrule
\endlastfoot
\ac{EIA} \\
\end{longtabu}

\acresetall

\begin{table}[htbp]
\begin{tabu} to 0.9\linewidth{lX}
\toprule
\ac{EIA} \\
\bottomrule 
\end{tabu}
\end{table}

\end{document}
Tobias
  • 107
  • The obvious suspect is the fact that tabu does two (or more) passes over the material, so the first pass marks the acronym as used. – egreg Feb 03 '16 at 18:32
  • Is there any solution to this? Or can an acronym just simply not be introduced in (long)tabu environments? – Tobias Feb 03 '16 at 18:36
  • this has come up before I'll see if I can find.... – David Carlisle Feb 03 '16 at 20:22
  • 1
    the tabu code is based on tabularx and the solution for tabularx is here http://tex.stackexchange.com/questions/94885/glossaries-fail-to-expand-in-tabularx/94895#94895 something similar will work although the exact test to detect the final run may be different (or you could use tabularx:-) – David Carlisle Feb 03 '16 at 20:24
  • @DavidCarlisle thanks for the link. That solution does not work for (long)tabu though, and unfortunately my Latex-skills are not good enough to modify the provided code. Would you mind helping me out? – Tobias Feb 04 '16 at 07:31
  • Wanted to bump this before we all forget about it and I manually insert the acronyms :) – Tobias Feb 10 '16 at 12:04

1 Answers1

2

tabu's tables need to measure the contents of a table before typesetting it. During this process the acronym already gets used. If this happens to be the first time for the acronym then this never gets printed because from the view of the typesetting phase the acronym already has been used (namely in the measuring phase).

However, tabu offers the command \tabuDisableCommands{<code>} to add <code> for the measuring phase exactly for such cases. In our case we need to redefine \@ac (the internal version of \ac) temporarily in a way that it resets the acronym if it is used for the first time during the measuring phase:

\makeatletter
\tabuDisableCommands{
  \renewcommand{\@ac}[1]{%
    \ifAC@dua
      \ifAC@starred\acl*{#1}\else\acl{#1}\fi
    \else
      \expandafter\ifx\csname AC@#1\endcsname\AC@used
        \ifAC@starred\acs*{#1}\else\acs{#1}\fi
      \else
        \ifAC@starred\acf*{#1}\else\acf{#1}\fi
        \AC@reset{#1}% <<< this is added to the original definition
      \fi
    \fi
  }
}
\makeatother

Complete example:

\documentclass[]{article}
\usepackage{booktabs}
\usepackage{tabu}
\usepackage{longtable}
\usepackage[]{acronym}

\acrodef{EIA}[EIA]{United States Energy Information Administration}

\makeatletter
\tabuDisableCommands{
  \renewcommand{\@ac}[1]{%
    \ifAC@dua
      \ifAC@starred\acl*{#1}\else\acl{#1}\fi
    \else
      \expandafter\ifx\csname AC@#1\endcsname\AC@used
        \ifAC@starred\acs*{#1}\else\acs{#1}\fi
      \else
        \ifAC@starred\acf*{#1}\else\acf{#1}\fi
        \AC@reset{#1}% <<< this is added to the original definition
      \fi
    \fi
  }
}
\makeatother

\begin{document}

\begin{longtabu} to 0.9\linewidth{lX}
\toprule 
\textbf{Some header}  &  \\
\midrule 
\endfirsthead\\
\toprule
\textbf{Some header} \\
\midrule
\endhead
\bottomrule\\
\endfoot
\bottomrule
\endlastfoot
\ac{EIA} \\
\ac{EIA} \\
\end{longtabu}

\acresetall

\begin{table}[htbp]
\begin{tabu} to 0.9\linewidth{lX}
\toprule
\ac{EIA} \\
\ac{EIA} \\
\bottomrule 
\end{tabu}
\end{table}

\end{document}

enter image description here

cgnieder
  • 66,645