# customization of glossaries

This is a follow up to this question.

As in the aforementioned question I have multiple files, actually 3. All of them have to share the same glossaries. With the answer and comments of the last question it is possible to have a satisfactory solution for 2 files. But as @NicolaTalbot said it is more difficult with 3 files.

So suppose I have 3 files: fileA.tex, fileB.tex and fileC.tex, and also a glossary entry

@entry{sample,
name = {an example}
}


This glossary entry appears in the 3 files and I don't know if is possible a customization of the glossary such that:

if the entry appears in page 1 in fileA.pdf, in page 1 in fileB.pdf and in page 5 in fileC.pdf, then the outputs looks like:

fileA.pdf

sample 1, B-1, C-5

fileB.pdf

sample A-1, 1, C-5

fileC.pdf

sample A-1, B-1, 5

As I said, I don't know if this kind of customization is possible, but any answer (affirmative or negative) would be appreciated.

You need at least glossaries-extra version 1.36 and bib2gls version 1.7.

File entries.bib contains:

@entry{sample,
name={sample},
description={an example}
}


or (if you don't want a description) just:

@index{sample}


File test-supp1.tex:

\documentclass{report}

\usepackage[record % requires bib2gls
]{glossaries-extra}

src={entries}% entries defined in entries.bib
]

\begin{document}
\tableofcontents

\chapter{Sample}
\gls{sample}.

\chapter{Another Sample}
\gls{sample}.

\printunsrtglossaries
\end{document}


Document build:

pdflatex test-supp1
bib2gls -g test-supp1
pdflatex test-supp1


The entry has two locations (page 2 and 3):

File test-supp2.tex:

\documentclass{report}

\usepackage[record % requires bib2gls
]{glossaries-extra}

src={entries}% entries defined in entries.bib
]

\begin{document}
\chapter{Sample}
\gls{sample}.

\chapter{Another Sample}
\gls{sample}.

\printunsrtglossaries
\end{document}


Document build:

pdflatex test-supp2
bib2gls -g test-supp2
pdflatex test-supp2


The locations in this case are page 1 and 2.

Main document test.tex that also needs the locations from the supplementary documents test-supp1.tex and test-supp2.tex:

\documentclass{book}

\usepackage[record % using bib2gls
]{glossaries-extra}

src={entries}, % data in entries.bib
% requires glossaries-extra v1.36 and bib2gls v1.7:
% include locations from supplementary documents obtained from
% test-supp1.aux and test-supp2.aux
supplemental-locations={test-supp1,test-supp2},
]

\begin{document}
\frontmatter

\chapter{Foreword}
\gls{sample}.

\mainmatter

\chapter{Sample}

\gls{sample}.

\chapter{Another}
Nothing to see here.

\chapter{And Another}
\gls{sample}

\printunsrtglossaries

\end{document}


The location list is now: i (Foreword), 1 (Chapter 1), 5 (Chapter 3), 2 (test-supp1.pdf), 3 (test-supp1.pdf), 1 (test-supp2.pdf) and 2 (test-supp2.pdf). It's not very clear which belongs to which document, except that internal links are red and external links are cyan.

(Not all PDF viewers fully support external links, so the links may just take you to the first page of the linked document.)

The separator between the internal list and the external list(s) is given by \bibglssupplementalsep. (It's omitted if the internal list is missing.)

The external lists are encapsulated in a single \bibglssupplemental{n}{sub-lists} where n is the total number of external locations (4 in this case).

Each sub-list is separated with \bibglssupplementalsubsep and each sub-list is encapsulated with \bibglssupplementalsublist{n}{document}{locations} where n is the total number of locations in the sub-list and document is the external document. The sub-lists are always in the same order as listed in supplemental-locations.

These commands are all provided in the .glstex file created by bib2gls so you need to defined them with \newcommand before \GlsXtrLoadResources to override the defaults.

For example:

\documentclass{book}

\usepackage[record % using bib2gls
]{glossaries-extra}

\newcommand{\bibglssupplementalsep}{.}
\newcommand{\bibglssupplementalsubsep}{; }

\newcommand{\bibglssupplemental}[2]{%
\par
\ifnum#1=1
External reference:
\else
External references:
\fi
#2.%
}

\newcommand{\bibglssupplementalsublist}[3]{%
#2: #3%
}

src={entries}, % data in entries.bib
% requires glossaries-extra v1.36 and bib2gls v1.7:
% include locations from supplementary documents obtained from
% test-supp1.aux and test-supp2.aux
supplemental-locations={test-supp1,test-supp2},
]

\begin{document}
\frontmatter

\chapter{Foreword}
\gls{sample}.

\mainmatter

\chapter{Sample}

\gls{sample}.

\chapter{Another}
Nothing to see here.

\chapter{And Another}
\gls{sample}

\printunsrtglossaries

\end{document}


This ends the internal location list with a full stop and puts a paragraph break before the start of the external lists and also a prefix. Each sub-list is started with the name of the external document:

Each external location is formatted with \glsxtrdisplaysupploc{hyperprefix}{counter}{format}{document}{location} where hyperprefix and counter are used in the creation of the hyperlink's target name, format is the original format used in the external document (ignored by default), document is the external document and location is the external location. This command is defined (in glossaries-extra-bib2gls.sty, which is automatically loaded with the record package option) as:

\newcommand*\glsxtrdisplaysupploc[5]{%
\setentrycounter[#1]{#2}%
\glsxtrmultisupplocation{#5}{#4}{#3}%
}


So if you want a prefix for each external location (rather than for the sub-list) then you can redefine this command. The simplest way is to provide a mapping from the document file name to the required prefix. For example:

\documentclass{book}

\usepackage[record % using bib2gls
]{glossaries-extra}

\newcommand{\setfileprefix}[2]{\csdef{prefix@#1}{#2}}
\newcommand{\usefileprefix}[1]{\csuse{prefix@#1}}

\setfileprefix{test-supp1.pdf}{A}
\setfileprefix{test-supp2.pdf}{B}

\renewcommand*\glsxtrdisplaysupploc[5]{%
\setentrycounter[#1]{#2}%
\usefileprefix{#4}\glsxtrmultisupplocation{#5}{#4}{#3}%
}

src={entries}, % data in entries.bib
% requires glossaries-extra v1.36 and bib2gls v1.7:
% include locations from supplementary documents obtained from
% test-supp1.aux and test-supp2.aux
supplemental-locations={test-supp1,test-supp2},
]

\begin{document}
\frontmatter

\chapter{Foreword}
\gls{sample}.

\mainmatter

\chapter{Sample}

\gls{sample}.

\chapter{Another}
Nothing to see here.

\chapter{And Another}
\gls{sample}

\printunsrtglossaries

\end{document}


Notes:

• Older versions of bib2gls only support a single value (not a list) for the supplemental-locations option.
• With v1.7, if bib2gls detects that the version of glossaries-extra is too old to support multiple supplementary locations, it will only accept the first item listed in supplemental-locations (and issue a warning).
• According to the site rules I shouldn't say "thanks", the +1 does the job. But seeing the job you have done and the incredible answer I'll say thanks for the time and work it took to answer my questions and explain every detail. – Luis Turcio Aug 20 '18 at 23:41