On several occations I have read instructions like "run Latex on your file, then run Bibtex, and afterwards run Latex again..." . I am using TeXstudio as editor and when compiling any tex-code I simply press the compile-button. What happens behind this did not matter to me as the pdf I wanted was created anyway. Now that I am using .bib
files for referencing, I am having a problem where the solution to this was the same as above. But how do I do it? I only know the compile-button. How can I run Latex individually from Bibtex and Bibtex individually from Latex? And which of both is running when simply pressing "compile"?
6 Answers
The 'compile' button is running a default compilation sequence. It sounds as if this is probably pdfLaTeX in your case. (You can probably change this if you wanted - many editors allow you to customise the default.)
To generate your bibliography, you need to look at what is in your document. How are you managing references? If you use commands such as
\bibliographystyle{stylename}
\bibliography{bibfilename}
Then you need to run
pdflatex
->bibtex
->pdflatex
->pdflatex
If you have something like this:
\usepackage{biblatex}
\addbibresource{bibfilename.bib}% or \bibliography{bibfilename}
...
\printbibliography
Then you need to run
pdflatex
->biber
->pdflatex
->pdflatex
It is possible to use bibtex
with biblatex
but it is not default. Unless you have
\usepackage[backend=bibtex]{biblatex}
you don't need to worry about this. If you do use this option, you would use the bibtex
compilation sequence above rather than the biber
one.
To run the compilations, you can either use the command line or your editor. Most editors have buttons or menus with options for non-default compilation. Even though pdfLaTeX is default, there is probably a button or menu option for bibTeX (and perhaps biber). You can probably customise things further to suit your work-flow.
-
If getting
file.aux
not found when usingpdflatex
, replace those calls withlatex
and callpdflatex
after you complete the sequence. May 1 at 18:16
Here's a trick I like to use:
Create a python script in the root directory of your project, called e.g.
compile_refs.py
and paste the following code into it:#!/usr/bin/python import subprocess, sys commands = [ ['pdflatex', sys.argv[1] + '.tex'], ['bibtex', sys.argv[1] + '.aux'], ['pdflatex', sys.argv[1] + '.tex'], ['pdflatex', sys.argv[1] + '.tex'] ] for c in commands: subprocess.call(c)
When you want to compile references you just run:
python compile_refs.py main_file_name
.
-
5
Here's a useful Makefile
you can use to automate the compiling process described in the answer by cfr:
DOCNAME=report
all: report
.PHONY: clean
report:
pdflatex $(DOCNAME).tex
bibtex $(DOCNAME).aux
pdflatex $(DOCNAME).tex
pdflatex $(DOCNAME).tex
view: report
open $(DOCNAME).pdf
clean:
rm *.blg *.bbl *.aux *.log
Just paste this into a file called Makefile
in the same directory as your main .tex file and replace report
in the variable definition DOCNAME=report
with whatever your file is named.
Then you can use this as follows:
make
ormake report
will create the PDF doc from the TeX sources.make view
will make the PDF if not already created and open it with your system default PDF viewer.make clean
will clean up the intermediate files created during PDF creation.
If you need to use biber
instead of bibtex
, you can just replace the call to bibtex
with a call to biber
.
A simple solution: latexmk. I can't say it works in all cases, but for some basic setting (thesis, paper), it works well.
Here is an example extracted from its man-doc (e.g. you have thesis.tex
in your current folder):
latexmk thesis
--> run latex enough times to resolve cross-references
latexmk -pvc -ps thesis
--> run latex enough times to resolve cross-references, make a postscript file, start a previewer. Then watch for changes in the source file thesis.tex and any files it uses. After any changes rerun latex the appropriate number of times and remake the postscript file. If latex encounters an error, latexmk will keep running, watching for source file changes.
latexmk -c
--> remove .aux, .log, .bbl, .blg, .dvi, .pdf, .ps & .bbl files
So with one command, we can make latexmk
works in the interactive mode, every change in .tex or event .bib file will be re-complied automatically. More detailed docuement here.
Building on the top answer, here's my simple script to do it for BibTex:
#!/bin/bash
BASE="${1%.*}"
pdflatex $BASE.tex
if [ $? -ne 0 ]; then
echo "Compilation error. Check log."
exit 1
fi
bibtex $BASE
pdflatex $BASE.tex
pdflatex $BASE.tex
exit 0
Which I run with ./latexcompile.sh mytexdoc
(note the lack of file extension).
Don't forget to do chmod +x latexcompile.sh
to make it executable!
IF YOU ARE USING TEXSTUDIO. Go To : settings --> compilations and run by waiting the excution of every step :
1 pdflatex. --> 2 bibtex . --> 3 pdflatex . --> 4 pdflatex .
biblatex
, you probably need to use biber. If you are usingbibtex
, you definitely need to use bibtex. [You can use bibtex withbiblatex
but it is not default.]\bibliographystyle{}
), then you need to do pdflatex -> bibtex -> pdflatex -> pdflatex. If you have written it usingbiblatex
(\usepackage{biblatex}
) then, by default, you need biber: pdflatex -> biber -> pdflatex. So what you use to compile in the second step depends on how you are managing things in your document.