# Problem using bibunits

I am trying to use bibunits package. If I compile the TeX file using the following sequence of commands, it works properly.

pdflatex document
bibtex bu1
pdflatex document
pdflatex document


However, if I compile it using TeXstudio 2.8.8, TeXstudio fails to recognize bibtex entries inside the bibunit. Here is a minimal example.

\documentclass{article}
\usepackage{bibunits}
\usepackage{filecontents}
\begin{filecontents}{mybib.bib}
@ARTICLE{Meyer2000,
AUTHOR="Bernd Meyer",
TITLE="A constraint-based framework for diagrammatic reasoning",
JOURNAL="Applied Artificial Intelligence",
VOLUME= "14",
ISSUE = "4",
PAGES= "327--344",
YEAR=2000
}
@ARTICLE{Codishetal2000,
AUTHOR="M. Codish and K. Marriott and C.K. Taboch",
TITLE="Improving program analyses by structure untupling",
JOURNAL="Journal of Logic Programming",
VOLUME= ""43",
ISSUE = "3",
PAGES= "251--263",
YEAR=2000
}
\end{filecontents}
\begin{document}
\begin{bibunit}[plain]
References to the \TeX book \cite{Meyer2000}
and to Lamport’s \LaTeX\ book, which appears
only in the references\nocite{Codishetal2000}.
\putbib[mybib]
\end{bibunit}
\end{document}

• bibunits wants you to run bibtex bu1.aux (1 for the 'first' BibUnit); are you sure you're running it? As a matter of taste: I'd put the filecontents in the preamble, too; and have no space before \end{filecontents}.
– jon
Feb 13 '15 at 3:22
• I updated the question. If I compile the above doc using command-line it works; however, TeXstudio cannot compile it. Feb 13 '15 at 3:34
• As a matter of fact, I realized that TeXstudio does not run bibtex bu1. I don't know why. Feb 13 '15 at 3:44
• I presume that's because it is not a 'normal' command for TeXstudio to know to run. (Never used the editor, so I don't know how clever it is.)
– jon
Feb 13 '15 at 3:49
• Can you open a command window from inside TeXStudio and type "bibtex bubu1" at the command prompt?
– Mico
Feb 13 '15 at 5:22

Old question, but exactly my problem. I don't know much about TeXstudio, but I put together a hack to get it to work. There must be a better way. Somebody please post it.

1. Go to Options->Configure TeXstudio...
2. Select Commands from the options on the left
3. Scroll to BibTeX
4. Update the BibTeX command as described below

The default command should be "bibtex.exe %", which apparently runs bibtex on the main filename (without the extension). I added a list of executions of bibtex on bu# where # is a number from 1 to 9.

So the BibTeX command now looks like:

bibtex.exe % | bibtex.exe bu1 | bibtex.exe bu2 | bibtex.exe bu3 | bibtex.exe bu4 | bibtex.exe bu5 | bibtex.exe bu6 | bibtex.exe bu7 | bibtex.exe bu8 | bibtex.exe bu9


FYI, I am running TeXstudio 2.8.4 on Windows 7

Like I said, a hack. But it seems to work.

Edit: I'm guessing TeXstudio does conditional "recompiles" of the bibliography based on whether it thinks there has been a change. I'm also guessing that it doesn't detect changes well with bibunits. Therefore, I've had to do (at least) three TeXstudio steps when using this hack. First, recompile main tex file. Second, recompile bib file (f11). Third, recompile main tex file again.

• You're a life saver! Oct 1 '19 at 18:50
• How about if someone is using overleaf? Nov 7 '20 at 15:14

Change

bibtex.exe %


to

bibtex ?a*/*.aux


in

Options - Configure TeXstudio - Commands - BibTeX.

Source. Compile order: F6, F11, F6, F11, F6, F12, F1.

To add to Claudio Fiandrino's answer, I had some problems due to my path to the working directory having a space in it and so I was getting errors saying that Bibtex needed exactly one argument. I found that changing it to the following worked:

bibtex ?me*/*.aux


The '?m' uses the double-quoted filename without extension, and the 'e' adds the file extension.

(I would have added this as a comment but don't have enough reputation).

For using bibunits with Texstudio under Linux (Texstudio 2.12.22 in my case), I do the following:

1. Options -> Configure TeXstudio...

2. Select Build from the options on the left

3. Under user command, add the following command that implements the building procedure that is described in the bibunits documentation:

/PATH/TO/SCRIPT/latex_bibunits.sh %.tex | txs:///view


With the bash script latex_bibunits.sh containing:

#!/bin/bash
FILE=$1 pdflatex$FILE
buFiles=$(ls bu*.aux) for f in${buFiles[@]}; do
bibtex $f done pdflatex$FILE
pdflatex \$FILE


Additionally, make sure that latex_bibunits.sh is executable, for example using chmod 755 latex_bibunits.sh.