4

I am currently writing my PhD thesis using the {report} class on Texshop (LaTex) for Mac. I have used BibTex to compile my reference list, in which I have created a library called 'database' which has in it all of the texts that I have read.

Using the command:

\bibliography{database}

in the preamble, I can generate a bibliography of the references that I have cited within the text.

OR

using the command:

\nocite{database}

in the preamble, I can generate a bibliography of all of the references I have compiled in my library (including cited references and additional reading).

How do I get two distinct sections, one for cited references and one for additional reading?

  • 2
    Would you consider using biblatex? It will be easier. – Bernard Oct 11 '15 at 18:15
  • Yes, I would if it is easier/better. I'm a bit of a novice though I'm afraid: could you offer some advice? – LAB Oct 11 '15 at 18:53
  • 1
    It already has been asked in this question and has an answer. – Bernard Oct 11 '15 at 19:23
1

I agree that there are better ways to go. However, here is a rather convoluted way to do it within the constraints given by the OP.

Assuming your document is named document.tex, your citations are in database.bib, and that you want all of the references in database.bib that are not explicitly cited to be in Additional Reading:

1. Compile your document as is

\documentclass{article}
\bibliographystyle{plain}

\begin{document}
Some text \cite{Acevedo12}.
\bibliography{database}
\end{document}

This results in the document.aux file containing \citation{key} entries for each of the citations. In this case it contains an entry \citation{Acevedo12}.

2. Run BibTex

This creates the document.bbl file which is the formatted references section. The \bibliography command is akin to \input{document.bbl} and will be used as such below.

3. Rename document.bbl to cited.bbl

This will save the formatted bibliography for the cited references.

4. Add \nocite{*} and recompile your document

\documentclass{article}
\bibliographystyle{plain}

\begin{document}
Some text \cite{Acevedo12}.
\nocite{*}
\bibliography{database}
\end{document}

This results in the document.aux file containing the \citation{*} command, which will instruct BibTex to include all of the references in the library.

5. Run BibTex

This creates a new document.bbl file containing all of the references in the library formatted for the references section.

6. Create a new .tex document (assumed to be called addreading.tex) with the following and compile

\documentclass{article}
\bibliographystyle{plain}
\usepackage{etoolbox}
\usepackage{ifthen}

\makeatletter
    \newcounter{citedrefcount}%
    \newcommand\setcited[2]{\expandafter\gdef\csname citedref#1\endcsname{#2}}
    \newcommand\addcited[1]{\stepcounter{citedrefcount}\setcited{\thecitedrefcount}{#1}}%
    \newcommand\getcited[1]{\csuse{citedref#1}}%

    \newcommand\adduncited[1]{%only add if the reference key is not contained within the cited references
        \newcount\temp\aloop\temp=1 step 1 until {\thecitedrefcount} do {%
            \gdef\uncited{\cite{#1}}
            \ifthenelse{\equal{\getcited{\@arabic\temp}}{#1}}%compare the citation key to the \temp citedref key
            {%citekey matches a citedref. redefine \uncited to do nothing and end the loop
                \gdef\uncited{\relax}%
                \temp=\thecitedrefcount}%
            {%citekey does not match checked citedref. do nothing (keep definition of \uncited)
            }} \endaloop\temp
        \uncited%execute \uncited (does nothing if reference is already in the cited list, cites the reference if it is not citedyet).
        }
\makeatother


%%% Basic Loop
%Taken from David Salomon's The Advanced TeXbook pg 191
\def\aloop#1=#2 {%
    \long\def\next step ##1 until ##2 do ##3 \endaloop#1{%
        ##3%
        \advance#1 by ##1
        \ifnum#1>##2\relax\else\next step ##1 until ##2 do ##3 \endaloop#1 \fi%
        }%end of \next
    #1=#2 \next}%end of \aloop  

\begin{document}
    \def\bibitem#1{\addcited{#1}}
    \input{cited.bbl}
    \def\bibitem#1{\adduncited{#1}}
    \input{document.bbl}
    \bibliography{database}
\end{document}

This compares the citation keys in the document.bbl file to those in the cited.bbl file, adding \citation{key} to the addreading.aux file only for citation keys not in the cited.bbl (i.e., not cited in the original document).

7. Run BibTex on the addreading file.

This results in addreading.bbl, which is the formatted references section for the references not cited in the original document.

8. Finally, modify the original document to reference the two .bbl files

\documentclass{article}
\bibliographystyle{plain}

\begin{document}
Some text \cite{Acevedo12}.
\input{cited.bbl}
\renewcommand\refname{Additional Reading}
\input{addreading.bbl}
\end{document}

Edit:

Redefining the bibliography environment to account for maximum number of references in either of the references sections allows for the enumeration to continue and the alignment to be correct after a couple runs.

\documentclass{article}
\bibliographystyle{plain}
\usepackage{ifthen}

\newcounter{allcitations}%counter to hold the total number of citations
\gdef\maxsubcitations{0}%maximum number of citations in a citation list (determines the space necessary for the enumeration
\makeatletter
    \let\oldthebib\thebibliography
    \let\oldendthebib\endthebibliography
    \renewenvironment{thebibliography}[1]{%redefine thebibliography environment to have a running count and align based on the largest number of citations
            \oldthebib{\maxsubcitations}%
            \ifthenelse{#1>\maxsubcitations}%
            {%
                \gdef\maxsubcitations{#1}
                \immediate\write\@auxout{\noexpand\gdef\noexpand\maxsubcitations{#1}}
            }{}
            \addtocounter{\@listctr}{\theallcitations}
        }{%
            \addtocounter{allcitations}{\c@enumiv}
            \oldendthebib}
\makeatother    
\begin{document}
Some text \cite{Acevedo12}.
\input{cited.bbl}
\renewcommand\refname{Additional Reading}
\input{addreading.bbl}
\end{document}

Partial page

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.