对于我的简历,我想反转出版物数量(即从出版物总数开始一直倒数到 1)。使用纯 LaTeX 和 BibTeX 可以实现吗?
这个问题和这里的问题类似,只是在另一个线程中人们使用了 biblatex,我想避免这种情况,因为我正在寻找一个只需要进行微小更改的简单解决方案。 https://tex.stackexchange.com/a/22770/15319
答案1
您可以使用该etaremune
包;这需要重新定义thebibliography
才能使用它。我假设您使用的是unsrt
书目样式。
\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}
该filecontents*
环境只是提供一个模拟的bib文件。
答案2
这是一个简洁的修复方法,对我的 CV 中的“thebibliography”环境进行反向编号,仅使用普通乳胶而没有任何外部包。
编辑:
- 将计数器的值写入辅助文件,这样您就不需要手动输入出版物数量了。实际上,它出奇地简洁明了。
- 添加命令以获取标准“[1]”(我意识到我的第一个答案实际上并没有这样做)
原始帖子:
我只是输入了出版物总数并定义了一个 \bibitem 包装器(重新定义它有点棘手)。因为它只是修改了 \bibitem 的计数器值,所以它具有标准的“[1]”括号样式,并且可以与 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...
注意:计数器从 0 开始,因此 bibitem 自动将 ref 标记为 [N+1],这样计数器中的值“0”将给出 ref [1](而不是 [0])。首先步进 num 计数器会处理 +1
编辑(续):
这是一个有效的例子
\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}
答案3
基于egreg 的回答,但这里不是使用etaremune
包,而是使用包的变体revnum
。
\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}