0

I was given a project to build a thesis document which has a cover.tex and a main.tex. The cover.tex generates the necessary covers to comply with the institution's style. The main.tex file imports the pages from cover.tex with \includepdf[pages=-]{cover.pdf}.

Is there a way, using latexmk (which I'm already using for makeglossaries), to generate the cover PDF automatically when building the main document?

2
  • Welcome to TeX.SE!
    – Mensch
    Commented Apr 18, 2023 at 16:37
  • Use @default_files = ('cover', 'main'); in .latexmkrc to specify the order for generating files. Though alphabetic order is the default already. Commented Apr 19, 2023 at 12:54

2 Answers 2

2

Just define a custom dependency to invoke latexmk to make a .pdf file (such as cover.pdf) from the corresponding .tex file:

add_cus_dep( 'tex', 'pdf', 0, 'makeexternaldocument' );
sub makeexternaldocument {
    my ($base_name, $path) = fileparse( $_[0] );
    return system "latexmk", "-output-directory=$path", $_[0];
}

The only complication here was to ensure that latexmk puts the generated .pdf file is in the same directory as the .tex file, as required by the definition of a custom dependency.

0

Look into using a build automation tool such as GNU Make. A simple Makefile can look like

all: main.pdf

main.pdf: cover.pdf

%.pdf: %.tex
    latexmk -pdf $<

clean:
    latexmk -CA

Using the command make we build cover.pdf if needed and then main.pdf, each using the pattern rule %.pdf: %.tex to build the file using latexmk.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .