bib2gls icon indicating copy to clipboard operation
bib2gls copied to clipboard

Duplicate entries in navigation menu of custom glossaries

Open amartos opened this issue 1 year ago • 3 comments

Hi.

Using *hypergroup styles, there are no issues if the TeX file is compiled once after calling bib2gls file, but compiling it twice duplicates all navigation menus for the custom glossaries. I tested:

  • compiling with pdflatex, xelatex, lualatex
  • styles indexhypergroup, altlisthypergroup, treehypergroup
  • with and without the main glossary (note: the main glossary is strangely not affected by this)
  • using one bib file with and without defined types, multiple bib files with and without types

The only workaround I found is to comment out the \bibglshypergroup command calls in the *.glstex files. Without this call, the pdf outputs are as expected, after one or two compilations.

I tested this with the latest version of bib2gls (3.6), although my texlive version is a little bit older (I'm on Debian, the repos bib2gls version is 3.3). I don't know if it matters.

Attached is a tar archive containing the setup + result files for some tests (with/without the main glossary, with/without the fix, and compiled once or twice). All compilation files (i.e. including the *.glstex and *.aux files) were removed before each test. I also attached a problematic pdf output (which is also in the tar archive). Here are the base files I used for these:

The TeX MWE file.

\documentclass{article}
\usepackage{hyperref}
\usepackage[
  record,
  nomain, % commented out for the "main" tests
  style=treehypergroup, % the issue is there for list and index hypergroups too
  debug=showtargets
]{glossaries-extra}
\newglossary*{words}{Words}
%% \GlsXtrLoadResources[src={test},selection={all}] % uncommented for the "main" tests
\GlsXtrLoadResources[src={test2},type={words},selection={all}]
\begin{document}
\printunsrtglossaries
\end{document}

The glossary bib file used for the "main" glossary.

@acronym{abc,%
  short={abc},%
  long={ABCDEF},%
  description={A bunch of letters.},%
}

@entry{def,%
  name={defghi},%
  description={A bunch of numbers.},%
}

The bib file for the custom glossary ("words" here).

@acronym{ghi,%
  short={ghi},%
  long={GHIJKL},%
  description={A bunch of letters.},%
}

@entry{abcdef,%
  name={abcdef},%
  description={A bunch of letters.},%
}

The compilation script.

#!/usr/bin/env bash

pdflatex test.tex
pdflatex test.tex

bib2gls --group --trim-fields test

pdflatex test.tex

[ ! -z $BIB2GLSFIX ] && sed -i 's+^\\bibglshypergroup{+%% \\bibglshypergroup{+g' *.glstex
[ ! -z $1 ] && pdflatex test.tex

The workaround I found.

diff --git a/nomain/nofix/twice/test.glstex b/nomain/fix/twice/test.glstex
index 5e66bbb..92ca01f 100644
--- a/nomain/nofix/twice/test.glstex
+++ b/nomain/fix/twice/test.glstex
@@ -1,4 +1,4 @@
-% This file was created by bib2gls v3.6 on 28/09/2023 19:59.
+% This file was created by bib2gls v3.6 on 28/09/2023 20:02.
 % DO NOT edit this file. Any changes made will be lost next time bib2gls is run.
 % This file was generated from data obtained from the following files:
 % test.aux and test2.bib
@@ -93,7 +93,7 @@
   \providecommand{\bibglshypergroup}[2]{}
 }
 \providecommand*{\bibglsflattenedhomograph}[2]{#1}
-\bibglshypergroup{words}{\bibglslettergroup{A}{a}{5373952}{words}}
+%% \bibglshypergroup{words}{\bibglslettergroup{A}{a}{5373952}{words}}
 
 \providecommand{\bibglsnewentry}[4]{%
  \longnewglossaryentry*{#1}{name={#3},#2}{#4}%
@@ -107,7 +107,7 @@ group={\bibglslettergroup{A}{a}{5373952}{words}}}%
 {A bunch of letters.}


-\bibglshypergroup{words}{\bibglslettergroup{G}{g}{5832704}{words}}
+%% \bibglshypergroup{words}{\bibglslettergroup{G}{g}{5832704}{words}}
 
 \providecommand{\bibglsnewacronym}[4]{%
   \newacronym[#2]{#1}{#3}{#4}%

test.pdf tests.tar.gz

amartos avatar Sep 28 '23 18:09 amartos

It looks like the default behaviour provided by glossary-hypernav isn't being correctly disabled, so both methods are being implemented. I'll investigate.

For a workaround, you don't need to edit the .glstex file. Just define \bibglshypergroup to do nothing before \GlsXtrLoadResources:

\newcommand{\bibglshypergroup}[2]{}
\GlsXtrLoadResources[src={test2},type={words},selection={all}]

nlct avatar Sep 29 '23 09:09 nlct

\newcommand{\bibglshypergroup}[2]{}
\GlsXtrLoadResources[src={test2},type={words},selection={all}]

Indeed, I missed that possibility, that'll simplify my setup. Thank you.

amartos avatar Sep 29 '23 09:09 amartos

I've fixed glossary-hypernav.sty bundled with glossaries v4.53 so that it doesn't add duplicate labels, but since glossaries-extra modifies some of the affected commands, I've also updated glossaries-extra otherwise there will be a conflict. So you need to upgrade to both glossaries v4.53 and glossaries-extra v1.53. (It may take a few days for the updates to reach the TeX distributions.)

I've also updated bib2gls (version 3.7) so that it checks the version numbers of glossaries and glossaries-extra. If they are both older than 2023-09-29 then bib2gls will simply write the no-op definition:

\providecommand{\bibglshypergroup}[2]{}

This means the document build will require LaTeX + bib2gls + LaTeX + LaTeX.

If both new versions are available then bib2gls will provide the definition:

\providecommand{\bibglshypergroup}[2]{\ifstrempty{#1}{}{\@gls@hypergroup{#1}{#2}}}

The first argument is the glossary label identified by the type option in \GlsXtrLoadResources. If that option isn't used, then bib2gls doesn't know which glossary the entries will end up in, in which case it will act like the no-op case. (This is why your example with the main glossary wasn't affected by the bug.) If the type option is used, then bib2gls knows which is the relevant glossary and can set the hypergroup information as it reads the .glstex file. This means that the document build only requires LaTeX + bib2gls + LaTeX (which can save time for a large document, but only if there isn't anything unrelated that may require extra LaTeX runs).

nlct avatar Oct 01 '23 20:10 nlct