3

Consider the following latexmkrc configuration file (say latexmkrc.tex) containing a custom dependency which is supposed to run the texindy subroutine whenever a .ind file is out-of-date with respect to the corresponding source file:

# $makeindex = 'texindy'; #$

add_cus_dep('idx', 'ind', 0, 'texindy');
sub texindy{
    system("texindy \"$_[0].idx\""); #$
}

$pdf_mode = 1; #$

Now, consider a .tex file (say test.tex) processed with:

latexmk -g -norc -r latexmkrc.tex test

where:

  • -g option to force latexmk to process the document fully (just for the example),
  • -norc option just to be sure no other latexmk configuration file than latexmkrc.tex is taken in account.

Then, the following happens:

  1. Running pdflatex -recorder "test.tex".
  2. Running makeindex -o "test.ind" "test.idx".
  3. Running pdflatex -recorder "test.tex".

The trouble is with step #2, latexmk creating a new rule:

=== Creating rule for 'cusdep idx ind test'
Latexmk: applying rule 'makeindex test.idx'...
Rule 'makeindex test.idx': File changes, etc:
   Non-existent destination files:
      'test.ind'
------------
Run number 1 of rule 'makeindex test.idx'
------------
------------
Running 'makeindex  -o "test.ind" "test.idx"'

ignoring the custom dependency and subroutine in latexmkrc.tex that is supposed to lead to: texindy -o "test.ind" "test.idx" instead.

As a workaround, one could comment out the line

# $makeindex = 'texindy'; #$

in latexmkrc.tex but I'm still puzzled: why latexmk does ignore my (index) custom dependency and subroutine?

Minimal complete example:

\documentclass{article}
\usepackage[xindy]{imakeidx}
\usepackage{filecontents}

\makeindex

\begin{filecontents*}{latexmkrc}
# $makeindex = 'texindy'; #$

add_cus_dep('idx', 'ind', 0, 'texindy');
sub texindy{
    system("texindy \"$_[0].idx\""); #$
}

$pdf_mode = 1; #$
\end{filecontents*}

\begin{document}
Foo\index{Foo}
\printindex
\end{document}
Denis Bitouzé
  • 9,652
  • 4
  • 27
  • 85
  • Do you mean "uncomment" the line? I think the reason is that latexmk already has a rule for converting .idx files to .ind, so it doesn't consider the "new" rule. (See this answer to a similar problem I had a few years ago, but where only the input extension was the same: http://tex.stackexchange.com/a/37730/9517 ) – T. Verron Oct 21 '16 at 13:12
  • @T.Verron Doesn't "comment out" means "uncomment": sorry if I am wrong (my globbish needs to be polished :) I am suspecting what you guess but, even if the latexmk's rule is first deleted by remove_cus_dep('idx', 'ind');, the trouble still occurs. – Denis Bitouzé Oct 21 '16 at 13:18
  • 3
    For me "comment out" means "comment instead of deleting", but I don't know. As for remove_cus_dep, I don't think built-in rules are cus_deps. – T. Verron Oct 21 '16 at 13:49
  • @T.Verron Outch! The Perl code in the answer to your question is beyond my competence :) – Denis Bitouzé Oct 21 '16 at 14:21
  • The point was just the initial remark. ;) This answer evolved a lot due to follow-up questions by other commenters, the version of that code in my .latexmkrc is just 3 lines long. – T. Verron Oct 21 '16 at 14:28
  • @T.Verron What are these 3 lines? – Denis Bitouzé Oct 21 '16 at 14:32
  • 1
    More or less the same I had written in the question. My problem was really only with the extensions. Anyway, your problem is much easier to solve, since latexmk provides this makeindex variable. – T. Verron Oct 21 '16 at 14:54

1 Answers1

4

You've got two rules for making an .ind file from an .idx file: the built-in makeindex rule and your custom dependency. Latexmk has to choose which. The way it's programmed, it finds the built-in rule first, so that's what get used.

As you've noticed, to use texindy you need to redefine $makeindex, either by

$makeindex = 'texindy';

or (slightly better) by

$makeindex = 'texindy %O -o %D %S';
John Collins
  • 11,183
  • 3
  • 32
  • 33
  • 1
    slightly off-topic: is there a way to customize $makeindex without a latexmkrc file, from command line only ? –  Oct 23 '16 at 14:11
  • 2
    See the documentation about option -e, which executes Perl initialization code. You can use it to make an assignment to $makeindex. – John Collins Oct 24 '16 at 19:58
  • ok, I had not read enough. Do you think -e "\$makeindex=q/makeindex -s foo.ist %O -o %D %S/" has any chance to work cross-platform ? it works on my mac os x (I actually use \$$makeindex because this is in a Makefile variable), but I have no idea about Windows. (I know I am getting even more off-topic, and don't feel in any way like you need to answer). Not knowing for sure I think I will go for the latexmkrc way nevertheless (hoping I don't have to worry about the endline character of my single line). –  Oct 24 '16 at 21:46
  • I am pretty sure it won't work cross platform. In Windows, $ is not a special character (IIRC), so it won't need to be escaped. But % is, and it is escaped by doubling it. Don't forget latexmk's -r option that reads a named initialization file. – John Collins Oct 24 '16 at 22:48