23

Some grant agencies require separate pdf files for the main proposal and the references. I guess, it is easier to work this way in Word :-)

In LaTeX, one can create a single PDF file and then split it later using pdftk or other tools. However, is a direct method of creating two separate PDF files: one that contains the main text (with the correct citation information) and the second with all the list of references. I understand that, at the very least this will involve compiling two separate .tex files. That is okay. I just don't want to use additional tools (can be tricky to install on all computers of all collaborators, etc.)

Here is a MWE to play with:

\begin{filecontents}{test.bib}
  @ARTICLE{author,
    title={A sample article},
    author={Random Author},
    journal={Random journal},
    volume = {10},
    year = {2000},
  }
\end{filecontents}

\documentclass{article}
\usepackage{natbib}

\begin{document}
As shown by \citet{author}, using references can be interesting

\newpage
\bibliographystyle{apalike}
\bibliography{test}
\end{document}
8
  • (1) You can do it with one .tex file if you rename the first PDF. (2) You could do it, I think, with 3 .tex files where 2 are wrappers you compile. (3) You can create a document specific .bib using biber (whether you use this for compilation or not) and use 2 .tex files. (4) You can use 3 .tex files all of which you compile, where 2 just include the right pages from the compiled version of the third.
    – cfr
    Jan 25, 2015 at 1:35
  • An MWE would obviously come in handy...
    – cfr
    Jan 25, 2015 at 1:35
  • How about using \includeonly? Also, the package tcolorbox provides recording macro. I wonder if it can be useful here.
    – user11232
    Jan 25, 2015 at 1:46
  • @cfr: Thanks. I have added a a MWE. I would greatly appreciate if you could expand up on your comments.
    – Aditya
    Jan 25, 2015 at 1:59
  • 1
    What about the page numbers? You want them to be independent or continuous?
    – user11232
    Jan 25, 2015 at 2:45

3 Answers 3

11

Here is some acrobatics that uses two .tex files. First use atbegshi and discard the bibliography and then add it in the second file. The following is named, say test.tex

\begin{filecontents}{testttt.bib}
  @ARTICLE{author,
    title={A sample article},
    author={Random Author},
    journal={Random journal},
    volume = {10},
    year = {2000},
  }
\end{filecontents}

\documentclass{article}
\usepackage{natbib}
\usepackage{atbegshi}

\begin{document}
As shown by \citet{author}, using references can be interesting

\newpage
\AtBeginShipout{%
\AtBeginShipoutDiscard
}
\bibliographystyle{apalike}
\bibliography{testttt}
\end{document}

This will not produce the bibliography.

enter image description here

Now create a new file called reference.tex with the following

\documentclass{article}
\usepackage{natbib}

\begin{document}
\bibliographystyle{apalike}
\input{test.bbl}     %% watch out for the same name
\end{document} 

This will give you

enter image description here

If you want a single .tex file, we can complicate things further ;-) Following is the test.tex file that will give you two pdf files -- test.pdf having proposal and reference.pdf having references.

\documentclass{article}
\usepackage{natbib}
\usepackage{atbegshi}
\usepackage{filecontents}
\begin{filecontents*}{reference.tex}
\documentclass{article}
\usepackage{natbib}

\begin{document}
\bibliographystyle{apalike}
\input{test.bbl}     %% watch out for the same name
\end{document}
\end{filecontents*}

\begin{filecontents*}{testttt.bib}
  @ARTICLE{author,
    title={A sample article},
    author={Random Author},
    journal={Random journal},
    volume = {10},
    year = {2000},
  }
\end{filecontents*}

\immediate\write18{pdflatex reference}

\begin{document}
As shown by \citet{author}, using references can be interesting

\newpage
\AtBeginShipout{%
\AtBeginShipoutDiscard
}
\bibliographystyle{apalike}
\bibliography{testttt}
\end{document}

However, if the page numbers need to be continuous, it is better to use pdfpages as suggested by cfr.

2
  • This method works the best for my workflow. Thanks
    – Aditya
    Jan 26, 2015 at 4:26
  • @Aditya Glad it worked. You are welcome :)
    – user11232
    Jan 26, 2015 at 5:01
3

Perhaps the simplest way is to compile the PDF normally and then use 2 wrappers with pdfpages to produce the 2 PDFs. The following assumes that your main article is main.tex and so produces main.pdf when compiled:

\begin{filecontents}{\jobname.bib}
  @ARTICLE{author,
    title={A sample article},
    author={Random Author},
    journal={Random journal},
    volume = {10},
    year = {2000},
  }
\end{filecontents}
\begin{filecontents}{body.tex}
  \documentclass{article}
  \usepackage{pdfpages}
  \begin{document}
  \includepdf[pages=1]{main}
\end{document}
\end{filecontents}
\begin{filecontents}{biblio.tex}
  \documentclass{article}
  \usepackage{pdfpages}
  \begin{document}
  \includepdf[pages=2]{main}
\end{document}
\end{filecontents}

\documentclass{article}
\usepackage{natbib}

\begin{document}
As shown by \citet{author}, using references can be interesting

\newpage
\pagenumbering{arabic}% comment out for continuous numbering
\bibliographystyle{apalike}
\bibliography{\jobname}
\end{document}

Here is the body:

body

and references:

biblio

0
1

Here's the bones of one way, which could be optimized with a simple Makefile.

I would've thought it would work with the --jobname= switch, but this seems to make it try to load the new jobname .aux file. So, instead, you can use --output-directory= to dump the new file sans bibliography there.

% filename.tex
\RequirePackage{etoolbox}% <-- to make the command line stuff more readable
\providebool{NObib}
% \newif\ifNObib
% \NObibtrue

\ifNObib
 \def\printthebib{\relax}
\else
  \def\printthebib{\newpage\bibliographystyle{apalike}\bibliography{\jobname}}
\fi

\begin{filecontents}{\jobname.bib}
  @ARTICLE{author,
    title={A sample article},
    author={Random Author},
    journal={Random journal},
    volume = {10},
    year = {2000},
  }
\end{filecontents}

\documentclass{article}
\usepackage{natbib}

\begin{document}
As shown by \citet{author}, using references can be interesting

% \newpage
% \bibliographystyle{apalike}
% \bibliography{\jobname}
\printthebib
\end{document}

Compile as normal. When you want to produce the two files, use:

pdflatex filename.tex && pdflatex --output-directory=nobibdir "\newif\ifNObib\NObibtrue\input{filename}"

(Where nobibdir is the subdirectory you created. The no-bib version of the PDF will be put there.)

One word of warning: you must remove the .aux file generated in the output directory. Otherwise, on a subsequent run, the bibliographic information will be lost. Maybe something like:

pdflatex filename.tex && pdflatex --output-directory=nobibdir "\newif\ifNObib\NObibtrue\input{filename}" && rm -v nobibdir/filename.aux
2
  • Thanks for the detailed reply. It was a toss up between your solution and that proposed by Harish Kumar. The other solution works better simply because I can create two files in the same directory.
    – Aditya
    Jan 26, 2015 at 4:28
  • No problem. When I was still sure --jobname would get the job done, I liked the answer more. I thought about a Makefile that would then mv the file back into the working directory, but it started to feel like a Rube Goldberg machine....
    – jon
    Jan 26, 2015 at 4:48

You must log in to answer this question.

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