6

I'm working on getting exceltex and latexmk communicating by adding custom dependencies to .latexmkrc.

As far as I understand, exceltex works by writing an entry for each \inctab/inccell command to an excltx file upon compilation, and the using the Perl script Spreadsheet::ParseExcel to extract information from the .xls file. The manual routine: latexmk, exceltex, latexmk, and it works. So I believe I need the following dependency relations:

  1. excltex and xls: if the xls file is changed, exceltex is invoked.
  2. excltex and tex: if the tex file with \inccell/\inctab calls changes, exceltex is invoked.

As I have understood, latexmk doesn't handle multiple files in one dependency, so I first focused on getting #2 working. I have tried:

add_cus_dep('excltx', 'tex', 0, 'excel2tex');
    sub excel2tex {
        system("exceltex \"$_[0].tex\"") ;
    }

which makes latexmk generate the following output:

For rule 'cusdep excltx tex test', running '&do_cusdep(  )' ...
Latexmk: Possible misconfiguration or bug:
  In trying to apply custom-dependency rule
  to make 'test.tex' from 'test.excltx'
  the function name is blank.

My intention is that the dependency will trigger exceltex file.tex. Why doesn't this happen? How can I change my dependency such that it will run exceltex?

Follow up: Assuming the above dependency works (which it does after commenting out all other dependencies in .latexmkrc, running latexmk and uncommenting the pacified dependencies), how can I make latexmk run exceltex when the xls file is changed? I have tried with

add_cus_dep('tex', 'xls', 0, 'excel2tex');

and

add_cus_dep('excltx', 'xls', 0, 'excel2tex'); 

(and both, for good measure). It works if I force a complete recompilation. With a normal compilation, where the content of the tex document is untouched but the xls file is changed, latexmk refuses to notice a change in just the xls file.

4
  • Updated question! And here: physik.uni-freiburg.de/~doerr/exceltex/index.en.html#probs – Holene Apr 9 '13 at 17:04
  • 1
    With your definitions, it should work. However, in the output listing, I see &do_cusdep( ) reported, whereas it should be &do_cusdep( excel2tex ) given your custom dependency's definition. Here are some possibilities: (a) The code in latexmkrc is not identical to the code in the question. (b) Something else in one of your latexmkrc files messes with the relevant latexmk internals. (c) Your latexmk is not a standard one. (d) A bug in latexmk, although I cannot reproduce it. What happens if the custom dependency is the only thing in any of the latexmkrc files? – John Collins Apr 10 '13 at 16:25
  • @JohnCollins I have two other dependencies, the gnuplot dependency and an nomencl dependency. Commenting out all dependencies and running latexmk made the excel2tex dependency run. Afterwords I made sure that my other dependencies still work. Dafuq? – Holene Apr 12 '13 at 7:34
  • 1
    @Holene This is quite strange. It might be best to debug the problem off-line, and then report the results here. My e-mail is in the latexmk documentation. Send a minimal example that shows the problem (complete latexmkrc files and tex files), and we can take it from there. – John Collins Apr 12 '13 at 14:05
4

Since the difficulty about a "Possible misconfiguration or bug" cannot now be reproduced, we can ignore that part of the question for the moment. I'll answer the rest of the question, which is how to make a custom dependency that will be run if the xls file changes. Here is a suitable tested code for a latexmkrc file:

add_cus_dep('excltx', 'tex', 0, 'excel2tex');
sub excel2tex {
    # First find dependency/ies on .xls files, by parsing the .excltx file,
    my $Hsource = new FileHandle;
    my %xls = ();
    my $source = "$_[0].excltx";
    if (! open $Hsource, "<$source") {
        warn "excel2tex subroutine: Could not read '$source'\n";
        return 1;
    }
    while ( <$Hsource> ) {
        if ( /^\s*;/ ) { next; }
        if ( /^\s*[ct]:[^:]*\:([^!]*)!/ ) { $xls{$1} = 1; }
    }
    close $Hsource;
    foreach (keys %xls) {
        rdb_ensure_file( $rule, $_ );
    }
    return system("exceltex \"$_[0]\"") ;
}

The functioning is as follows: The main tex file uses the package exceltex to use the contents of cells in an xls spreadsheet. It does this by writing a specification of the cells to a file with extension excltx. The script exceltex reads this, extracts the data from the spreadsheet(s), and writes them in files that are read during the next compilation of the main document. (The exceltex package, with its script, is part of the current version of TeXLive.)

In addition to running the exceltex script, the subroutine defined above also reads the excltx file to find the names of the spreadsheet files used. It then uses an internal subroutine of latexmk to add these files to the source-file list of the custom dependency. Thus if the spreadsheet file (or files) changes even without any other changes, latexmk will know to rerun exceltex and then recompile the main tex file if necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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