shiblon / latex-makefile

A Makefile for LaTeX - drop it in, type make, and magic happens.
Other
185 stars 30 forks source link

chapterbib package is not supported #150

Open shiblon opened 8 years ago

shiblon commented 8 years ago

Originally reported on Google Code with ID 137

The chapterbib package allows bibliographies for each chapter. When building with latex-makefile,
the bibliographies are not generated if each chapter is included from external files
into the main document. In addition, errors are generated with latex-makefile because
it runs bibtex on the main document.

I minimal example is attached. This example builds correctly with the following commands:

pdflatex test
bibtex ch1._include_
bibtex ch2._include_
pdflatex test
pdflatex test

I have also attached a quick hack that seems to cause latex-makefile to reliably build
this specific example by hard-coding the files that bibtex should run over.

It may be possible (but probably too slow) to automatically determine which files bibtex
needs to be run on by parsing the aux files. For example, the following command returns
that the two chapter files have bibliography data:
# fgrep bibdata *.aux
ch1._include_.aux:\bibdata{test}
ch2._include_.aux:\bibdata{test}

As Chris pointed out, there is also a similar issue: http://code.google.com/p/latex-makefile/issues/detail?id=103

Reported by russell@kliese.id.au on 2011-07-27 01:39:09


shiblon commented 8 years ago
Thanks for the minimal example.  I'm looking at this now.

Reported by shiblon on 2011-08-09 19:53:44

shiblon commented 8 years ago
This is somewhat tricky, but I think we can do it.

Let me be sure that I understand what is going on, first, though.

- Chapterbib is a misnomer

Because, it's really "included-file bib".  The bibliography is at the file level, not
necessarily the chapter level.  Fair enough.  So long as I understand it, that's what
matters.

- When *not* using chapterbib, we are to run bibtex on the main source .aux file, but

- When using chapterbib, we are to run bibtex on any .aux file *that contains bibdata
entries*, and *not* the main source .aux file.

- After that, latex compilation proceeds normally.

Is that a correct assessment?

Reported by shiblon on 2011-08-10 17:34:44

shiblon commented 8 years ago
You are right, chapterbib is a misnomer. Quoting from the documentation: "despite the
name ‘chapterbib’, the bibliographies are for each included file, not necessarily for
each chapter, although a bibliography per chapter is the usual application" [1].

Your assessment for using chapterbib is correct for the "normal usage". (After reading
the documentation, I found that it is possible to use the chapterbib package without
\include but rather using the cbunit environment. It sounds a bit too complicated to
implement in the Makefile because you need to first run latex in draft mode, run bibtex
on the various files and then remove draft mode and run latex again.)

[1] http://www.tug.org/texlive/Contents/live/texmf-dist/doc/latex/cite/chapterbib.pdf

Reported by russell@kliese.id.au on 2011-08-10 23:11:36

shiblon commented 8 years ago
The chapterbib documentation also allows bibliographies to be gathered to the end of
the document, and even duplicated in each chapter and at the end. In these cases, the
latex and bibtex commands are run as previously outlined (see 8 and 9 in chapterbib.pdf).

It is also possible to have a regular overall bibliography in the main file in addition
to the chapter bibliographies (see  7 in chapterbib.pdf). In this case, latex is run
first, then bibtex on the main source .aux file, then bibtex on the \included .aux
files, the latex again (twice).

I just thought I would alert you to these possible use cases in case a solution can
be made that easily supports them all.

Reported by russell@kliese.id.au on 2011-08-10 23:27:35