没有 bibtex 和引文的多个参考书目

没有 bibtex 和引文的多个参考书目

我正在写一篇文章,其中我使用了分节参考书目(我没有使用 bibtex)。代码如下:

\documentclass{article}
\begin{document}

% Save old cite/bibitem command(s)
\let\oldcite\cite
\let\oldtextcite\textcite % Add others as needed
\let\oldbibitem\bibitem

% Add new counter to increment at each paper
\newcounter{papernum}
\def\nextpaper{\stepcounter{papernum}}

% Define new cite/bibitem command(s) with prefix applied
\def\mynewcite#1{\oldcite{\thepapernum#1}}%
\def\mynewtextcite#1{\oldtextcite{\thepapernum#1}}%
\def\mynewbibitem#1{\oldbibitem{\thepapernum#1}}%

% Reroute original commands to new commands
\let\cite\mynewcite%
\let\textcite\mynewtextcite%
\let\bibitem\mynewbibitem%

\section*{Paper 1}\nextpaper %This could be wrapped into whatever unit you use to start a new paper; just make sure another sectioning command (in this case, References is also a \section*) doesn't increment the counter in places you don't want it to.
Ipsum \cite{ipsum}, % I want this to produce the text '[1]', since it is number 1 in this paper's bibliography.
Dolor \cite{dolor}

\begin{thebibliography}{9}
\bibitem{ipsum} Ipsum
\bibitem{dolor} Dolor
\end{thebibliography}

\section*{Paper 2}\nextpaper
Lorem \cite{lorem}, Ipsum \cite{ipsum}

\begin{thebibliography}{9}
\bibitem{lorem} Lorem
\bibitem{ipsum} Ipsum
\end{thebibliography}

\end{document}

效果很好,但是当我写第 (论文 2) 节时,它显示 [1,?]。在这种情况下,\cite{lorem,ipsum}如何使用命令获取多个引用?\cite

答案1

我不确定你为什么要使用方形轮子,但是,既然你这么做了,也许这样的东西会适合:

\documentclass{article}
% Add new counter to increment at each paper
\newcounter{papernum}
\def\nextpaper{\stepcounter{papernum}}

% Save old bibitem command(s)
\let\oldbibitem\bibitem
\def\mynewbibitem#1{\oldbibitem{\thepapernum#1}}
\let\bibitem\mynewbibitem

\makeatletter
\def\@citex[#1]#2{\leavevmode
  \let\@citea\@empty
  \@cite{\@for\@citeb:=#2\do
    {\@citea\def\@citea{,\penalty\@m\ }%
     \edef\@citeb{\thepapernum\expandafter\@firstofone\@citeb\@empty}%
     \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
     \@ifundefined{b@\@citeb}{\hbox{\reset@font\bfseries ?}%
       \G@refundefinedtrue
       \@latex@warning
         {Citation `\@citeb' on page \thepage \space undefined}}%
       {\@cite@ofmt{\csname b@\@citeb\endcsname}}}}{#1}}
\makeatother

\begin{document}

\section*{Paper 1}\nextpaper %This could be wrapped into whatever unit you use to start a new paper; just make sure another sectioning command (in this case, References is also a \section*) doesn't increment the counter in places you don't want it to.
Ipsum \cite{ipsum}, % I want this to produce the text '[1]', since it is number 1 in this paper's bibliography.
Dolor \cite{dolor}

\begin{thebibliography}{9}
\bibitem{ipsum} Ipsum
\bibitem{dolor} Dolor
\end{thebibliography}

\section*{Paper 2}\nextpaper
Lorem \cite{lorem}, Ipsum \cite{ipsum}
Lorem and Ipsum \cite{lorem,ipsum}

\begin{thebibliography}{9}
\bibitem{lorem} Lorem
\bibitem{ipsum} Ipsum
\end{thebibliography}

\end{document}

以下是代码中定义的方形轮子的结果:

使用方轮的参考书目和引文

相关内容