BibTeX, biblatex and biberAutomatic BibTeX run on each included File

Information and discussion about BiBTeX - the bibliography tool for LaTeX documents.
Post Reply
nphaibk
Posts: 23
Joined: Fri Sep 19, 2008 4:34 pm

Automatic BibTeX run on each included File

Post by nphaibk »

This question should be for advanced users! It may be a bit long before you get the question.


Problem:
When using multiple bibliographies, e.g. for each chapter in a book, we use packages chapterbib, multibib, or bibunits and use \include{chapter1} \include{chapter2} etc... with \bibliography{<bib file>} inside each chapter file (chapter1.tex, chapter2.tex...).

This works well in WinEdt, but not others, tested with TeXMaker, TeXnicCenter, TeXStudio.

I have figured out that WinEdt run BibTeX several times, first on the main file, then on each chapter file. This correctly creates references on each chapters. In contrast, the other editors (TeXStudio...) compile BibTeX only on the main file, and cannot generate references for each chapter (the file inside \include).

Question:
My idea is to create a batch BibTeX run like in WinEdt for other editors (we can actually configure the compiling commands in these editors). How to do that?

This is just my idea, any better ideas are certainly appreciate.
Thanks
Last edited by cgnieder on Tue Dec 11, 2012 1:42 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
nphaibk
Posts: 23
Joined: Fri Sep 19, 2008 4:34 pm

Automatic BibTeX run on each included File

Post by nphaibk »

I solved this problem in TeXstudio (should be the same for TeXmaker), in four steps:
  1. Creating a batch script named "bibtexbat.bat" containing this.

    Code: Select all

    @ECHO off
    IF (%1)==() GOTO end
    
    FOR %%f in (%1\*.aux) DO bibtex %%f
    
    @ECHO on
    :end
  2. Then place this .bat file into folder bin (e.g. C:\Program Files\MiKTeX 2.9\miktex\bin\)
  3. In TeXstudio
    • Navigate to Options/Configure TexStudio
    • Navigate to Command tab (menu on left side), look for the line "bibtex" and replace the code there by

      Code: Select all

      "C:/Program Files/MiKTeX 2.9/miktex/bin/bibtexbat.bat" ?a
      (including the quotes). The path to "bibtexbat.bat" may be different in your case, you can select this file from the 'bib' folder where you have stored it (in step 2). The ?a must be there.
  4. When compiling, we need first to compile BibTeX, then PFDLaTeX (or PDFTeXify). If the references do not appear yet, compile again. You can configure a Build including those two steps easily in TexStudio
    • Navigate to Options/Configure TexStudio
    • Choose Build -> Add (bottom) -> the outer left button (of the three on right side) -> choose BibTeX, PDFTeXify, and maybe PDF viewer.
You can also assign a shortcut for this action (figure out your self in Options)


Note:
The batch file compile all .aux files in the current folder including some unnecessary ones, e.g. of others chapters which are cancelled out. This may slow down the compiling process, thus, you can clean up the auxiliary files (Tools -> Clean Auxiliary files).
Last edited by cgnieder on Tue Dec 11, 2012 11:25 am, edited 1 time in total.
benibela
Posts: 97
Joined: Thu Aug 09, 2007 8:13 pm

Automatic BibTeX run on each included File

Post by benibela »

nphaibk wrote:I solved this problem in TexStudio (should be the same for TexMaker), in four steps:
Really? That's way too complicated for Texstudio.

It should bibtex-compile all aux files with the command:

Code: Select all

bibtex ?a*.aux
?a means that it should look for the aux files in the current (absolute) directory
nphaibk
Posts: 23
Joined: Fri Sep 19, 2008 4:34 pm

Automatic BibTeX run on each included File

Post by nphaibk »

benibela wrote:Really? That's way too complicated for Texstudio.

It should bibtex-compile all aux files with the command:

Code: Select all

bibtex ?a*.aux
?a means that it should look for the aux files in the current (absolute) directory
Thanks, looks wonderful. Did you try yourself? It did not work for me.

I also know that bibtex require only and only ONE parameter (i.e. one aux file) at a time. Here we need to compile the aux of the main file, then each chapter. Also, for TexStudio '*' does not mean 'every' like in DOS.
benibela
Posts: 97
Joined: Thu Aug 09, 2007 8:13 pm

Automatic BibTeX run on each included File

Post by benibela »

nphaibk wrote: Thanks, looks wonderful. Did you try yourself? It did not work for me.

I also know that bibtex require only and only ONE parameter (i.e. one aux file) at a time. Here we need to compile the aux of the main file, then each chapter. Also, for TexStudio '*' does not mean 'every' like in DOS.
I tried it on Linux, does not seem to work as it is on Windows.

However

Code: Select all

bibtex ?a*/*.aux
works there.

(bug 1: needs a slash in the file name, bug 2: everything before the last slash is ignored)


edit: very strange, I tested ?a*.aux again and it did NOT work. Perhaps I had only tested if bibtex is called for each aux file (which it is), not if it actually creates the bibliography (which it does not, since it seems not to be able to handle absolute filenames)
Last edited by benibela on Thu Dec 13, 2012 2:37 pm, edited 1 time in total.
nphaibk
Posts: 23
Joined: Fri Sep 19, 2008 4:34 pm

Automatic BibTeX run on each included File

Post by nphaibk »

benibela wrote:
nphaibk wrote: Thanks, looks wonderful. Did you try yourself? It did not work for me.

I also know that bibtex require only and only ONE parameter (i.e. one aux file) at a time. Here we need to compile the aux of the main file, then each chapter. Also, for TexStudio '*' does not mean 'every' like in DOS.
I tried it on Linux, does not seem to work as it is on Windows.

However

Code: Select all

bibtex ?a*/*.aux
works there.

(bug 1: needs a slash in the file name, bug 2: everything before the last slash is ignored)
Love it :D worked like a charm!
I actually tried ?a*.aux before you suggested, but forgot '/' either.
nphaibk
Posts: 23
Joined: Fri Sep 19, 2008 4:34 pm

Re: Automatic BibTeX run on each included File

Post by nphaibk »

Hello again,

With the suggested solution, my thesis went smoothly, however, I got an error

'bibtex needs exactly one argument'

when compiling normal documents. I mean with 1 bibliography for entire document. I have to change back to '%.aux'

Could somebody help to find a configuration that works in both cases (normal bib and sectionbib)

Thanks
Post Reply