Here's an appropriate insertion for the latexmkrc
file.
$pdflatex = 'internal musixlatex %R %O %S';
push @generated_exts,"mx2";
push @generated_exts,"mx1";
sub musixlatex {
my $root = shift;
# Define root filename for the mx1 and mx2 files
# Note that $aux_dir1 includes directory separator
# and it equals $out_dir1 if only the out_dir is set.
my $mx = "$aux_dir1$root";
my @args = @_;
if ( $pass{$rule} <= 1 ) {
print "======= FIRST PASS: Deleting '$mx.mx2' =======\n";
unlink "$mx.mx2";
print "==== Generating '$mx.mx1' then '$mx.mx2' ===\n";
my $ret = system( "pdflatex @args" );
if ($ret) { return $ret; }
$ret = system( "musixflx $mx" );
if ($ret) { return $ret; }
}
return system( "pdflatex @args" );
}
The main thing is that it is necessary to delete the .mx2
file before running pdflatex
for the first time. Then musixflx
is run to generate a new mx2
file, and then pdflatex
again.
But sometimes more than two passes through pdflatex
are needed to resolve cross references and the like. So I've used a bit of trickery with an internal variable of latexmk
so that the use of musixflx
only happens on the first pass; this keeps the number of runs of pdflatex
to the minimum.
latexmk -pdf -pdflatex="pdflatex %S; musixflx %S; pdflatex %S"
. But I havent tested that, its just what came to mind skimming over the manualmx2
file before the first run ofpdflatex
. With that change, your solution would work. See my answer for an improvement.