2

Is it possible to have aliases/synonyms for keys for amsrefs? That is, consider the following sample document:

\documentclass{amsart}
\usepackage{amsrefs}
\begin{document}
See \cite{short}.
It is the same reference as
%\cite{a-longer-label-for-the-texbook}
    %% Uncomment the previous line.
\cite{short}. %% Comment out this line

\begin{bibdiv} \begin{biblist} \bib{short}{book}{ author={Knuth, Donald}, title={The TeXbook} }

%\synonym{a-longer-label-for-the-texbook}{short} %% Uncomment the previous line. \end{biblist} \end{bibdiv} \end{document}

I would like to uncomment the two indicated lines (and comment out the indicated line) and have the same behaviour. (Of course, I could just duplicate the content of the short bibliography entry under the longer key; but then, if I used both labels in the source, then two identical entries would appear in the resulting bibliography.)

If we were talking about \labels instead of bibliography entries, one could—although I am aware that it is very much not best practice—just put two \labels in the relevant scope, and reference them interchangeably; this is the sort of functionality that I am seeking. The documentation mentions the word "alias" (though not the word "synonym"), but not in this context.

This probably seems like a very strange desire. There are a few reasons that one might want to do this; I give two that have arisen for me, though I recognise that they are not necessarily compelling. One is to allow easily writing a document with a co-author who disagrees about how internal bibliography keys should be formatted, while allowing everyone to be happy. Of course, this can make the TeX code confusing, so here's another reason.

For this second reason, past me is the co-author: I would like to be able to use a single amsrefs file for all my papers, but also to be able to accommodate changes I've made over time in how I choose my keys, without having to change the source of old papers. Here I could simply duplicate the bibliography entry, as long as I'm consistent within each document about how I cite it; but then it can be easy to confuse almost-duplicate entries (say, for the 1st and 2nd editions of a book) with actually-duplicate entries. A \synonym type would make the intentional duplication explicit.

LSpice
  • 1,448
  • Since very few people are acquainted with amsrefs, adding a short example would be better. I'm not going into the effort of reading the docs and prepare the example myself. While I know about amsrefs, I've never used it, although I've been able to give some advice when a full example was provided. – egreg Jun 22 '22 at 10:09
  • @egreg, my very short example doesn't work, but that's because I don't know how to do what I want to do! Can you tell me what more I should provide to make a useful example? – LSpice Jun 22 '22 at 11:40
  • A full example of a (short) document calling the necessary packages and a simple bibliography item to alias. – egreg Jun 22 '22 at 11:55
  • @egreg, I have edited accordingly. I hope this is what is needed; please let me know if I need to revise it further. – LSpice Jun 22 '22 at 13:29

1 Answers1

2

The internal reference to short is stored in \b@short. We can use the .aux file to make the new key the same as \b@short. With \csname and \endcsname, because keys may not have only letters.

\documentclass{amsart}
\usepackage{amsrefs}

\makeatletter \newcommand{\makesynonym}[2]{% \AtEndDocument{\write@auxout{\noexpand@makesynonym{#1}{#2}}}% } \newcommand{@makesynonym}[2]{% \global\expandafter\let\csname b@#1\expandafter\endcsname\csname b@#2\endcsname } \makeatother

\makesynonym{a-longer-label-for-the-texbook}{short}

\begin{document} See \cite{short}. It is the same reference as \cite{a-longer-label-for-the-texbook}

\begin{bibdiv} \begin{biblist} \bib{short}{book}{ author={Knuth, Donald}, title={The TeXbook} } \end{biblist} \end{bibdiv} \end{document}

enter image description here

egreg
  • 1,121,712