[Tex/LaTex] Multiple bibliographies without bibtex and citations

bibliographies

I am writing an article where I am using section wise bibliography (I am not using bibtex). The code is the following:

\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}

It works well, but when I write for section (Paper 2) say \cite{lorem,ipsum} it shows [1,?]. How can I get multiple citations with \cite command in this case?

Best Answer

I'm not sure why you wish to use square wheels, but, since you do, perhaps something like this would suit:

\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}

Here is the result of the square wheels defined in the code:

bibliography and citations using square wheels

Related Question