6

When I use an acronym (glossaries or acronym package) for the first time in tabularx, then it fails to expand, and even breaks down the table structure. The problem is already mentioned here, but there is no straightforward solution provided.

The problem does not appear with \acf, \acs or other commands that do not check for the first time usage of the entry. However, it is not a solution, as the whole idea of this package is automatic checking. I am looking for a simple solution with not too much processing overhead, as I have thousands of \ac commands in my text.

Sample code:

\documentclass{article}
\usepackage[acronym,shortcuts]{glossaries} 
\usepackage{tabularx}
\newacronym{BI}{BI}{Beacon Interval}

\begin{document}

\begin{tabularx}{\textwidth}{|l|X|}
Parameter & Value \\ \hline
\ac{BI}  & Typical: 0.1 seconds. I heard somebody say, that the sentence ended here, But everyone knows it's goin' still. \\
\end{tabularx}

\bigskip

\begin{tabularx}{\textwidth}{|l|X|}
Parameter & Value \\ \hline
\ac{BI}  & Typical: 0.1 seconds. I heard somebody say, that the sentence ended here, But everyone knows it's goin' still. \\
\end{tabularx}

\end{document}
David Carlisle
  • 757,742
Aydin
  • 1,983
  • 1
    Could you make your snippet of code into a complete minimal working example (MWE)? – egreg Jan 22 '13 at 17:19
  • I just tried it using the acronym package. Works fine with tabular. Sadly, this does not work correctly with tabularx, too. – Rico Jan 22 '13 at 17:19
  • 1
    I changed it to a complete MWE. – Aydin Jan 23 '13 at 13:23
  • 1
    I don't think it's a good idea that an acronym appears for the first time in the tabular. The obvious problem is that tabularx makes two passes over the material, so on the first pass it expands the "new" acronym, but on the second pass the acronym has been marked as "already seen" and so not expanded any more. – egreg Jan 23 '13 at 13:44
  • @egreg, I agree, and try to avoid such an occasion. However, the procedure is somewhat automatic. I have a long text full of acronyms. If I remove a paragraph (that has an acronym) from an early chapter, then the acronym may appear somewhere else for its first time. I don't want to end up with unpredictable layout issues when there is no time to review the whole document. – Aydin Jan 25 '13 at 16:20

3 Answers3

9

enter image description here

\documentclass{article}
\usepackage[acronym,shortcuts]{glossaries} 
\usepackage{tabularx}
\newacronym{BI}{BI}{Beacon Interval}
\makeatletter


