1

It doesn't work out of the box: it's treats first and last name as last name. I guess "expand after" comes into play, but long time since I used this feature.

\documentclass{article}
\usepackage[french]{babel}
\usepackage{expl3}
\usepackage{glossaries}
\usepackage{csquotes}
\usepackage[backend=biber,autolang=other]{biblatex}

\DefineBibliographyStrings{french}{
  in = {dans},
}

\newglossary*{cont}{Contact}

\newglossaryentry{dupont}
{
  type=cont,
  name={Dupont, Michel},
  description={}
}    

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{lefoo
  ,author =       {Dupond, Marie}
  ,title =        "TITRE"
  ,journal =      "LE JOUR"
  ,year =         "AAAA"
  ,language={french}
  ,hyphenation={french}
}
@article{lebar
  ,author =       {\gls{dupont}}
  ,title =        "TITRE"
  ,journal =      "LE JOUR"
  ,year =         "AAAA"
  ,language={french}
  ,hyphenation={french}
}
\end{filecontents*}
\addbibresource{\jobname.bib}

\begin{document}

Une citation: \autocite{lefoo}.

Une citation au milieu du texte: Comme \textcite{lebar} a dit \dots

\printbibliography
\end{document}

Print

1
  • 1
    I don't think this is going to work. By the time biblatex gets access to the author, the bib file has been processed by biber and the author name has been broken apart. You could potentially hack the data model to replace things ...
    – StrongBad
    Sep 19, 2019 at 19:16

1 Answer 1

1

I'm afraid this simply won't work.

Name fields need to be parsed by Biber (or BibTeX) to extract the different name parts (given name, family name, suffix and prefix), since Biber does not know about LaTeX macros in general (it knows about some macros for single non-ASCII characters) there is no way \gls{dupont} would be treated like Dupont, Michel.

In the example \gls{dupont} is treated as the sole family name of the author and the macro is only later expanded to produce the output you see.

There are no amounts of \expandafter s that could help you to pass the expected name to Biber. You could use a source map to replace the macro again, but that appears a bit backwards and you lose all other benefits of \gls.

\documentclass{article}
\usepackage[french]{babel}
\usepackage{expl3}
\usepackage{glossaries}
\usepackage{csquotes}
\usepackage[backend=biber,autolang=other]{biblatex}

\DefineBibliographyStrings{french}{
  in = {dans},
}

\newglossary*{cont}{Contact}

\newglossaryentry{dupont}
{
  type=cont,
  name={Dupont, Michel},
  description={}
}    

\DeclareSourcemap{
  \maps[datatype=bibtex, overwrite]{
    \map{
      \step[fieldsource=author, match=\regexp{\\gls\{dupont\}}, replace={Dupont, Michel}]
    }
  }
}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{lefoo
  ,author =       {Dupond, Marie}
  ,title =        "TITRE"
  ,journal =      "LE JOUR"
  ,year =         "AAAA"
  ,language={french}
  ,hyphenation={french}
}
@article{lebar
  ,author =       {\gls{dupont}}
  ,title =        "TITRE"
  ,journal =      "LE JOUR"
  ,year =         "AAAA"
  ,language={french}
  ,hyphenation={french}
}
\end{filecontents*}
\addbibresource{\jobname.bib}

\begin{document}
Une citation: \autocite{lefoo}.

Une citation au milieu du texte: Comme \textcite{lebar} a dit \dots

\printbibliography
\end{document}

Correctly formatted names.

You probably need a different way to achieve what you want to do with \gls.

4
  • I feel like with some nasty expandafter and regexp trickery you might be able to match all \gls{*} and make the "replace" be essentially \expandafter\gls{*}, but it is so not worth it.
    – StrongBad
    Sep 24, 2019 at 13:39
  • @StrongBad Nice idea. The replacement text is accessible expandably in \glo@<label>@name. But I couldn't get this to work since I would need Biber to match the regexp in \gls{.*} and then pass the captured group back to LaTeX to resolve \glo@$1@name.
    – moewe
    Sep 24, 2019 at 15:58
  • At a minimum you could change replace={Dupont, Michel} to something like replace={\glo@dupont@name} with a whole bunch of expandafter trickery to get \glo@dupont@name to actually be expanded.
    – StrongBad
    Sep 24, 2019 at 16:06
  • 1
    @StrongBad True replace={\csname glo@dupont@name\endcsname} would work, but might explode when you have non-ASCII chars in non Unicode-engines, so finer expansion control is needed.
    – moewe
    Sep 24, 2019 at 16:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .