shiblon / latex-makefile

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

Support for the pdfpages package #189

Closed llbit closed 6 years ago

llbit commented 6 years ago

I'm currently working on a large document that consists of several pdfs glued together with the pdfpages package. I'd like the main document and all included documents to be compiled by a single Makefile, but it does not work as I want it to:

Makefile
main.tex
frontpage.tex

Inside main.tex, I have:

\includepdf[pages=-,offset=16mm 0mm]{frontpage.pdf}

If I try to build everything from scratch I get the following error:

= refs.bib main.aux --> main.bbl =
./main.tex:263: Package pdfpages Error: Cannot find file `frontpage.pdf'.

If I keep a copy of frontpage.pdf and add it to the neverclean variable, then I end up in an infinite loop rebuilding frontpage.pdf constantly.

Is there any way to get this to work, or do I have to split it up into separate builds?

Edit: I tried with latex-makefile 2.2.1-alpha9 and 2.2.1-alpha10

shiblon commented 6 years ago

Hey, thanks for leaving a note here. I think for your use case, you will indeed need to just do multiple builds. Even so, the Makefile should be able to help you with the individual builds. You can create a Makefile.ini in the same directory that has a rule for your overall document, that uses make to build the various pieces. So, perhaps something like this:

# In Makefile.ini

mydocument.pdf: main.tex frontpage.pdf otherpage.pdf
  make frontpage.pdf
  make otherpage.pdf
  make main.pdf

There are a lot of cases that are super hard for the Makefile to tease out from logs, and this looks like one of them, so it's probably best to just add your own custom rule in Makefile.ini this way. The Makefile will include your file and you should still be able to do everything using a single make command. Hopefully. Fingers crossed.

llbit commented 6 years ago

Thank you for the suggestion! It works very nicely. However, I noticed that each time I do make clean; make everything, frontpage.pdf is compiled twice. It's not a big deal, but it seems unnecessary. This is my current Makefile.ini (I moved frontpage.tex into a subdirectory):

everything: main.tex sections/frontpage.pdf
        make sections/frontpage.pdf
        make main.pdf

Is there some way I could make the everything target be the default target?

shiblon commented 6 years ago

Oops, I'm afraid that's my fault. I led you astray with make syntax. There is no need to "make sections/frontpage.pdf" since it's already in the dependency list. So, your rule can be simplified:

everything: main.tex sections/frontpage.pdf make main.pdf

The problem with this is that if main.tex pulls in any dependencies of its own (other than the other .pdf files), those will also need to be added to trigger a rebuild of "everything".

Don't forgot to use .PHONY:

.PHONY: everything everything: main.tex sections/frontpage.pdf make main.pdf

:)

llbit commented 6 years ago

Okay, I updated my Makefile.ini as you suggested. It works fine (it still compiles frontpage.pdf twice).

It seems like the build gets stuck in an infinite loop (constantly rebuilding frontpage.pdf) if I just run make without arguments, but make everything is what I'm doing now.

shiblon commented 6 years ago

Cool. I'm still somewhat mystified about what triggers those weird loopy build cases, but I'm glad you have a working setup now!

llbit commented 6 years ago

Thanks for the help!