\def\foo#1\hbox#2#3!!{%
\def\TX@trial##1{#1\hbox{\let\glsunset\@gobble#2}#3}%
}
\expandafter\foo\TX@trial{#1}!!
\makeatother
\begin{document}


\noindent X \dotfill X

\noindent
\begin{tabularx}{\textwidth}{|l|X|}
Parameter & Value \\ \hline
\ac{BI}  & Typical: 0.1 seconds. I heard somebody say, that the sentence ended here, But everyone knows it's goin' still. \\
\end{tabularx}

\bigskip

\noindent
\begin{tabularx}{\textwidth}{|l|X|}
Parameter & Value \\ \hline
\ac{BI}  & Typical: 0.1 seconds. I heard somebody say, that the sentence ended here, But everyone knows it's goin' still. \\
\end{tabularx}

\noindent X \dotfill X

\end{document}
David Carlisle
  • 757,742
5

Following on from David's answer, version 4.28 (2017-01-07) of glossaries now has a command \glspatchtabularx that does David's patch without the need for \makeatletter:

\documentclass{article}
\usepackage[acronym,shortcuts]{glossaries}
\usepackage{tabularx}
\newacronym{BI}{BI}{Beacon Interval}

\glspatchtabularx

\begin{document}


\noindent X \dotfill X

\noindent
\begin{tabularx}{\textwidth}{|l|X|}
Parameter & Value \\ \hline
\ac{BI}  & Typical: 0.1 seconds. I heard somebody say, that the
sentence ended here, But everyone knows it's goin' still. \
\end{tabularx}

\bigskip

\noindent
\begin{tabularx}{\textwidth}{|l|X|}
Parameter & Value \\ \hline
\ac{BI}  & Typical: 0.1 seconds. I heard somebody say, that the
sentence ended here, But everyone knows it's goin' still. \
\end{tabularx}

\noindent X \dotfill X

\end{document}

It will do nothing if tabularx hasn't been loaded.

Nicola Talbot
  • 41,153
0

I know this is old, and already made upstream, but I think I have an alternative solution which might not need to patch tabularx. The idea is that tabularx performs a number of trials before typesetting the table, but when they are over, before the final step, \@footnotetext is let to \TX@ftntext, and this assignment could be used to identify the trials are over:

\documentclass{article}
\usepackage[acronym,shortcuts]{glossaries}
\usepackage{tabularx}
\newacronym{BI}{BI}{Beacon Interval}
\makeatletter
\renewcommand*{\glsunset}[1]{%
  \ifx\@footnotetext\TX@ftntext
    \gls@ifnotmeasuring
    {%
      \glsdoifexists{#1}%
      {%
        \@glsunset{#1}%
      }%
    }%
  \fi
}
\makeatother
\begin{document}

\noindent X \dotfill X

\noindent \begin{tabularx}{\textwidth}{|l|X|} Parameter & Value \ \hline \ac{BI} & Typical: 0.1 seconds. I heard somebody say, that the sentence ended here, But everyone knows it's goin' still. \ \end{tabularx}

\bigskip

\noindent \begin{tabularx}{\textwidth}{|l|X|} Parameter & Value \ \hline \ac{BI} & Typical: 0.1 seconds. I heard somebody say, that the sentence ended here, But everyone knows it's goin' still. \ \end{tabularx}

\noindent X \dotfill X

\end{document}

Of course, this is just "proof of concept", but if this check is indeed solid for the situation, it would not be difficult to provide something similar to \gls@ifnotmeasuring based on it.

gusbrs
  • 13,740
  • 1
    yes I think I have a comment in an issue somewhere that I should have provided an \ifTX@... test for that, see also here or more generally here I think I patched TX in my original answer just so I only needed to touch my code rather than patch glossaries in code I didn't know to add a test. I didn't know that glossaries now does that patch... – David Carlisle Apr 08 '22 at 07:47
  • Oh! There are other similar assignments then that could be used. Well, a formal test like the amsmath's \ifmeasuring@ would be nice, of course. And glossaries does not patch by default, but users can enable the patch. Problem there is if more people (packages, that is) need it. As things currently stand, is there any reason to prefer one or other or these assignments to identify the final pass? – gusbrs Apr 08 '22 at 09:55
  • 1
    Not really, as you see in the code I made (a long long time ago) some random set of functions safe (or quiet) while doing the tests. Just pick one, I should add a newif token there I think (perhaps I should not have an @ so you can use it in documents \ifTXfinal \typeout{helllo}\fi ?? One issue I never had a good answer to is what the calling package (or document) should do in the trial case. It is easy to avoid errors by doing "nothing" but if that changes the effective width of the column it means the trials are broken and won't necessarily end up with widths that work on the final pass – David Carlisle Apr 08 '22 at 10:12
  • Ok, thanks! I guess I'll use the \savedwrite/\write one for being a little more semantic. Regarding what to do in the trial passes, it is difficult, and I guess depends on the case. In my case at the moment, I'm working with end notes, so what I do is add a "dumb" mark to take the space of what will be typeset in the final pass, so that the measurement is not tripped, but refrain from doing other operations, like adding the note to the "queue" sequence, not to get duplicated notes later on. – gusbrs Apr 08 '22 at 10:28