latex3 / tagging-project

Issues related to the tagging project
https://latex3.github.io/tagging-project/
LaTeX Project Public License v1.3c
23 stars 5 forks source link

Bug tagging glossaries #48

Closed YellowJacketLinux closed 1 month ago

YellowJacketLinux commented 6 months ago

With testphase=phase-III there is some kind of tagging bug when the glossaries package from CTAN is used. The bug only happens after makeglossaries has been run. TeXLive 2023 current. The bug:

! Package tagpdf Error: The number of automatic begin (9) and end (8)
(tagpdf)                text-unit para hooks differ!

For immediate help type H <return>.
 ...                                              

l.33 \end{document}

Minimal example:

\DocumentMetadata{
 uncompress,
 pdfversion=1.7,
 lang=en-US,
 testphase=phase-III
}
\documentclass{article}
\usepackage{fontspec}
\setromanfont{TeX Gyre Termes}
\setmonofont{TeX Gyre Cursor}
\usepackage{glossaries}
\makeglossaries
\newacronym{ce}{\textsc{c.e.}}{Common Era}
\newglossaryentry{vulgate}
{
  name={Latin Vulgate},
  description={foo foo fee foo}
}

\begin{document}
To compile (works with \texttt{testphase=phase-II} but not \texttt{testphase=phase-III}):
\begin{verbatim}
lualatex-dev glossary-bug.tex
makeglossaries glossary-bug
lualatex-dev glossary-bug.tex
lualatex-dev glossary-bug.tex
\end{verbatim}

The \gls{vulgate} is a late fourth century \gls{ce} translation of the Christian Bible.

\printglossary[title=Glossary]

\end{document}
YellowJacketLinux commented 6 months ago

Tagging @nlct who I believe is the maintainer of the glossaries package.

u-fischer commented 6 months ago

This is quite similar to a problem with \printbibliography described here https://github.com/plk/biblatex/issues/1279

glossaries hides the list used to print the glossary inside a group and the \@doenpe needed for the correct tagging of the list can't escape. This can be corrected similar to the biblatex case. Be aware that this changes the indentation of text directly following \printglossary command: similar to text directly after a list it will not be indented anymore. If this is not wanted the code could also use \par\egroup instead.

\DocumentMetadata{
 uncompress,
 pdfversion=1.7,
 lang=en-US,
 testphase=phase-III
}
\documentclass{article}
\usepackage{fontspec}
\setromanfont{TeX Gyre Termes}
\setmonofont{TeX Gyre Cursor}
\usepackage{glossaries}
\makeglossaries
\newacronym{ce}{\textsc{c.e.}}{Common Era}
\newglossaryentry{vulgate}
{
  name={Latin Vulgate},
  description={foo foo fee foo}
}

\makeatletter
\renewcommand{\@printglossary}[2]{%
  \def\@glo@type{\glsdefaulttype}%
  \def\glossarytitle{\csname @glotype@\@glo@type @title\endcsname}%
  \def\glossarytoctitle{\glossarytitle}%
  \let\org@glossarytitle\glossarytitle
  \def\@glossarystyle{%
    \ifx\@glossary@default@style\relax
      \GlossariesWarning{No default glossary style provided \MessageBreak
        for the glossary `\@glo@type'. \MessageBreak
        Using fallback. \MessageBreak
        To fix this set the style with \MessageBreak
        \string\setglossarystyle\space or use the \MessageBreak
        style key=value option}%
    \fi
  }%
  \def\gls@dotoctitle{\glssettoctitle{\@glo@type}}%
  \let\@org@glossaryentrynumbers\glossaryentrynumbers
  \bgroup
   \@printgloss@setsort
   \setkeys{printgloss}{#1}%
   \@printgloss@checkexists{\@glo@type}%
   {%
    \ifx\glossarytitle\org@glossarytitle
    \else
      \expandafter\let\csname @glotype@\@glo@type @title\endcsname
                    \glossarytitle
    \fi
    \let\currentglossary\@glo@type
    \let\org@glossaryentrynumbers\glossaryentrynumbers
    \let\glsnonextpages\@glsnonextpages
    \let\glsnextpages\@glsnextpages
    \let\nopostdesc\@nopostdesc
    \gls@dotoctitle
    \@glossarystyle
    \let\gls@org@glossaryentryfield\glossentry
    \let\gls@org@glossarysubentryfield\subglossentry
    \renewcommand{\glossentry}[1]{%
      \protected@xdef\glscurrententrylabel{\glsdetoklabel{##1}}%
      \gls@org@glossaryentryfield{##1}%
    }%
    \renewcommand{\subglossentry}[2]{%
      \protected@xdef\glscurrententrylabel{\glsdetoklabel{##2}}%
      \gls@org@glossarysubentryfield{##1}{##2}%
    }%
    \@gls@preglossaryhook
    #2%
   }%
  %\egroup %<-----------------old
  \expandafter\egroup\if@endpe\@doendpe\fi %<---------------- new
  \global\let\glossaryentrynumbers\@org@glossaryentrynumbers
  \global\let\warn@noprintglossary\relax
}

\begin{document}
To compile (works with \texttt{testphase=phase-II} but not 
\texttt{testphase=phase-III}): 
\begin{verbatim}
lualatex-dev glossary-bug.tex
makeglossaries glossary-bug
lualatex-dev glossary-bug.tex
lualatex-dev glossary-bug.tex
\end{verbatim}

The \gls{vulgate} is a late fourth century \gls{ce} translation of the 
Christian Bible. 

\printglossary[title=Glossary] 
xxxx %not indented anymore!
\end{document}
nlct commented 6 months ago

Is this specific to the default list style (and those based on it) that uses the description environment or is this fix required for all glossary styles, including the tree, index, multicol and tabular-like styles?

u-fischer commented 6 months ago

@nlct As mentioned in the biblatex issue every LaTeX environment ends with \expandafter\endgroup\if@endpe\@doendpe\fi and so executes if needed \@doendpe. You do not need to care if you have a list inside or not. Above I didn't add the fix to some special style but to the general printing command. If you want to end a glossary with a \par anyway, you could also simply use \par\egroup.

nlct commented 6 months ago

Okay, thanks. I'll fix it after I've finished rewriting datatool.

FrankMittelbach commented 1 month ago

@nlct as far as I can see this has been fixed at your end, correct?

nlct commented 1 month ago

@nlct as far as I can see this has been fixed at your end, correct?

Yes, it should be fixed in glossaries v4.54 (2024-04-03).

FrankMittelbach commented 1 month ago

thanks, in that case we can close it