19

For my CV, I would like to reverse number publications (i.e., starting from the total number of publications all the way down to 1). Is this possible with plain LaTeX and BibTeX?

This question is similar to that one here, except that in the other thread people used biblatex, which I would like to avoid because I am looking for a simple solution that requires only minor changes. https://tex.stackexchange.com/a/22770/15319

  • 3
    Do you want just the label numbers to count downwards rather than upwards, or do you want the entire list order to be inverted? E.g., if entries are sorted alphabetically, do you want the first entry to be by Zwicky (and numbered, say, [125]) and the last one to be by Aaberg and numbered [1])? – Mico Jun 5 '12 at 13:22
  • Hello. I just would like to have the numbering backwards. Thanks! – Eric Jul 9 '12 at 15:06
18

You can use the etaremune package; this requires redefining thebibliography to use it. I assume you are using the unsrt bibliography style.

\begin{filecontents*}{\jobname.bib}
@article{a,
 author={x y},
 title={a},
 journal={j},
 year=2000,
}
@article{b,
 author={x y},
 title={b},
 journal={j},
 year=2000,
}
@article{c,
 author={x y},
 title={c},
 journal={j},
 year=2000,
}
@article{d,
 author={x y},
 title={d},
 journal={j},
 year=2000,
}
\end{filecontents*}
\documentclass{article}
\usepackage{etaremune}
\makeatletter
\long\def\thebibliography#1{%
  \section*{\refname}%
  \@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}
  \settowidth{\dimen0}{\@biblabel{#1}}%
  \setlength{\dimen2}{\dimen0}%
  \addtolength{\dimen2}{\labelsep}
  \sloppy
  \clubpenalty 4000 
  \@clubpenalty 
  \clubpenalty 
  \widowpenalty 4000
  \sfcode `\.\@m
  \renewcommand{\labelenumi}{\@biblabel{\theenumi}} % labels like [3], [2], [1]
  \begin{etaremune}[labelwidth=\dimen0,leftmargin=\dimen2]\@openbib@code
}
\def\endthebibliography{\end{etaremune}}
\def\@bibitem#1{%
  \item \if@filesw\immediate\write\@auxout{\string\bibcite{#1}{\the\value{enumi}}}\fi\ignorespaces
}
\makeatother

\begin{document}
\cite{a,b,c,d}

\bibliographystyle{unsrt}
\bibliography{\jobname}

\end{document}

The filecontents* environment is just to provide a mock bib file.

| improve this answer | |
  • This works great, thanks! Is there a way to have the numbers appear as [3], [2], [1]... instead of 3., 2., 1.? I don't really understand the TeX you posted, so I don't quite see how to tweak it. – Eric Dec 5 '12 at 18:10
  • @Eric I've fixed my answer to get that. – egreg Dec 5 '12 at 18:23
3

Here is a concise fix that does reverse numbering for "thebibliography" environment in my CV, using only plain latex without any external package.

EDITS:

  1. write the value of the counter to the aux-file, so you don't need to input the number of publications manually. It was surprisingly concise and straightforward actually.
  2. added commands to get the standard "[1]" (I realized my first answer was not actually doing it)

Original post:

I just input the total number of publications and defined a wrapper around \bibitem (redefining it is a bit more tricky). Because it just modifies the counter value of \bibitem, it has the standard "[1]" bracket style and it works with hyperref.

\begin{thebibliography}{99}
\makeatletter
\newcounter{num}
\newcommand{\MyNbOfPub}{24}%input your number of publications here
\newcommand{\mybibitem}[1]{\stepcounter{num}\setcounter{\@listctr}{\MyNbOfPub-\value{num}}\bibitem{#1}}
\makeatother

\mybibitem{Myfirstref}
...
\mybibitem{Mysecondref}
...
etc...

NB: counters start at 0 thus bibitem automatically labels ref as [N+1] so that a value of "0" in the counter gives ref [1] (and not [0]). Stepping the num counter first takes care of that +1

enter image description here

EDITS (continued):

here is a working example

\documentclass[11pt,letterpaper,sans]{moderncv}
\moderncvstyle{classic}
\moderncvcolor{orange}
\usepackage[colorlinks=true,urlcolor=blue,citecolor=blue,unicode]{hyperref}
\usepackage[utf8]{inputenc}
\usepackage[scale=0.9]{geometry}

% Macros
% if \NbOfPub is defined in aux file 
%     the value is automatically read from the aux file
% else (first run)
%     create counter which will be wrote to the aux file at the end of the document
%     (note that we just use this counter as a fixed variable)
\ifdefined\NbOfPub
\else
    \newcount\NbOfPub
    \NbOfPub 0\relax
\fi

\makeatletter
% make square brackets numerical labels 
\renewcommand*{\bibliographyitemlabel}{\@biblabel{\arabic{enumiv}}}
% bibitems margins formatting
\setlength\bibindent{2em}
\renewcommand\@openbib@code{%
    \leftmargin 2em %push bib to the right by that amount
    \itemindent 0em %push item  1st line to the right by that amount
    \listparindent \parindent
    \parsep \z@
    \labelsep 1em %push label to the left from 1st line by that amount
}
% bibliography counter
\newcounter{num}
% define "\metibib", a \bibitem wrapper that counts in reverse
\newcommand{\metibib}[1]{%
    \stepcounter{num}
    \setcounter{\@listctr}{\NbOfPub-\value{num}}
    \bibitem{#1}
}
\makeatother

% document
\setlength{\hintscolumnwidth}{2cm}
\firstname{John}
\familyname{Doe}
\namespacing{1cm}{1cm}
\begin{document}
\makecvtitle
\section{Career Summary}
Here are my publications on A\cite{refA} and B\cite{refB}.

% change bibliography standard name
\renewcommand{\refname}{List of Publications}
% the bibliography
\begin{thebibliography}{9}
\item[] You have \the\NbOfPub\ publications in the .aux file

\item[\textbf{2018}]

\metibib{refA}
\underline{\textbf{J.~Doe}} \textit{et al.}\\
\textit{On topic A}\\
\textbf{Great Journal A}, xx, yyy\\
\url{https://doi.org/xxyyy}

\item[\textbf{2017}]

\metibib{refB}
\underline{\textbf{J.~Doe}} \textit{et al.}\\
\textit{On topic B}\\
\textbf{Great Journal B}, xx, yyy\\
\url{https://doi.org/xxyyy}

\end{thebibliography}

%write number of publications to aux-file
\makeatletter
\write\@auxout{\noexpand\newcount\NbOfPub}
\write\@auxout{\global\NbOfPub \arabic{num}\relax}
\makeatother

\end{document}

and here is the result I get enter image description here

| improve this answer | |
  • It would be very nice if your answer included a way to automatically calculate that \MyNbOfPub. One very easy way to do that would be to first count the number of references, then save it to the .aux file to use in the next run. One of LaTeX's outstanding qualities is the automation of boring and error prone tasks such as counting stuff :) – Phelype Oleinik Aug 15 '18 at 20:52
  • I totally agree. I just didn't have time to delve into it. Now – Max Aug 20 '18 at 17:28
  • Now a more tongue-in-cheek answer is that, if you're writing a CV you probably know the exact number of publications you have and are actively working on improving that number, and if you have so many you lost count of them, you probably don't need to write a CV ;-) – Max Aug 20 '18 at 17:35
  • I don't like the approach, but I agree. I, for one, would forget to update that number and get a reference numbered [-1] and, probably, wouldn't notice. Either way it would be nice if your answer included at least a compilable example... even though the question didn't. – Phelype Oleinik Aug 20 '18 at 17:51
  • Well, turns out it's fairly simple in latex to keep track of a counter in the aux-file, see my edited answer. – Max Aug 20 '18 at 21:38
0

Based on egreg's answer, but instead of the etaremune package, here a variant using the revnum package.

\begin{filecontents*}{\jobname.bib}
@article{a,
 author={x y},
 title={a},
 journal={j},
 year=2000,
}
@article{b,
 author={x y},
 title={b},
 journal={j},
 year=2000,
}
@article{c,
 author={x y},
 title={c},
 journal={j},
 year=2000,
}
@article{d,
 author={x y},
 title={d},
 journal={j},
 year=2000,
}
\end{filecontents*}
\documentclass{article}
\usepackage{revnum}


\makeatletter
\long\def\thebibliography#1{%
  \section*{\refname}%
  \@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}
  \settowidth{\dimen0}{\@biblabel{#1}}%
  \setlength{\dimen2}{\dimen0}%
  \addtolength{\dimen2}{\labelsep}
  \sloppy
  \clubpenalty 4000 
  \@clubpenalty 
  \clubpenalty 
  \widowpenalty 4000
  \sfcode `\.\@m
  \renewcommand{\labelenumi}{\@biblabel{\theenumi}} % labels like [3], [2], [1]
  \begin{revnumerate}\@openbib@code
}
\def\endthebibliography{\end{revnumerate}}
\def\@bibitem#1{%
  \item \if@filesw\immediate\write\@auxout{\string\bibcite{#1}{\the\value{enumi}}}\fi\ignorespaces
}
\makeatother

\begin{document}
\cite{a,b,c,d}

\bibliographystyle{unsrt}
\bibliography{\jobname}

\end{document}
| improve this answer | |

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.