0

I have this command \name which stores the name of someone. (Edit: I also use this command for other things, so I would like it to be the same).

I would like to use the command \plauthorname[first name][von-part]{surname} to remove the name given in \name from the bibliography. The problem is to make a command that splits \name into one, two or three strings depending on the input:

  • If only surname is given, i.e. \name{surname} we get \plauthorname{surname}
  • If first (and middle) names are given, but no von-part, i.e. \name{ Firstname Middlename Lastname} we get \plauthorname[Firstname Middlename]{surname}.
  • If a von-part recognized by biblatex is given in name, i.e. \name{Firstname von-part Lastname} we get \plauthorname[first name][von-part]{surname}
  • I would also like it to work if someone wrote \name{Lastname, Firstname}

The hardest part (I think) is to find out if the name contains a von-part recognized by \plauthorname.

\documentclass{article}

% From .sty file: \newcommand{\name}[1]{\def@name{#1}} \RequirePackage[% backend=biber, bibstyle=publist, hyperref=auto ]{biblatex}

% Some code to get first name, middle name von-part and surname.

\plauthorname[first name][von-part]{surname}

\begin{filecontents}[overwrite]{sample.bib} @article{einstein, author = "Albert Einstein", title = "{Zur Elektrodynamik bewegter K{"o}rper}. ({German}) [{On} the electrodynamics of moving bodies]", journal = "Annalen der Physik", volume = "322", number = "10", pages = "891--921", year = "1905", DOI = "http://dx.doi.org/10.1002/andp.19053221004", }

@book{dirac, title = {The Principles of Quantum Mechanics}, author = {Paul Adrien Maurice Dirac}, isbn = {9780198520115}, series = {International series of monographs on physics}, year = {1981}, publisher = {Clarendon Press}, } \end{filecontents} \addbibresource{sample.bib}

% This will be defined by users: \name{Paul Adrien Maurice Dirac}

\begin{document}

foo baz baa

\nocite{*}

\printbibliography

\end{document}

\plauthorname[first name][von-part]{surname} is from biblatex-publist: https://ctan.org/pkg/biblatex-publist


Side note: I was thinking of declaring class options to (a) not hide name from publist or (b) highlight name in publist instead (for example normalpublist and highlightpublist). How would I go about this? Here is my thinking: for higlight set plauthorhandling=highlight somehow (?), and for normal also set plauthorhandling=highlight but re-define highlight to be normal text by (p. 11 in documentation):

\renewcommand*\plauthorhl[1]{%
#1%
}
Vebjorn
  • 1,778
  • Redoing BibTeX's name parsing in TeX sounds painful (though not entirely undoable - I guess). For name comparison I usually prefer the name hashes generated by Biber, which you can even sort of have produced from the TeX file with a temporary .bib file. See https://tex.stackexchange.com/a/416416/35864. – moewe Nov 02 '22 at 16:38

1 Answers1

1

This answer is only a preliminary one - the text is too long for comment.

You wish to split a string (input) into components. You have roughly described how possible input strings can be structured. But you did not describe how the algorithm for parsing the input should work.

Since the whole thing is to run on macro level, it is about tokens and thus, e.g., also about the question whether the string, which consists of tokens, should be expanded before parsing.

Some other questions are:

  • Is the mechanism to cope with different input encodings, and if so, which ones?
  • Does the use of the package inputenc play a rôle?
  • To what extent do different LaTeX notations for the same name or the same von-part play a rôle? (E.g., assume a von-part that contains umlauts - eg \"a and "a and ä might mean the same character.)

I could imagine a mechanism which

  • removes all leading and trailing space tokens from the string,
  • tests the remaining string for the presence of token sequences that might represent von-parts and, if such token sequences are present, splits the remaining string into first name and von-part and surname at the place of the first occurrence of a von-part. If in the remaining string no von-part is preset: if there are no spaces uses the remaining string as surname while assuming that no first name is given; if there are spaces, uses the last space-separable element of the remaining string as surname while assuming that stuff before the last space-separable element forms the first name.

How the mechanism should behave in edge cases is not specified.

  • E.g., behavior in case there are only things that count as von-part;
  • E.g., behavior in case the string is empty/blank;
  • E.g., behavior in case there is only a first name;
  • E.g., behavior in case the surname is a double-name consisting of several space-separated elements;
  • E.g., behavior in case the surname is a double-name whereof each has a von-part.

Also the order in which checking for presence of different von-parts takes place is relevant - e.g. checking for "Van der" (like in Van der Waals) should take place before checking for "Van de" (like in Van de Graaff), which in turn should happen before checking for "Van" (like in Van Gogh).

Proper/improper letter-casing with von-parts might also play a rôle.

Because there are so many edge cases, the question arises whether it is not preferable to do things the other way around:

Have the user of the interface you have in mind specify tthe single components of the name/the arguments of \plauthorname individually and then compose the argument for the \name macro from them as well.

Ulrich Diez
  • 28,770
  • Yes, I think it may be better to have the user specify each component and compose it in \name – Vebjorn Nov 03 '22 at 14:39
  • Re what goes into the von part and what goes into the last name bit (and what happens in edge cases): the only thing that makes sense here is to mimic BibTeX behaviour here (even if that might be odd or illogical in some edge cases). The behaviour is described in some detail in http://mirrors.ctan.org/info/bibtex/tamethebeast/ttb_en.pdf, but even that might not catch all of it, in which case a look at the source (or at lots of examples) might be needed. – moewe Nov 03 '22 at 21:00