From c5a2b996ae14f24d174cd68b44fb854752961036 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Tue, 15 Sep 2020 03:02:49 +0000 Subject: CTAN sync 202009150302 --- .../latexmk/example_rcfiles/chapterbib-latexmkrc | 71 ++++++++++++++++++++++ support/latexmk/example_rcfiles/fix-aux.latexmkrc | 20 ++++-- 2 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 support/latexmk/example_rcfiles/chapterbib-latexmkrc (limited to 'support/latexmk/example_rcfiles') diff --git a/support/latexmk/example_rcfiles/chapterbib-latexmkrc b/support/latexmk/example_rcfiles/chapterbib-latexmkrc new file mode 100644 index 0000000000..403cbd6ef5 --- /dev/null +++ b/support/latexmk/example_rcfiles/chapterbib-latexmkrc @@ -0,0 +1,71 @@ +# This file gives a configuration suitable when chapterbib is being used. +# Latexmk without special configuration works with chapterbib only if +# chapter bibliographies are used, but not when an overall consolidated +# document-level bibliography is used. (This is because one of the runs of +# bibtex gives an error of a kind that causes latexmk to stop further +# processing. The chapterbib documentation mentions this problem +# explicitly and says the error is to be ignored.) + +# The configuration in this file allows the use of a document level +# bibliographys without any errors. It works equally when there is no +# document level bibliography and when chapterbib is not used. + + +$bibtex = 'bibtex %O %S'; +$bibtex_save = $bibtex; +$bibtex = 'internal bibtex_fix %R %D %S'; + +# MUST NOT use bibtex_fudge (i.e., change of directory before running bibtex). +# That's not needed in post-2019 versions of bibtex, and messes up +# things with chapterbib. So turn it off: +$bibtex_fudge = 0; + +$clean_ext .= " %R-mod.blg %R-mod.aux %R-mod.bbl"; + +sub bibtex_fix { + my ($root, $dest, $source) = @_; + local ($base_tex, $path, $ext) = fileparse( $source, '\.[^\.]*' ); + my $ret = 0; + if ( $base_tex eq $root ) { + print "--- Will run bibtex on modified '$root.aux' file\n"; + my $aux_mod_base = $path.$base_tex."-mod"; + local $out_fh = new FileHandle "> $aux_mod_base$ext"; + if (!$out_fh) { die "Cannot write to '$aux_mod_base$ext'\n"; } + local $level = 0; + fix_aux( $source ); + close $out_fh; + $ret = Run_subst( $bibtex_save, 2, undef, "$aux_mod_base.aux", undef, $aux_mod_base ); + foreach ( 'bbl', 'blg' ) { + copy "$aux_mod_base.$_", "$path$root.$_"; + } + } + else { + $ret = Run_subst( $bibtex_save ); + } + return $ret; +} + +sub fix_aux { + # Read aux file, outputting flattened version to file handle $out_fh and + # removing \bibdata and \bibstyle lines that were in included .aux files. + my $aux_file = $_[0]; + print "Processing '$aux_file'\n"; + my $aux_fh = new FileHandle $aux_file; + if (!$aux_fh) { die "$My_name: Couldn't read aux file '$aux_file'\n"; } + $level++; + while (<$aux_fh>) { + if ( ($level > 1) && + ( /^\\bibdata\{(.*)\}/ || /^\\bibstyle\{(.*)\}/ ) + ) + { next; } + elsif ( /^\\\@input\{(.*)\}/ ) { + fix_aux( $path.$1 ); + next; + } + else { + print $out_fh $_; + } + } + close($aux_fh); + $level--; +} diff --git a/support/latexmk/example_rcfiles/fix-aux.latexmkrc b/support/latexmk/example_rcfiles/fix-aux.latexmkrc index 9b01210a14..aefa206d5a 100644 --- a/support/latexmk/example_rcfiles/fix-aux.latexmkrc +++ b/support/latexmk/example_rcfiles/fix-aux.latexmkrc @@ -28,8 +28,8 @@ sub latex_fix_aux { # command line. # 3. Run the command. # 4. If the aux and output directories are different, move any of the dvi, - # fls, ps and pdf files that are present in the intended aux directory - # to the intended output directory. + # fls, pdf, ps and synctex.gz files that are present in the intended aux + # directory to the intended output directory. # N.B. It might seem more appropriate to keep the fls file in the aux # directory. But MiKTeX puts it in the output directory, so we must do # the same to copy its behavior. @@ -37,6 +37,8 @@ sub latex_fix_aux { # directory, like a dvi file. But xelatex under MiKTeX puts it in the # aux directory, so we must copy that behavior. + my @move_exts = ('dvi', 'fls', 'pdf', 'ps', 'synctex.gz' ); + # Determine aux and output directories from command line: my $auxD = ''; my $outD = ''; @@ -85,9 +87,17 @@ sub latex_fix_aux { print "Running: '@args_act'\n"; my $ret = system @args_act; if ($auxD ne $outD) { - print "Moving dvi, fls, ps, pdf files from '$auxD' to '$outD'\n"; - foreach my $ext ('dvi', 'fls', 'ps', 'pdf' ) { - rename "$auxD1$root_filename.$ext", "$outD1$root_filename.$ext",; + print "Move @move_exts files from '$auxD' to '$outD'\n"; + # Use copy and unlink, not rename, since some viewers appear to keep the + # viewed file open. So if rename were used, such viewers would see the + # old version of the file, rather than the new one. With copy, the + # contents of the old file are normally overwritten by the new contents. + # + # In addition, copy works across file system boundaries, but rename + # doesn't. + foreach my $ext (@move_exts) { + copy "$auxD1$root_filename.$ext", "$outD1$root_filename.$ext"; + unlink "$auxD1$root_filename.$ext"; } } return $ret; -- cgit v1.2.3