58

How do you produce a document with citations (\citep, \citet) working properly in the paper but without a bibliography at the end?

I've come up with one solution that is bad because it breaks my makefile.

latex file.tex
bibtex file
# comment out \bibliography{} command
latex file.tex

Similarly, is there a way to produce the bibliography with no accompanying text? Again, I've come up with a solution: fill an otherwise blank .tex file with \nocite{} commands. However, this is a pain because I have to keep two files synced by hand (and regular expressions to search for \citep{author1, author2} can be a huge pain when there are pagebreaks...).

1
  • 2
    why are you commenting out the \bibliography{} command? presumably you do have a .bib file, otherwise it makes no sense to have any \cite instructions. once bibtex has created a .bbl file from the .bib file, it doesn't matter whether the cite entries are put into the .aux file again. Oct 12, 2011 at 17:40

9 Answers 9

21

Your second request is easy: use \nocite{*}. This will produce a full bibliography, regardless of which bibliography entries are actually cited.

1
  • 7
    This is a good idea only if your .bib file contains nothing but entries you want in your bibliography. I guess that's so for the OP but thought it worth mentioning for others. It would produce something ridiculous with a common database of entries, for example.
    – cfr
    Mar 24, 2014 at 0:29
71

Use the \usepackage{bibentry} and then instead of \bibliography{} use \nobibliography{}.

e.g.

\nobibliography{/Users/Thomas/Dropbox/bibliography.bib}
4
32

You can define a savebox and put the \bibliography command inside the savebox.

Here is a small example:

\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{test,
author={Name},
title={TITLE},
year={2011},
}
\end{filecontents}
\documentclass{article}
\usepackage{natbib}
\bibliographystyle{plainnat}
\begin{document}
\cite{test}

\newsavebox\mytempbib
\savebox\mytempbib{\parbox{\textwidth}{\bibliography{test}}}

\end{document}

NOTE: If you are using biblatex you don't need such hacks.

EDIT

In relation to my answer I have a small question. What do you think about a small package which allows the user to print the bibliography or not?

Here my first try:

%% Copyright (C) 2011 by Marco Daniel
\ProvidesPackage{nobibprint}[2011/10/12 v0.1 nobibprint]
\RequirePackage{etoolbox}
\RequirePackage{xkeyval}
\define@boolkey{nobibprint.sty}[nobib@]{hide}{}
\ExecuteOptionsX{hide=true}
\ProcessOptionsX
\newsavebox\nobib@tempbox
\ifnobib@hide
   \AtBeginDocument{%
     \let\nobib@bibliography@orig\bibliography
     \def\bibliography#1{%
        \savebox\nobib@tempbox{%
           \parbox{\linewidth}{%
              \nobib@bibliography@orig{#1}%
            }%
        }%
      }%
   }
\fi
\endinput

Now simple use:

\usepackage{nobibprint}

or:

\usepackage[hide=true]{nobibprint}%default

or

\usepackage[hide=false]{nobibprint}
3
  • 2
    I certainly like the idea of the package, and will give it a shot. I don't think I understand saveboxes; will have to look those up.
    – keflavich
    Oct 12, 2011 at 21:20
  • Amazing, but I still had to add \bibliographystyle{} before \bibliography{}. Otherwise, this is magical.
    – hatmatrix
    Oct 15, 2012 at 20:08
  • Great. Just to be clear, the only thing that's needed is: \newsavebox\mytempbib \savebox\mytempbib{\parbox{\textwidth}{\bibliography{test}}} Sep 22, 2014 at 21:24
9

If you put the \bibliography command in a file, say bibcommand.tex and in the main file you say

\documentclass{book}
...
%\includeonly{}
...

\begin{document}
<the document>

\include{bibcommand}

\end{document}

then a normal compilation will include the bibliography, but commenting out \includeonly{} will omit it.

You can also add the \includeonly{} from the shell

latex "\includeonly{}\input{filename}"

(where your main file is filename.tex) and this may be included in a Makefile, I believe.

2
  • So \includeonly{} forces the later \include command to be ignored? And using "latex [some latexcommand] filename" prepends the latex command to the file? Both very useful features, thanks.
    – keflavich
    Oct 12, 2011 at 21:15
  • @Sosi I'd like to acknowledge who first taught me this trick, but it was something I read in comp.text.tex several years ago.
    – egreg
    May 9, 2013 at 18:03
7

Simply use biblatex and its natbib compatibility option.

\documentclass{article}

\usepackage[style=authoryear,natbib=true]{biblatex}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@misc{A01,
  author = {Author, A.},
  year = {2001},
  title = {Alpha},
}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}

Some text \citep{A01}.

% \printbibliography

\end{document}
1

If you already have a foo.bbl file that you want to pull from (e.g. from another main document), a slight modification from this question works wonders:

\newsavebox\mytempbib
\savebox\mytempbib{\parbox{\textwidth}{\input{foo.bbl}}}
1

For your first question: "How do you produce a document with citations (\citep, \citet) working properly in the paper but without a bibliography at the end?"

This maybe a dirty solution, but please try adding \vspace*{-200in} right before your \bibliography{} command. I think the whole references then go to somewhere too high to be seen.

1
  • This is really great solution.
    – Myshkin
    Jul 7, 2022 at 18:29
0

Your makefile can empty the *.bbl file. If you want to use Konrad's suggestion to separately compile the bibliography, you can try the following (untested):

file.dvi: file.tex
        latex file
        bibtex file
        mv -f file.bbl references.bbl; touch file.bbl
        latex file
        latex references

where references.tex is the Latex file that invokes \nocite{*}.

0

I used a sorta hack :)

Compiling only a page range or page selection

this gives info on page selection while making pdf ... I put a \newpage before bibliography and just didn't compile those pages ...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .