0

I would like to be able to have some text with a reference inserted in a way that is not very disruptive to the reading of my text in the editor.

Currently I have something like this:

Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text
ever since the 1500s \cite{www.somethingaboutlorumipsom.com},
when an unknown printer took a galley of type and scrambled it
to make a type specimen book.

When I would prefer something like this, with the reference name in full in a smaller paragraph below the first paragraph:

Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s \cite{1},
when an unknown printer took a galley of type and scrambled it
to make a type specimen book.

My text describing the citation:

\cite{1}{www.somethingaboutlorumipsom.com}

I am aware that I can change the reference in bibtex or natbib so I only need to type \cite{@1} or something. The issue is my workflow: I typically want to put the entire reference name in place so I can see what I have or have not referenced. I do a lot of literature reviews and its vital to have the names visible.

Are there any packages or approaches you could recommend to me? It would honestly help enormously.

3
  • 1
    it is very hard to tell what you have done or what output you want (a small test document always makes a question clearer). Normally you just use \cite{abc} where abc is an internal key used in the bib file, and then your bibliography style specifies if that is printed as [1] or [James et al] or whatever other style is needed. – David Carlisle May 28 '20 at 13:03
  • You might take a look at the packages showlabels and showkeys. Another possibility might be to create a command that triggers a dedicated footnote in which you could enter the reference info, that can be redefined to be ignored in the final run; this would, of course, change the paging, but wouldn't have the width problems that your long references might have when being set in the margin. – barbara beeton May 28 '20 at 13:21
  • Would it be an option to use short keys, and print a separate bibliography for each section, showing only the references used in that section? This can be done with Bibtex with the help of some packages or with Biblatex. You could even use a bibliography style that only prints, e.g., author and title and no other bibliographical information. Then for your final article you remove the per-section bibliographies and replace them with one full bibliography with a normal style. Or is this too far from your normal workflow? – Marijn May 28 '20 at 13:32
0

This is generally not how citations in BibTeX/biblatex work. It looks a bit like the approach in markdown. (With a bit of creativity manual thebibliography+\bibitem is a less flexible version of that approach.)

In the LaTeX world the idea is is that you assign a useful label to each source once BibTeX/biblatex in the .bib file and use that throughout your document (or even for all your documents loading the same .bib file). Often people pick the family name of the first author(s) and possibly the year, a keyword or a few important words from the title. For example sigfridsson, nussbaum1978, geer:thesis, worman:cast (adapted from biblatex-examples.bib). This label should be long enough so that it immediately tells you what it refers to, but short enough so it doesn't take up too much space in your source code and you can remember and type it quickly.


With biblatex and Biber it is possible to use the ids field to give a .bib entry several possible keys with which it can be cited, but those keys still reside in the .bib file and can not be changed dynamically from the .tex document. (See Renaming BibTeX keys without breaking existing documents.)


Here is a proof of concept that lets you define arbitrary aliases in your document. Define an alias with

\assigncite{<document cite key>}{<bib cite key>}

for example \assigncite{1}{sigfridsson} so you can use 1 in your document and get sigfridsson from the .bib file.

Then cite as usual with \jsmcite{<document cite keys>}.

Since we are writing the aliases to the .aux file this needs two compilation runs before you run BibTeX/Biber (so the full compile sequence is at least LaTeX, LaTeX, Biber/BibTeX, LaTeX, LaTeX), but the advantage is that you can define the alias everywhere in your document.

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=authoryear, backend=biber]{biblatex}

\usepackage{etoolbox}
\makeatletter
\newcommand*{\jmsc@citekeys}{}

% {<document cite alias>}{<bib entry key>}
\newcommand{\assigncite}[2]{%
  \ifinlist{#1}{\jmsc@citekeys}
    {\PackageWarning{james-cite}
       {Key for '#1' already defined.\MessageBreak
        Overwriting urrent value '\csuse{jmsc@citekey@#1}'
        with '#2'}}
    {\listadd{\jmsc@citekeys}{#1}}%
  \csdef{jmsc@citekey@#1}{#2}}

\newcommand*{\jmsc@aux@assigncite}[2]{%
  \csgdef{jmsc@aux@citekey@#1}{#2}}

\newcommand*{\jmsc@write@liasestoaux}{%
  \forlistloop{\jmsc@write@liastoaux}{\jmsc@citekeys}}

\newcommand*{\jmsc@write@liastoaux}[1]{%
  \immediate\write\@mainaux{%
    \string\jmsc@aux@assigncite{#1}{\csuse{jmsc@citekey@#1}}}}

\AtEndDocument{%
  \jmsc@write@liasestoaux}

% allowing for all arguments of \...cite
% with the #{ "argument"
\newcommand*{\makejmscitecommand}{}
\protected\def\makejmscitecommand#1#2#{%
  \def\jmsc@tempcite{#1#2}%
  \jmscite@process}

\newcommand{\jmscite@process}[1]{%
  \let\jmsc@tempa\@empty
  \forcsvlist{\jmscite@preprocess@itm}{#1}%
  \expandafter\jmsc@tempcite\expandafter{\jmsc@tempa}}

\def\jmscite@preprocess@itm#1{%
  \ifcsundef{jmsc@aux@citekey@#1}
    {\G@refundefinedtrue
     \PackageWarning{james-cite}
       {Citation key '#1' not defined}}
    {\ifdefvoid\jmsc@tempa
       {\letcs\jmsc@tempa{jmsc@aux@citekey@#1}}
       {\eappto\jmsc@tempa{,\csuse{jmsc@aux@citekey@#1}}}}}
\makeatother

% defined the new cite command
\newcommand*{\jmscite}{\makejmscitecommand{\autocite}}

\addbibresource{biblatex-examples.bib}

\begin{document}
Lorem ipsum \jmscite{1}

\assigncite{1}{sigfridsson}

Lorem ipsum \jmscite[45]{1}

\printbibliography
\end{document}

Lorem ipsum (Sigfridsson and Ryde 1998)//Lorem ipsum (Sigfridsson and Ryde 1998, p. 45)

You can define new \jmscite-like commands as \makejmscitecommand{<cite command>}. In the example we based \jmscite on biblatex's \autocite. But the implementation does not depend on biblatex and can easily be switched to natbib commands with

\newcommand*{\jmscitep}{\makejmscitecommand{\citep}}
\newcommand*{\jmscitet}{\makejmscitecommand{\citet}}

We only allowed alias keys in \jmscite. It would be possible to also allow normal entry keys, but then we would have to drop the warning for undefined aliases.

\def\jmscite@preprocess@itm#1{%
  \ifcsundef{jmsc@aux@citekey@#1}
    {\ifdefvoid\jmsc@tempa
       {\def\jmsc@tempa{#1}}
       {\appto\jmsc@tempa{,#1}}}
    {\ifdefvoid\jmsc@tempa
       {\letcs\jmsc@tempa{jmsc@aux@citekey@#1}}
       {\eappto\jmsc@tempa{,\csuse{jmsc@aux@citekey@#1}}}}}

While I was looking for a good reference for ids I found Having several keys refer to the same bibliography entry, where Werner's answer uses a broadly similar approach (without the additional .aux file round trip).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.