Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Background
Now that TeX Live 2010 has a restricted \write18, I figured it'd be reasonable to update my cv which uses the bibunits package to run BibTeX for each of the .aux files.

Currently, I have a macro \pubs that typesets a label and then the bibliography (\pubs is used inside a cvlist environment from currvita, but that is not important here).

\makeatletter
\newcommand*\pubs[2]{%
        \item[#1]
        \begin{bibunit}%
                \nocite{#2}%
                \putbib
        \end{bibunit}%
        \IfFileExists{\@bibunitname.bbl}{}
                {Run \texttt{bibtex \@bibunitname}}%
}
\makeatother

It is used like \pubs{Refereed papers}{foo,bar,baz} to typeset the bibliography entries corresponding to the citation keys foo, bar, and baz (or it prints a helpful message if BibTeX hasn't been run).

Question
How can I modify this to run bibtex \@bibunitname and then use the results in a sane way?

One idea I had that mostly works is

\makeatletter
\newcommand*\pubs[2]{%
        \item[#1]
        \begin{bibunit}%
                \nocite{#2}%
                \immediate\write\@bibunitaux{\string\bibdata{\bu@bibdata}}%
        \end{bibunit}%
        \immediate\write18{bibtex \@bibunitname}%
        \InputIfFileExists{\@bibunitname.bbl}{}
                {Run \texttt{bibtex \@bibunitname}}%
}
\makeatother

Here the \putbib has been replaced with a write of the \bibdata and \IfFileExists has become \InputIfFileExists. When run, this complains that all of my citations are undefined, but the output looks fine. In particular, all of the aux files are closed before they are read in from the \InputIfFileExists.

share|improve this question
1  
If your general aim is an easy workflow when compiling a LaTeX document with multiple bibliographies, you may want to switch from bibunits/bibtex to biblatex/biber. Since v0.5.4, biber will handle multiple bibliographies in a single pass. (And biber installation is now quite easy, as "ready" binaries for Linux, Windows and Mac are available.) –  lockstep Oct 24 '10 at 12:21
2  
@lockstep: I'm deleting all my comments, and have "archived" this discussion on meta. It might be nice if you deleted your comments (besides maybe the first); the meta thread is at meta.tex.stackexchange.com/questions/597/… –  Charles Stewart Oct 27 '10 at 10:19
    
Yet another non-answer: You might consider using rubber. I do not know about bibunits, but rubber works well with multibib. In particular, it does dependency-tracking correctly; for example, it runs Bibtex if *.bbl is older than your *.bib database. –  Jukka Suomela Oct 27 '10 at 11:16
add comment

2 Answers

After I wrote this answer I realised it's not exactly what you're trying to do. Ohwell Without looking into bibunits, my guess is that you need to wait until after the aux files are closed before you run bibtex. Here's a hack to do it for the main document class:

\documentclass{article}
\makeatletter
\let\end@doc@hook\@enddocumenthook
\def\@enddocumenthook#1\@@end{
  \end@doc@hook
  #1
  \immediate\write18{echo "^^J^^JCompiling bibliography with BibTeX:^^J" && bibtex \jobname && echo "^^JEnd BibTeX processing^^J"}
  \@@end
}
\makeatother
\begin{document}
\cite{whole-set}
\bibliographystyle{plain}
\bibliography{xampl}
\end{document}
share|improve this answer
add comment

As a big proponent of PerlTeX, I posted a blurb on another post which I am going to shamelessly quote here:

I know this isn't an answer to the question, but perhaps could help you with your problem. PerlTeX allows you to embed Perl code as a LaTeX function. When compiling if you use perltex --nosafe myfile.tex then the perl process has free reign to call system functions. I'm not sure if this could help your problem (because of an order of operations, though if \write18 would work at compile time then this should), but it is a way to get full access to your system as well as other benefits of using inline Perl code in your source.code in your source.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.