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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a book which will include and explain a handful of different memoir page layouts.

Setting the scene

In the book, I want to imbed thumbnails of pages from PDFs generated with the page layouts, which I'm successfully doing with \includegraphics[...]{<pdfname>}.

The top-level document, ''mlayout.tex'', then, includes pages from a series of PDFs, called ''mlayout-a'', ''mlayout-b'', etc.

At the next level, the documents (''mlayout-a.tex'' etc) set the style (a,b,c...) in a couple of lines, and end with \input{mlayout-text}

''mlayout-text.tex'' contains the lipsum stuff. I need to illustrate some specific things like \marginpars that lipsum or blindtext can't do for me, so that's why I use this third-level file.

The problem

This nesting of dependencies seems to demand latexmk; if I change mlayout-text.tex, it will (I hope) enable me simply to reprocess mlayout.tex and thereby regenerate, automatically, all the intermediate PDFs.

The first try, with no modifications to latexmkrc, didn't attempt to produce the intermediate PDFs, so I added a custom dependency to latexmkrc:

add_cus_dep('tex', 'pdf', 0, 'maketex2pdf');
sub maketex2pdf {
    system("latexmk -pdf $_[0]");

But, as far as I can tell, it still doesn't detect changes to the lowest-level file (mlayout-text).

What am I doing wrong?

Note: I haven't included an MWE (to save a lot of space and a fair amount of time); if you think the question needs one, please comment and I'll add a custom-made (i.e. small) one.

share|improve this question
Since you have not had much luck with getting an answer, perhaps including a MWE might help. I for one am very interested in the solution to this. – Peter Grill Oct 15 '11 at 4:55
Bit bogged down elsewhere at the moment, but I'll work on it (the devil is in the "M"). – Brent.Longborough Oct 15 '11 at 11:36
up vote 5 down vote accepted

You are doing nothing wrong. Internally, latexmk generates a custom dependency with a single source file, and doesn't have a built-in method of finding other source files. The recursively called latexmk does have this information, but doesn't propagate it back to the caller. But you can obtain this information by a bit of trickery using the internal subroutines of latexmk. In the latexmkrc file, change the definition of maketex2pdf to

sub maketex2pdf {

    # Make pdf file from tex file, recording dependencies
    my $dep_file = "$_[0].dep";
    system("latexmk -pdf -deps -deps-out=$dep_file $_[0]");

    # Read the list of dependencies, which is in the
    #   format of a fragment of a makefile.
    # In the precise format written by latexmk, source filenames on a
    #   are each on a separate line starting with white space; these
    #   lines often end with a continuation character.
    my $fh = new FileHandle "< $dep_file";
    if (! defined $fh ) {
        warn "maketex2pdf: Cannot read '$dep_file'\n";
    while ( <$fh> ) {
        # Ignore comment lines:
        if ( /^\s*#/ ) { next; }
        if ( /^\s+(.*)$/ ) {
            # Line containing name of source file
            my $dep = $1;
            # Remove continuation character:
            $dep =~ s/\\$//;
            # Make sure this file is in the list of source files for the
            # current rule, by calling rdb_ensure_rule.  This is an 
            # internal latexmk subroutine.  The first argument to this
            # subroutine is $rule, which is a global variable that
            # indicates what rule is currently being processed.
            rdb_ensure_file( $rule, $dep );
    close $fh;
    return 0;

This worked on a MWE I constructed.

share|improve this answer
John, thanks, I'm sorry to have been so discourteous in failing to acknowledge your post, but I'm really bogged down in another project. I hope to get back to this before long, and then accept your answer. – Brent.Longborough Nov 3 '11 at 14:57

Your Answer


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.