# Citations with no bibliography at the end

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...).

-

## migrated from stackoverflow.comOct 12 '11 at 17:09

This question came from our site for professional and enthusiast programmers.

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. –  barbara beeton Oct 12 '11 at 17:40

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

-
That's simple and accurate... a great answer. –  keflavich Oct 12 '11 at 21:19
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 at 0:29

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}

-
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 '11 at 21:20
Amazing, but I still had to add \bibliographystyle{} before \bibliography{}. Otherwise, this is magical. –  crippledlambda Oct 15 '12 at 20:08

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

e.g.

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

-
Welcome to TeX.sx! Thanks for your answer, we're looking forward to your future contributions to this Q&A. –  Marco Daniel Nov 7 '13 at 18:09

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.

-
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 '11 at 21:15
@egreg this was very useful, thanks! –  Sosi May 9 '13 at 17:47
@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 '13 at 18:03

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}

\begin{document}

Some text \citep{A01}.

% \printbibliography

\end{document}

-

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{*}.

-

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 ...

-