diff options
author | Karl Berry <karl@freefriends.org> | 2023-11-09 22:13:57 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2023-11-09 22:13:57 +0000 |
commit | e8dcef4eb9e70ed986b683df23cb2b278a121ae2 (patch) | |
tree | 7dda7a8b5120a1d6ee509bcaa3a4f295b061c2b6 | |
parent | 8fda739576093f019df0a4da907b38e7f591a328 (diff) |
latexmk (7nov23)
git-svn-id: svn://tug.org/texlive/trunk@68769 c570f23f-e606-0410-a88d-b1316a301751
14 files changed, 1238 insertions, 718 deletions
diff --git a/Build/source/texk/texlive/linked_scripts/latexmk/latexmk.pl b/Build/source/texk/texlive/linked_scripts/latexmk/latexmk.pl index 434da3529c6..9583f45a3fa 100755 --- a/Build/source/texk/texlive/linked_scripts/latexmk/latexmk.pl +++ b/Build/source/texk/texlive/linked_scripts/latexmk/latexmk.pl @@ -42,8 +42,8 @@ use warnings; $my_name = 'latexmk'; $My_name = 'Latexmk'; -$version_num = '4.80'; -$version_details = "$My_name, John Collins, 4 Apr. 2023. Version $version_num"; +$version_num = '4.81'; +$version_details = "$My_name, John Collins, 6 Nov. 2023. Version $version_num"; use Config; use File::Basename; @@ -82,7 +82,7 @@ use Cwd "chdir"; # Ensure $ENV{PWD} tracks cwd. use Digest::MD5; # **WARNING**: Don't import time; that overrides core function time(), and messes up -# +# somethings use Time::HiRes; ################################################# @@ -312,6 +312,7 @@ sub fprint8 { # v. pdflatexmk, etc): (our $invoked_name) = fileparseA($0); +# Save name, since I override it if I don't recognize it our $invoked_kind = $invoked_name; print "$My_name: Invoked as '$invoked_name'\n" if ($invoked_name ne 'latexmk'); @@ -360,6 +361,11 @@ else { # It is the parameter max_print_line in the TeX program. (tex.web) $log_wrap = 79; +# Expected biggest construct in log file in bytes. +# Use to limit number of (potentially) wrapped lines to combine into single line. +$max_log_construct = 600; + + ######################################################################### ## Default parsing and file-handling settings @@ -372,8 +378,8 @@ $log_wrap = 79; ## push @file_not_found, '^No data file found `([^\\\']*)\\\''; ## will give match to line starting "No data file found `filename'" @file_not_found = ( - '^No file\\s*(.*)\\.$', - '^No file\\s*(.+)\s*$', + '^No file\\s+(.*)\\.$', + '^No file\\s+(.+)\s*$', '^\\! LaTeX Error: File `([^\\\']*)\\\' not found\\.', '^\\! I can\\\'t find file `([^\\\']*)\\\'\\.', '.*?:\\d*: LaTeX Error: File `([^\\\']*)\\\' not found\\.', @@ -559,7 +565,7 @@ $input_extensions{xelatex} = $input_extensions{pdflatex}; # and because of the possibility of extra bibtex/biber rules with # non-standard basename. @generated_exts = ( 'aux', 'bcf', 'fls', 'idx', 'ind', 'lof', 'lot', - 'out', 'toc', + 'out', 'run.xml', 'toc', 'blg', 'ilg', 'log', 'xdv' ); @@ -1459,7 +1465,7 @@ our $times_are_clock = ($^O eq "MSWin32" ); # Data for 1 run and global (ending in '0'): -our ( $processing_time1, $processing_time0, @timings1, @timings0); +our ( $clock1, $processing_time1, $processing_time0, @timings1, @timings0); &init_timing_all; @@ -1913,8 +1919,21 @@ elsif ($HOME ne '') { %rc_files_read2 = (); # Map **abs** filename to 1; used to check duplicate reads. # Options that are to be obeyed before rc files are read: +# Also under MSWin32 and msys, CL arguments sometimes get quotes in them. +# (Specific example: TeXLive 2023 with msys's perl and arguments containing +# both non-ASCII character, when latexmk.exe invoked from cmd.exe. In some +# other situations (powershell and msys's terminal+bash), it seems that both +# space and non-ASCII character are needed to trigger a problem.) foreach $_ ( @ARGV ) { + if ( ($^O eq "MSWin32") || ($^O eq 'msys') ) { + # "arg" -> arg. + # -..="arg" -> -..=arg. + # In both cases, only do this if there are no other ". Otherwise I + # my run afoul of " that are intended to be there. + s/^\"([^\"]+)\"$/$1/; + s/^(-[^\"=]+=)\"([^\"]+)\"$/$1$2/; + } if (/^-{1,2}norc$/ ) { $auto_rc_use = 0; } @@ -2020,8 +2039,18 @@ while (defined($_ = $ARGV[0])) { elsif (/^-diagnostics/) { $diagnostics = 1; } elsif (/^-dir-report$/) { $aux_out_dir_report = 1; } elsif (/^-dir-report-$/) { $aux_out_dir_report = 0; } - elsif (/^-dvi$/) { $dvi_mode = 1; } - elsif (/^-dvilua$/) { $dvi_mode = 2; } + elsif (/^-dvi$/) { $dvi_mode = 1; + if ( ($pdf_mode != 2) && ($pdf_mode != 3) ) { + # if pdf_mode is not via dvi or pdf, turn it off + $pdf_mode = 0; + } + } + elsif (/^-dvilua$/) { $dvi_mode = 2; + if ( ($pdf_mode != 2) && ($pdf_mode != 3) ) { + # if pdf_mode is not via dvi or pdf, turn it off + $pdf_mode = 0; + } + } elsif (/^-dvi-$/) { $dvi_mode = 0; } elsif ( /^-dvilualatex=(.*)$/ ) { $dvilualatex = $1; @@ -2101,7 +2130,10 @@ while (defined($_ = $ARGV[0])) { my $format = $1; if ($format eq 'dvi' ) { $dvi_mode = 1; - $pdf_mode = $postscript_mode = 0; + if ( ($pdf_mode != 2) && ($pdf_mode != 3) ) { + # if pdf_mode is not via dvi or pdf, turn it off + $pdf_mode = 0; + } } elsif ($format eq 'pdf' ) { $pdf_mode = 1; @@ -2117,12 +2149,12 @@ while (defined($_ = $ARGV[0])) { $preview_mode = 0; } elsif (/^-p-$/) { $printout_mode = 0; } - elsif (/^-pdf$/) { $pdf_mode = 1; } + elsif (/^-pdf$/) { $pdf_mode = 1; $dvi_mode = $postscript_mode = 0; } elsif (/^-pdf-$/) { $pdf_mode = 0; } elsif (/^-pdfdvi$/){ $pdf_mode = 3; } - elsif (/^-pdflua$/){ $pdf_mode = 4; } + elsif (/^-pdflua$/){ $pdf_mode = 4; $dvi_mode = $postscript_mode = 0; } elsif (/^-pdfps$/) { $pdf_mode = 2; } - elsif (/^-pdfxe$/) { $pdf_mode = 5; } + elsif (/^-pdfxe$/) { $pdf_mode = 5; $dvi_mode = $postscript_mode = 0; } elsif (/^-pdflatex$/) { $pdflatex = "pdflatex %O %S"; $pdf_mode = 1; @@ -2150,7 +2182,12 @@ while (defined($_ = $ARGV[0])) { &exit_help("$My_name: unknown print type '$value' in option '$_'"); } } - elsif (/^-ps$/) { $postscript_mode = 1; } + elsif (/^-ps$/) { $postscript_mode = 1; + if ( ($pdf_mode != 2) && ($pdf_mode != 3) ) { + # if pdf_mode is not via dvi or pdf, turn it off + $pdf_mode = 0; + } + } elsif (/^-ps-$/) { $postscript_mode = 0; } elsif (/^-pv$/) { $preview_mode = 1; $preview_continuous_mode = 0; # to avoid conflicts @@ -2391,7 +2428,10 @@ else { push( @file_list, $file) unless ( exists $excl{$file} ); } if ( !@file_list ) { - &exit_help( "No file name specified, and I couldn't find any"); + &exit_help( + "No file name(s) specified on command line, and no files match the\n". + "patterns in the default list." + ); } } @@ -2715,10 +2755,17 @@ foreach $filename ( @file_list ) $failure_msg = ''; # Indicate reason for failure if ( $do_cd ) { - ($filename, $path) = fileparse( $filename ); - print "$My_name: Changing directory to '$path'\n" - if !$silent; - pushd( dirname_no_tail( $path ) ); + # Use my fileparse routine rather than the built-in one, otherwise + # under msys, a directory separator \ won't be recognized by fileparse. + # My routines fix that. At this point, $filename ought to have had its + # \s changed to /s. But I won't leave boobytrapped code. + # I use fileparseB rather than fileparseA, because fileparseA changes + # path './' to '', but fileparseB keeps the fileparse behavior there. + # I have to supply an explicit pattern of '' to keep extension in $filename. + ($filename, $path) = fileparseB( $filename, '' ); + print "$My_name: Changing directory to '$path'\n" + if !$silent; + pushd( dirname_no_tail( $path ) ); } else { $path = ''; @@ -2853,7 +2900,7 @@ foreach $filename ( @file_list ) &init_timing1; if ($compiling_cmd) { Run_subst( $compiling_cmd ); } - $failure = &rdb_make; + $failure = rdb_make(); if ( ( $failure <= 0 ) || $force_mode ) { rdb_for_some( [keys %one_time], \&rdb_run1 ); } @@ -2896,7 +2943,7 @@ continue { push @failed_primaries, $filename; } &ifcd_popd; - if ($show_time) { &show_timing1; }; + if ($show_time && ! $preview_continuous_mode) { &show_timing1; }; print "\n"; } close($deps_handle) if ( $deps_handle ); @@ -2981,6 +3028,7 @@ sub init_timing1 { # Initialize timing for one run. @timings1 = (); $processing_time1 = processing_time(); + $clock1 = Time::HiRes::time(); } ############################ @@ -2997,8 +3045,17 @@ sub init_timing_all { sub show_timing1 { # Show timing for one run. my $processing_time = processing_time() - $processing_time1; + my $invoked_time = 0; + for (@timings1) { + if (/: time = (.*)\s$/) { + $invoked_time += $1; + }} print @timings1, "Processing time = ", - sprintf('%.2f', $processing_time), "\n"; + sprintf('%.2f', $processing_time), + ", of which invoked processes = $invoked_time, other = ", + sprintf( '%.2f', $processing_time-$invoked_time ), ".\n"; + print "Elapsed clock time = ", + sprintf( '%.2f', Time::HiRes::time()-$clock1 ), ".\n"; print "Number of rules run = ", 1+$#timings1, "\n"; } @@ -4194,7 +4251,7 @@ CHANGE: if ($compiling_cmd) { Run_subst( $compiling_cmd ); } - $failure = &rdb_make; + $failure = rdb_make(); if ( $MSWin_fudge_break && ($^O eq "MSWin32") ) { $SIG{BREAK} = $SIG{INT} = 'DEFAULT'; @@ -4381,7 +4438,16 @@ sub process_rc_file { my ($rc_file, $repeat_reaction) = @_; my $abs_rc = abs_path($rc_file); my $ret_code = 0; - if ( exists $rc_files_read2{$abs_rc} ) { + if ( (!-e $rc_file) || ( ! defined $abs_rc ) ) { + warn "$My_name: The rc-file '$rc_file' does not exist\n"; + return 1; + } + elsif ( -d $rc_file ) { + warn "$My_name: The supposed rc-file '$rc_file' is a directory; but it\n", + " should be a normal text file\n"; + return 1; + } + elsif ( exists $rc_files_read2{$abs_rc} ) { if ( $repeat_reaction ) { warn "$My_name: A user -r option asked me to process an rc file an extra time.\n", @@ -4407,16 +4473,7 @@ sub process_rc_file { # current versions of Perl (Nov. 2022), so "do latexmkrc;" for # latexmkrc in cwd fails. # So I'll read the rc file and eval its contents. - if ( !-e $rc_file ) { - warn "$My_name: The rc-file '$rc_file' does not exist\n"; - return 1; - } - elsif ( -d $rc_file ) { - warn "$My_name: The supposed rc-file '$rc_file' is a directory; but it\n", - " should be a normal text file\n"; - return 1; - } - elsif ( open( my $RCH, "<", $rc_file ) ) { + if ( open( my $RCH, "<", $rc_file ) ) { my $code = ''; # Read all contents of file into $code: { local $/ = undef; $code = <$RCH>;} @@ -5188,7 +5245,7 @@ sub set_names { #************************************************** -sub correct_aux_out_files { +sub correct_locations { # Deal with situations after a *latex run where files are in different # directories than expected (specifically aux v. output directory). # Do minimal fix ups to allow latexmk to analyze dependencies with log @@ -5279,7 +5336,7 @@ sub correct_aux_out_files { warn "$My_name: fls file doesn't appear to have been made.\n"; } } -} # END correct_aux_out_files +} # END correct_locations #----------------- @@ -6197,28 +6254,68 @@ sub get_log_file { # ref to array to receive lines, # ref to hash to receive diagnostic etc informaion ) # 3rd argument is optional - # Lines are unwrapped and converted to CS_system. + # Lines are unwrapped and converted to the CS_system coding system (so + # that filenames are suitable for use in file opening calls and on + # command line to invoked programs). + # + # **Complication**: When writing to the .log file, *latex converts + # lines longer than a given length (by default, 79) to a sequence + # of lines with at most the maximum length. + # This subroutine converts such sequences of lines to the original + # unwrapped form. + # **However**, + # 1. The algorithm for line wrapping differs between all of pdflatex, + # xelatex, and lualatex. See below for details. + # 2. It is possible to write an unwrapped line L1 of a relevant + # length followed by a shorter line L2, such that it is impossible + # to distingish it from a wrapped line whose contents were those + # of L1 concatenated with L2. + # So when it is determined that a line is potentially wrapped, + # several possibilities for the unwrapped lines are added to the + # output array of lines (referenced by the second argument), so that + # subsequent scanning of the lines in the subroutine parse_log picks + # up the possible diagnostic messages independently of complications + # in identifying wrapped lines versus unwrapped lines. my ($file, $PAlines, $PHinfo) = @_; - # Where lines are wrapped at. We'll sometimes override. local $log_wrap = $log_wrap; + # Lines held for wrapping: + my @held_lines = (); + # Routine for setting wrapped lines; setup by assignment to keep visibility + # in the enclosing subroutine, and to access its my-variables: + my $Pwrap_sub = + sub { + for ( my $i=0; $i <= $#held_lines; $i++ ) { + my $line = ''; + for ( my $j=$i; $j <= $#held_lines; $j++ ) { + last if ($j-$i > 1 + ($max_log_construct /$log_wrap) ); + $line .= $held_lines[$j]; + push @$PAlines, $line; + } + } + @held_lines = (); + }; + + my $engine = ''; my $tex_distribution = ''; - my ($line_num, $cont, $max_len) = ( 0, 0, 0 ); + my ($line_num, $max_len) = ( 0, 0 ); my $lua_mode = 0; # Whether to use luatex-specific wrapping method. - my $byte_wrapping = 1; # *latex does byte wrapping. Modify if we find - # log file is generated by a tex program that - # wrapping by Unicode code points. - + my $byte_wrapping = 1; # Assume by default that the wrapping occurs at + # a certain number of bytes. Modify this + # variable if we find that the log file was + # generated by a tex program that does wrapping + # at a certain number of Unicode code points. + # The details for the different programs (underlying the *latex programs): # File encoding: pdftex: UTF-8 but with wrapping at $log_wrap BYTES. # (So individual wrapped lines can be malformed # UTF-8, but we get valid UTF-8 after unwrapping.) # luatex: UTF-8 but with wrapping at APPROXIMATELY # $log_wrap bytes. Rest as pdftex # xetex: UTF-8 with wrapping at $log_wrap codepoints. - # So we read file as bytes + # So we read file as bytes. Then # first line gives which program was used and hence whether to wrap # according to byte or codepoint count. # wrapping is always performed on the encoded byte strings, but the @@ -6262,17 +6359,46 @@ sub get_log_file { } if ($len > $max_len) { $max_len = $len } - # Is this line continuation of previous line? - if ($cont) { $$PAlines[$#$PAlines] .= $_; } - else { push @$PAlines, $_ } - # Is this line wrapped? I.e., is next line to be appended to it? - # Allow for fact that luatex doesn't reliably wrap at std place, e.g., 79. - $cont = ($len == $log_wrap) + # 2 cases: + # pdflatex and xelatex wrap at exactly length $log_wrap + # (default 79), and normally append empty line when line + # is exactly of the maximimum length (so we shouldn't have a + # problem of distinguishing a wrapped line from a line of + # length exactly $log_wrap). + # lualatex: Wrap at a variable position dependent in a complicated + # way on contents. With default settings, wrapping occurs + # between 77 and 80 bytes, according to my tests. It preserves + # UTF-8 coding, and doesn't split multi-byte UTF-8 coding of + # a code point between lines, unlike pdflatex. But details + # of exactly where a line is wrapped is not clear. + # It is not possible in all cases to distinguish whether + # a pair of lines arise from wrapping of a longer line + # or from actual writing of a pair of lines. + # Determine whether line is potentially wrapped: + my $cont = ($len == $log_wrap) || ( $lua_mode && ($len >= $log_wrap-2) && ($len <= $log_wrap+1) ); - if ($cont && $diagnostics ) { - print "====Continuing line $line_num of length $len\n$_\n"; + if ($cont) { + # Save lines that may be continued onto @held_lines + print "====Continuing line $line_num of length $len\n$_\n" + if $diagnostics; + push @held_lines, $_; + } + elsif (@held_lines) { + # No more continuation lines after this: + push @held_lines, $_; + # Put possibilities for lines before wrapping onto the main + # array and then clear @held_lines + &$Pwrap_sub(); } + else { + push @$PAlines, $_; + } + } + if (@held_lines) { + # Get here if the last line of the file is of a length that + # it may be a wrapped. + &$Pwrap_sub(); } close($fh); foreach (@$PAlines) { $_ = utf8_to_mine($_); } @@ -6330,7 +6456,7 @@ sub parse_fls { # is produced by MS-Windows program (e.g., in MiKTeX) with CRLF line ends, # but is read by Unix Perl (which treats LF as line end, and preserves CRLF # in read-in lines): - # And convert '\' + # And convert '\' to '/' s/\r?\n$//; s[\\][/]g; $line_no++; @@ -6340,10 +6466,17 @@ sub parse_fls { } else { # Deal with MS-Win issues when system CP isn't UTF-8 - if ( ($^O eq 'MSWin32') && /PWD/ && ! is_valid_utf8($_) ) { - # TeXLive on MSWin produces PWD in CS_system not UTF-8. - # ???? Later get tex_distribution before analyzing fls file, so do better test. - print "PWD line not in UTF-8. This is normal for TeXLive. I will handle it.\n"; + # Situation is that the fls file should be in UTF-8 and + # needs to be converted to system CP to fit with latexmk's + # convention (determined by file-system calls). + # However, under Windows' TeXLive 2021 (and maybe earlier) the + # PWD uses the system CP while the rest of the file is UTF-8. + # In TeXLive 2022 and 2023, the whole file, including the PWD + # line is UTF-8. + # So give special treatment to PWD line under Windows. + # Also to guard against any other problems, check for non-UTF-8 lines. + if ( ($^O eq 'MSWin32') && /PWD/ && ! is_valid_utf8($_) ) { print + "PWD line not in UTF-8. This is normal for older TeXLives (2021 and earlier).\n". "I will handle it.\n"; # Assume in CS_system, no change needed. } elsif ( ! is_valid_utf8($_) ) { @@ -6548,8 +6681,12 @@ sub normalize_filename { sub normalize_filename_abs { # Convert filename to be either # absolute path in canonical form - # or relative to cwd. - return normalize_filename( abs_path($_[0]) ); + # or relative to cwd, if possible. + # abs_path returns undef if it doesn't know how to get an absolute path. + # Just work with the original path in that case. + my $abs = abs_path($_[0]); + if (! defined $abs) { $abs = $_[0]; } + return normalize_filename( $abs ); } #----------------------------- @@ -6770,7 +6907,7 @@ sub parse_bcf { return 2; } - show_array( "$My_name: Bibliography file(s) form .bcf file:", @$Pbib_files ) + show_array( "$My_name: Bibliography file(s) from .bcf file:", @$Pbib_files ) unless $silent; if (@not_found_bib) { show_array( @@ -8175,6 +8312,10 @@ DEP: " I'll try making it with allowed extensions \n"; foreach my $try_ext ( keys %$Pinput_extensions ) { my $new_dest = "$file.$try_ext"; + if (-e $new_dest) { + # A file that exists cannot have been the missing file. + next; + } &Run_subst( "$make $quote$new_dest$quote" ); if ( -e $new_dest ) { print "SUCCESS in making '$new_dest'\n", @@ -8462,31 +8603,27 @@ sub rdb_make { # no error in the run, the source-file-state is **not** updated # after the rule is run. Then on a subsequent pass through # rdb_make's main loop, when the rule is tested for a rerun, any - # change in source file contents is cause for running the rule - # again. - # 8. But after a run giving an error, the state of the generated - # files (i.e., non-user files) is updated to the current state. - # This is because the error (under normal circumstances) must be - # corrected by user action: e.g., correcting a source file, and - # possibly deleting some corrupted auxiliary file. Files (e.g., - # .aux by *latex) generated by the rule just run may well have - # changed, so updating their state to the current state prevents - # another run before a user change. If a file was generated by - # another rule, it won't have changed its state, so updating its - # state won't matter. But a non-generated file is a - # user-created file, and a rerun is entailed if its contents - # changed compared with the start of the run; it's the - # start-of-run contents that were used in the error run. - # 9. Note: an error may be caused by a problem with a file - # generated by another rule, e.g., a bbl file created by bibtex - # and read by *latex, but with no error reported by bibtex. To - # correct the error a source file (possibly more than once - # removed must be changed). That triggers a rerun of the - # producing rule, and after that the resulting change causes a - # rerun of the original rule that had the error. E.g., - # correcting a .bib file causes bibtex to run, producing a - # corrected .bbl file, after which *latex is caused to be run. - # 10. With circular dependencies, there is a choice of which order + # change in source file contents since the start of the previous + # run is cause for running the rule again. + # 8. When there is an error, and force_mode is off, processing of + # all further rules is terminated. A problem is then caused for + # a later invocation of latexmk (or, in -pvc mode, the next + # scanning of source-file status): It may be that a generated + # file from a run of some rule changed compared with its status + # before the run. Because of the termination of processing + # there was no rerun of the rule. New runs should only be made + # after a change in the user-written files, which give the + # possibility of correcting the error. But on a subsequent + # invocation of latexmk it could appear that some rule(s) is/are + # out-of-date because of the changed generated files, which + # would result in unneeded extra runs, which will tend to + # pollute the screen output with misleading downstream + # consequences of the original error. + # To avoid this problem, after an error-generating round of + # compilations, the cached state of generated files is updated + # to their state after the compilations. Then only user-caused + # file changes will be cause for new runs. + # 9. With circular dependencies, there is a choice of which order # to examine the rules. Generally, primary rules are more # time-consuming than most others, so the choice of the order of # examination of rules to check out-of-dateness is to try to @@ -8495,7 +8632,7 @@ sub rdb_make { # graphics. These are normally outside a dependency loop, so # those are left to last. Even if they are inside a dependency # loop, they need the primary rule to have been run first. - # 11. After rdb_make is run, all non-user source files are updated + # 10. After rdb_make is run, all non-user source files are updated # to their current state. Rules are considered up-to-date # here. On a subsequent call to rdb_make, subsequent changes are # relevant to what is to be done. Note: the states of user @@ -8625,7 +8762,7 @@ sub rdb_make { } if ( ($runs > 0) && ! $too_many_passes ) { $retry_msg = 0; - if ( $force_mode || (! $failure) || $switched_primary_output ) { + if ( $force_mode || (! $failure) ) { next PASS; } # Get here on failure, without being in force_mode @@ -8673,7 +8810,31 @@ sub rdb_make { # but do not change primaries. # Problem is that %current_primaries gets altered &rdb_set_rule_net; - } #End PASS + } #End PASS + + if ($failure ) { + # Update state of generated source files, but not non-generated, + # i.e., user source files. Without that, when there was a termination of + # processing because of an error, it could be some generated files changed + # without reruns of the relevant rule(s) being triggered; that's because + # with an error and with force_mode off, the reruns are blocked. + # But that situation would cause reruns either when latexmk is reinvoked + # or at the next examination of file state (in -pvc mode). But those runs + # (almost certainly) won't improve the error situation in the absence of + # a change in user files, since the error is ultimately due to a problem + # with a user file. + # By updating the state of generated source files, reruns are not + # triggered until a user file is changed. + # Also turn $$Pout_of_date off for the rules. It may have been set + # at some point to trigger a rerun, but that information is now + # out-of-date, given that an error occurred. + rdb_for_some( [&rdb_accessible()], + sub{ + &rdb_update_gen_files; + $$Pout_of_date = 0; + } + ); + } rdb_for_some( [@unusual_one_time], \&rdb_make1 ); @@ -8839,7 +9000,7 @@ sub rdb_make1 { # Is this needed? Yes; rdb_make1 is called on a sequence of rules and # if one gives an error, then it provides source files directly or # indirectly to later rules, which should not be run. - if ($failure & ! $force_mode) {return;} + if ($failure && ! $force_mode) {return;} # Rule may have been created since last run. Just in case we didn't, # define $pass{$rule} elsewhere, do it here: @@ -8922,6 +9083,7 @@ sub rdb_make1 { warn_running( "Run number $pass{$rule} of rule '$rule'" ); $return = &rdb_run1; } + if ($$Pchanged) { $newrule_nofile = 1; $return = 0; @@ -8972,15 +9134,6 @@ sub rdb_make1 { if ( !$$Plast_message ) { $$Plast_message = "Run of rule '$rule' gave a non-zero error code"; } - # Update state of generated source files, but not non-generated, - # i.e., user source files. Thus any change in the rule's own - # generated source files during the run will not cause a - # rerun. Files generated by another rule should not have been - # changed during the run, so updating their saved state in this - # rule is a NOP. But any change in user files since the **start** - # of the run is a cause for a rerun, so their saved state must not - # be updated. - rdb_update_gen_files(); } foreach ( keys %$PHsource_rules ) { $$PHsource_rules{$_} = $pass{$_}; @@ -9074,7 +9227,7 @@ sub rdb_run1 { # $$Pout_of_date = $$Pout_of_date_user = 0; if ($latex_like) { - &correct_aux_out_files; + &correct_locations; run_hooks( 'after_xlatex' ); $return = analyze_latex_run( $return ); run_hooks( 'after_xlatex_analysis' ); @@ -9490,7 +9643,6 @@ sub rdb_rerun_needed { # # ???!!!! # Check all uses!!!!!!!!!!!!! - our ($rule, %pass); local our $PHchanges = shift; @@ -9628,9 +9780,7 @@ sub rdb_rerun_needed { } $$Pno_history = 0; # See comments in definition of %rule_db. if ($rerun_needed) { - $$Pout_of_date = 1; push @{$$PHchanges{rules_to_apply}}, $rule; - if (@{$$PHchanges{changed_user}}) {$$Pout_of_date_user = 1;} } return $rerun_needed; } #END rdb_rerun_needed @@ -10500,37 +10650,6 @@ sub Parray { #************************************************************ -sub analyze_string { - # Show information about string: utf8 flag or not, length(s!), byte content - my ($m,$s) = @_; - - print "=== $m "; - my $length = length($s); - if (utf8::is_utf8($s)) { - my $encoded = encode( $CS_system, $s, Encode::FB_WARN | Encode::LEAVE_SRC ); - my $len_chars = 0; - my $len_bytes = 0; - { no bytes; $len_chars = length($s); } - { use bytes; $len_bytes = length($s); } - print "'$encoded':\n", - "utf8, len = $length; chars = $len_chars; bytes = $len_bytes\n"; - } - else { - print "'$s':\n", - "NOT utf8, len = $length\n"; - } - - print join ' ', to_hex($s), "\n"; -} - -#---------------------------- - -sub to_hex { - return map { sprintf('%4X', $_) } unpack( 'U*', shift ); -} - -#================== - sub glob_list1 { # Glob a collection of filenames. # But no sorting or elimination of duplicates @@ -10691,24 +10810,30 @@ sub get_checksum_md5 { # We won't use checksum for directory return 0; } - else { - open( $input, '<:bytes', $source ) - or return 0; - my ($base, $path, $ext) = fileparseA( $source ); - $ext =~ s/^\.//; - if ( exists $hash_calc_ignore_pattern{$ext} ) { - $ignore_pattern = $hash_calc_ignore_pattern{$ext}; - } + open( $input, '<:bytes', $source ) + or return 0; + my ($base, $path, $ext) = fileparseA( $source ); + $ext =~ s/^\.//; + if ( exists $hash_calc_ignore_pattern{$ext} ) { + $ignore_pattern = $hash_calc_ignore_pattern{$ext}; } - if ( defined $ignore_pattern ) { - while (<$input>) { - if ( ! /$ignore_pattern/ ){ - $md5->add($_); + eval { + # Trap any errors that occur during reading, even though the file + # was successfully opened. + # Such errors have been known to occur under OneDrive on macOS. + if ( defined $ignore_pattern ) { + while (<$input>) { + if ( ! /$ignore_pattern/ ){ + $md5->add($_); + } } } - } - else { - $md5->addfile($input); + else { + $md5->addfile($input); + } + }; + if ($@) { + warn "$My_name: Attempt to get md5 of '$source' failed. Error=\n$@"; } close $input; return $md5->hexdigest(); @@ -11184,7 +11309,12 @@ sub ext_no_period { sub fileparseA { # Like fileparse but replace $path for current dir ('./' or '.\') by '' # Also default second argument to get normal extension. + # With msys, change all \ to / in given name since with msys, fileparse + # doesn't recognize \ as directory separator. my $given = $_[0]; + if ( $^O eq 'msys' ) { + $given =~ s[\\][/]g; + } my $pattern = '\.[^\.]*'; if ($#_ > 0 ) { $pattern = $_[1]; } my ($base_name, $path, $ext) = fileparse( $given, $pattern ); @@ -11198,7 +11328,12 @@ sub fileparseA { sub fileparseB { # Like fileparse but with default second argument for normal extension + # With msys, change all \ to / in given name since with msys, fileparse + # doesn't recognize \ as directory separator. my $given = $_[0]; + if ( $^O eq 'msys' ) { + $given =~ s[\\][/]g; + } my $pattern = '\.[^\.]*'; if ($#_ > 0 ) { $pattern = $_[1]; } my ($base_name, $path, $ext) = fileparse( $given, $pattern ); @@ -11551,7 +11686,11 @@ sub cache_good_cwd { } # Normalized if ($normalize_names) { - $cwd = abs_path($cwd); + my $abs = abs_path($cwd); + # It's conceivable that abs_path doesn't know how to convert to an + # absolute path of a standard normalization. Then it returns undef. + # In that case, it's probably good not to try normalizing $cwd. + if (defined $abs) { $cwd = $abs; } } $cache{cwd} = $cwd; } # END cache_good_cwd diff --git a/Master/texmf-dist/doc/man/man1/latexmk.1 b/Master/texmf-dist/doc/man/man1/latexmk.1 index b71b5599774..0b57ebea1bc 100644 --- a/Master/texmf-dist/doc/man/man1/latexmk.1 +++ b/Master/texmf-dist/doc/man/man1/latexmk.1 @@ -1,4 +1,4 @@ -.TH LATEXMK 1 "4 April 2023" "" +.TH LATEXMK 1 "6 November 2023" "" .SH NAME latexmk \- generate LaTeX document .SH SYNOPSIS @@ -2733,6 +2733,36 @@ database of information on source files. You will not normally need to change this. .TP +.B @file_not_found +This an array of Perl regular expressions that are patterns to find +messages in the .log file from a run of *latex that indicate that a file +was looked for and not found. To see the current default set, you should +look at the definition of \fI@file_not_found\fR in the latexmk.pl file. + +In the regular expression, the string for the name of the missing file +should be enclosed in parentheses. That carries the implication that after +latexmk gets a succesful match to the pattern, the variable $1 is set to +the filename, which is then picked up by latexmk. + +If you happen to encounter a package that gives a missing file message of a +different form than one that matches one of the built-in patterns, you can +add another pattern to the array. An example would be + + push @file_not_found, '^No file\\\\s+(.+)\\\\s*$'; + +The regular expression itself is + + ^Missing file\\s+(.+)\\s*$ + +But the corresponding string specification in the push statement has to +have the backslashes doubled. + +This regular expression matches a line that starts with 'No file', then has +one or more white space characters, then any number of characters forming +the filename, then possible white space, and finally the end of the line. +(See documentation on Perl regular expressions for details.) + +.TP .B $fls_uses_out_dir [0] This variable determines whether or not the .fls file should be in the output directory instead of the natural directory, which is the aux @@ -3995,9 +4025,49 @@ dollar signs. .B $$Pdest This gives the name of the main output file if any. Note the double dollar signs. + +.TP +.B pushd( path ), popd() +These subroutines are used when it is needed to temporarily change the +working directory, as in + + pushd( 'some_directory' ); + ... Processing done with 'some_directory' as the working directory + popd() + +They perform exactly the same function as the commands of the same names in +operating system command shells like bash on Unix, and cmd.exe on the +Windows. + +.TP +.B rdb_add_generated( file, ... ) +This subroutine is to be used in the context of a rule, that is, from +within a subroutine that is carrying out processing of a rule. Such is the +case for the subroutine implementing a custom dependency, or the subroutine +invoked by using the "internal" keyword in the command specification like +that in the variable \fI$latex\fR. + +Its arguments are a sequence of filenames which are generated during the +running of the rule. The names might arise from an analysis of the results +of the run, e.g., in a log file, or from knowledge of properties of the +specific rule. Calling \fIrdb_add_generated\fR with these filenames +ensures that these files are flagged as generated by the rule in +\fIlatexmk\fR's internal data structures. Basically, no action is taken if +the files have already been flagged as generated. + +A main purpose of using this subroutine is for the situation when a +generated file is also the source file for some rule, so that \fIlatexmk\fR +can correctly link the dependency information in its network of rules. + +\fINote: Unlike some other subroutines in this section, there is no +argument for a rule for \fRrdb_add_generated\fI. Instead, the subroutine is +to be invoked during the processing of a rule when \fRlatexmk\fI has set up +an appropriate context (i.e., appropriate variables). In contrast, +subroutines with a rule argument can be used also outside a rule context.\fR + .TP .B rdb_ensure_file( $rule, file ) -This a subroutine that ensures that the given file is among the source +This subroutine ensures that the given file is among the source files for the specified rule. It is typically used when, during the processing of a rule, it is known that a particular extra file is among the dependencies that \fIlatexmk\fR should know, but its default @@ -4010,17 +4080,34 @@ For examples of its use, see some of the files in the directory cases that use this subroutine are \fIbib2gls-latexmkrc\fR, \fIexceltex_latexmkrc\fR and \fItexinfo-latexmkrc\fR. These illustrate typical cases where \fIlatexmk\fR's normal processing fails -to detect certain extra source files. +to detect certain extra source files. + +\fINote that \fRrdb_ensure_file\fI only has one filename argument, unlike +other subroutines in this section. If you want to apply its action to +multiple files, you will need one call to \fRrdb_ensure_file\fI for each +file.\fR + .TP .B rdb_remove_files( $rule, file, ... ) This subroutine removes one or more files from the dependency list for the given rule. + +.TP +.B rdb_remove_generated( file, ... ) +This subroutine is to be used in the context of a rule, that is, from +within a subroutine that is carrying out processing of a rule. It performs +the opposite action to \fIrdb_add_generated\fR. Its effect is to ensure +that the given filenames are not listed in \fIlatexmk\fR's internal data +structures as being generated by the rule. + .TP .B rdb_list_source( $rule ) This subroutine returns the list of source files (i.e., the dependency list) for the given rule. + .TP .B rdb_set_source( $rule, file, ... ) + .TP .B rdb_set_source( $rule, @files ) This subroutine sets the dependency list for the given rule to be the @@ -4028,6 +4115,7 @@ specified files. Files that are already in the list have unchanged information. Files that were not in the list are added to it. Files in the previous dependency list that are not in the newly specified list of files are removed from the dependency list. + .TP .B Run_subst( command_spec ) This subroutine runs the command specified by \fIcommand_spec\fR. The @@ -4296,12 +4384,12 @@ e-mail addresses are not written in their standard form to avoid being harvested too easily.) .SH AUTHOR Current version, by John Collins -(Version 4.80). +(Version 4.81). Report bugs etc to his e-mail (jcc8 at psu.edu). Released version can be obtained from CTAN: <http://www.ctan.org/pkg/latexmk/>, and from the -author's website <http://www.personal.psu.edu/jcc8/latexmk/>. +author's website <https://www.cantab.net/users/johncollins/latexmk/>. .br Modifications and enhancements by Evan McLean (Version 2.0) .br diff --git a/Master/texmf-dist/doc/man/man1/latexmk.man1.pdf b/Master/texmf-dist/doc/man/man1/latexmk.man1.pdf Binary files differindex ec8a6364001..d5d95724cca 100644 --- a/Master/texmf-dist/doc/man/man1/latexmk.man1.pdf +++ b/Master/texmf-dist/doc/man/man1/latexmk.man1.pdf diff --git a/Master/texmf-dist/doc/support/latexmk/CHANGES b/Master/texmf-dist/doc/support/latexmk/CHANGES index f43cb57bb70..09e5cd9b2e8 100644 --- a/Master/texmf-dist/doc/support/latexmk/CHANGES +++ b/Master/texmf-dist/doc/support/latexmk/CHANGES @@ -857,5 +857,19 @@ From v. 4.79 to 4.80 Various bug fixes and corrections, improvements in error and warning messages, and corrections to documentation. - +From v. 4.80 to 4.81 + Fix various problems when filenames contain non-ASCII characters, + especially when MSYS is used. + Fix problems with analyzing wrapped lines in log files, especially with + lualatex. + With options like -dvi that set the kind of output file, turn off + settings corresponding to incompatible options. + Improved warning and error messages. + Fix problem when using the $use_make_for_missing_files, with the search + over possible extensions for a missing file. + Add .run.xml to the list of generated extensions in @generated_exts. + Correct the behavior after errors. Previously force_mode didn't work as + documented, terminating processing too early, while in + preview_continuous_mode, incorrect extra runs were sometimes made. + Other bug fixes. diff --git a/Master/texmf-dist/doc/support/latexmk/INSTALL b/Master/texmf-dist/doc/support/latexmk/INSTALL index fc4b4a0f62a..359686d527a 100644 --- a/Master/texmf-dist/doc/support/latexmk/INSTALL +++ b/Master/texmf-dist/doc/support/latexmk/INSTALL @@ -1,6 +1,6 @@ INSTALLING latexmk ================== - (Version 4.80, 4 Apr. 2023) + (Version 4.81, 6 Nov. 2023) John Collins Physics Department diff --git a/Master/texmf-dist/doc/support/latexmk/README b/Master/texmf-dist/doc/support/latexmk/README index 87b742eb536..72848ce8f3a 100644 --- a/Master/texmf-dist/doc/support/latexmk/README +++ b/Master/texmf-dist/doc/support/latexmk/README @@ -1,4 +1,4 @@ -Latexmk, version 4.80, 4 Apr 2023 +Latexmk, version 4.81, 6 Nov 2023 --------------------------------- Latexmk completely automates the process of generating a LaTeX diff --git a/Master/texmf-dist/doc/support/latexmk/example_rcfiles/README-latexmk-rcfiles b/Master/texmf-dist/doc/support/latexmk/example_rcfiles/README-latexmk-rcfiles index 19690cf168b..1517b35ed57 100644 --- a/Master/texmf-dist/doc/support/latexmk/example_rcfiles/README-latexmk-rcfiles +++ b/Master/texmf-dist/doc/support/latexmk/example_rcfiles/README-latexmk-rcfiles @@ -26,7 +26,7 @@ NOTES: But it is preferable to leave the quotes in, since they provide safety against special characters in filenames. The double quotes - appear not to cause problems in all situations that I have tried. + appear not to cause problems in all the situations that I have tried. 5. Note that the files for exceltex and pythontex illustrate an answer to an issue that arises in the following generic situation: diff --git a/Master/texmf-dist/doc/support/latexmk/example_rcfiles/pdflatex_latexmkrc b/Master/texmf-dist/doc/support/latexmk/example_rcfiles/pdflatex_latexmkrc new file mode 100644 index 00000000000..38c7e6670d2 --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/example_rcfiles/pdflatex_latexmkrc @@ -0,0 +1,6 @@ +# This shows how to configure latexmk to use pdflatex + +$pdf_mode = 1; +$postscript_mode = $dvi_mode = 0; + + diff --git a/Master/texmf-dist/doc/support/latexmk/example_rcfiles/pythontex-latexmkrc b/Master/texmf-dist/doc/support/latexmk/example_rcfiles/pythontex-latexmkrc index 825706a630b..458c5a40706 100644 --- a/Master/texmf-dist/doc/support/latexmk/example_rcfiles/pythontex-latexmkrc +++ b/Master/texmf-dist/doc/support/latexmk/example_rcfiles/pythontex-latexmkrc @@ -15,6 +15,13 @@ $clean_ext .= " pythontex-files-%R/* pythontex-files-%R"; push @generated_exts, 'pytxcode'; $pythontex = 'pythontex %O %S'; + +# Specify a rule for running the pythontex program. +# Because of the unusual structure of input and output files, I've used +# an internal hash variable %extra_rule_spec of latexmk to specify the +# rule. Currently the only documentation is in the latexmk source code. +# Probably the following line is stable against future changes in latexmk, +# but that isn't guaranteed. $extra_rule_spec{'pythontex'} = [ 'internal', '', 'mypythontex', "%Y%R.pytxcode", "%Ypythontex-files-%R/%R.pytxmcr", "%R", 1 ]; sub mypythontex { diff --git a/Master/texmf-dist/doc/support/latexmk/example_rcfiles/schultz-texshop-latexmkrc b/Master/texmf-dist/doc/support/latexmk/example_rcfiles/schulz-texshop-latexmkrc index 6f43e982ec6..6f43e982ec6 100644 --- a/Master/texmf-dist/doc/support/latexmk/example_rcfiles/schultz-texshop-latexmkrc +++ b/Master/texmf-dist/doc/support/latexmk/example_rcfiles/schulz-texshop-latexmkrc diff --git a/Master/texmf-dist/doc/support/latexmk/example_rcfiles/xr_latexmkrc b/Master/texmf-dist/doc/support/latexmk/example_rcfiles/xr_latexmkrc index 24647ae6e87..bd860852301 100644 --- a/Master/texmf-dist/doc/support/latexmk/example_rcfiles/xr_latexmkrc +++ b/Master/texmf-dist/doc/support/latexmk/example_rcfiles/xr_latexmkrc @@ -27,10 +27,6 @@ # or extra enhancements to latexmk. # 5. The code uses subroutines copy and fileparse that are loaded by # latexmk from the Perl packages File::Copy and File::Basename. -# 6. It also uses some not-yet-documented features of latexmk: an array -# variable @file_not_found and subroutines popd, pushd, and -# rdb_add_generated. - #-------------------- # Configurable choices for compilation of external documents @@ -72,14 +68,13 @@ sub makeexternaldocument { # aux_dir rather than the one the cus dep is assumed by latexmk # to produce, which is in the same directory as the .tex source # file for this custom dependency.) - # Use not-yet-documented latexmk subroutine rdb_add_generated - # to do this: + # Use the latexmk subroutine rdb_add_generated to do this. # 2. A copy of the .aux file must be in same directory as .tex file # to satisfy latexmk's definition of a custom dependency. rdb_add_generated( "$sub_doc_output/$base_name.aux" ); copy "$sub_doc_output/$base_name.aux", "."; } - popd; + popd(); return $return; } } diff --git a/Master/texmf-dist/doc/support/latexmk/latexmk.pdf b/Master/texmf-dist/doc/support/latexmk/latexmk.pdf Binary files differindex a746f4cfda9..4c2ed709641 100644 --- a/Master/texmf-dist/doc/support/latexmk/latexmk.pdf +++ b/Master/texmf-dist/doc/support/latexmk/latexmk.pdf diff --git a/Master/texmf-dist/doc/support/latexmk/latexmk.txt b/Master/texmf-dist/doc/support/latexmk/latexmk.txt index 31bcadb0a5b..720022a6348 100644 --- a/Master/texmf-dist/doc/support/latexmk/latexmk.txt +++ b/Master/texmf-dist/doc/support/latexmk/latexmk.txt @@ -61,7 +61,7 @@ DESCRIPTION - 4 April 2023 1 + 6 November 2023 1 @@ -127,7 +127,7 @@ LATEXMK OPTIONS AND ARGUMENTS ON COMMAND LINE - 4 April 2023 2 + 6 November 2023 2 @@ -193,7 +193,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 3 + 6 November 2023 3 @@ -259,7 +259,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 4 + 6 November 2023 4 @@ -325,7 +325,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 5 + 6 November 2023 5 @@ -391,7 +391,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 6 + 6 November 2023 6 @@ -457,7 +457,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 7 + 6 November 2023 7 @@ -523,7 +523,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 8 + 6 November 2023 8 @@ -589,7 +589,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 9 + 6 November 2023 9 @@ -655,7 +655,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 10 + 6 November 2023 10 @@ -721,7 +721,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 11 + 6 November 2023 11 @@ -787,7 +787,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 12 + 6 November 2023 12 @@ -853,7 +853,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 13 + 6 November 2023 13 @@ -919,7 +919,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 14 + 6 November 2023 14 @@ -985,7 +985,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 15 + 6 November 2023 15 @@ -1051,7 +1051,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 16 + 6 November 2023 16 @@ -1117,7 +1117,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 17 + 6 November 2023 17 @@ -1183,7 +1183,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 18 + 6 November 2023 18 @@ -1249,7 +1249,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 19 + 6 November 2023 19 @@ -1315,7 +1315,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 20 + 6 November 2023 20 @@ -1381,7 +1381,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 21 + 6 November 2023 21 @@ -1447,7 +1447,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 22 + 6 November 2023 22 @@ -1513,7 +1513,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 23 + 6 November 2023 23 @@ -1579,7 +1579,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 24 + 6 November 2023 24 @@ -1645,7 +1645,7 @@ EXAMPLES - 4 April 2023 25 + 6 November 2023 25 @@ -1711,7 +1711,7 @@ DEALING WITH ERRORS, PROBLEMS, ETC - 4 April 2023 26 + 6 November 2023 26 @@ -1777,7 +1777,7 @@ AUXILIARY AND OUTPUT DIRECTORIES - 4 April 2023 27 + 6 November 2023 27 @@ -1843,7 +1843,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 28 + 6 November 2023 28 @@ -1909,7 +1909,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 29 + 6 November 2023 29 @@ -1975,7 +1975,7 @@ ALLOWING FOR CHANGE OF OUTPUT FILE TYPE - 4 April 2023 30 + 6 November 2023 30 @@ -2041,7 +2041,7 @@ CONFIGURATION/INITIALIZATION (RC) FILES - 4 April 2023 31 + 6 November 2023 31 @@ -2107,7 +2107,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 32 + 6 November 2023 32 @@ -2173,7 +2173,7 @@ FORMAT OF COMMAND SPECIFICATIONS - 4 April 2023 33 + 6 November 2023 33 @@ -2239,7 +2239,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 34 + 6 November 2023 34 @@ -2305,7 +2305,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 35 + 6 November 2023 35 @@ -2371,7 +2371,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 36 + 6 November 2023 36 @@ -2437,7 +2437,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 37 + 6 November 2023 37 @@ -2503,7 +2503,7 @@ LIST OF CONFIGURATION VARIABLES USABLE IN INITIALIZATION FILES - 4 April 2023 38 + 6 November 2023 38 @@ -2569,7 +2569,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 39 + 6 November 2023 39 @@ -2635,7 +2635,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 40 + 6 November 2023 40 @@ -2701,7 +2701,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 41 + 6 November 2023 41 @@ -2767,7 +2767,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 42 + 6 November 2023 42 @@ -2833,7 +2833,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 43 + 6 November 2023 43 @@ -2899,7 +2899,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 44 + 6 November 2023 44 @@ -2965,7 +2965,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 45 + 6 November 2023 45 @@ -3031,7 +3031,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 46 + 6 November 2023 46 @@ -3097,7 +3097,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 47 + 6 November 2023 47 @@ -3163,7 +3163,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 48 + 6 November 2023 48 @@ -3229,7 +3229,7 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - 4 April 2023 49 + 6 November 2023 49 @@ -3271,6 +3271,51 @@ LATEXMK(1) General Commands Manual LATEXMK(1) need to change this. + @file_not_found + This an array of Perl regular expressions that are patterns to + find messages in the .log file from a run of *latex that indi- + cate that a file was looked for and not found. To see the cur- + rent default set, you should look at the definition of + @file_not_found in the latexmk.pl file. + + In the regular expression, the string for the name of the miss- + ing file should be enclosed in parentheses. That carries the + implication that after latexmk gets a succesful match to the + pattern, the variable $1 is set to the filename, which is then + picked up by latexmk. + + If you happen to encounter a package that gives a missing file + message of a different form than one that matches one of the + built-in patterns, you can add another pattern to the array. An + example would be + + push @file_not_found, '^No file\\s+(.+)\\s*$'; + + The regular expression itself is + + + + 6 November 2023 50 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + + ^Missing file\s+(.+)\s*$ + + But the corresponding string specification in the push statement + has to have the backslashes doubled. + + This regular expression matches a line that starts with 'No + file', then has one or more white space characters, then any + number of characters forming the filename, then possible white + space, and finally the end of the line. (See documentation on + Perl regular expressions for details.) + + $fls_uses_out_dir [0] This variable determines whether or not the .fls file should be in the output directory instead of the natural directory, which @@ -3291,19 +3336,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) of the .fls file to be generated. - - - - - 4 April 2023 50 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - $force_mode [0] If nonzero, continue processing past minor latex errors includ- ing unrecognized cross references. Equivalent to specifying the @@ -3325,8 +3357,20 @@ LATEXMK(1) General Commands Manual LATEXMK(1) After initialization of latexmk and the processing of its com- mand line, the items in clean_ext are appended to @gener- - ated_exts. So these two variables have the same meaning (con- - trary to older versions of latexmk). + ated_exts. So these two variables have the same meaning + + + + 6 November 2023 51 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + + (contrary to older versions of latexmk). The items in @generated_exts are normally extensions of files, whose base name is the same as the main tex file. But it is @@ -3359,17 +3403,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) If nonzero, process files regardless of timestamps, and is then equivalent to the -g option. - - - 4 April 2023 51 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - %hash_calc_ignore_pattern !!!This variable is for experts only!!! @@ -3391,6 +3424,18 @@ LATEXMK(1) General Commands Manual LATEXMK(1) This creates a rule for files with extension .eps about lines to ignore. The left-hand side is a Perl idiom for setting an item + + + + 6 November 2023 52 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + in a hash. Note that the file extension is specified without a period. The value, on the right-hand side, is a string contain- ing a regular expression. (See documentation on Perl for how @@ -3424,18 +3469,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) This specifies the jobname, i.e., the basename that is used for generated files (.aux, .log, .dvi, .ps, .pdf, etc). If this - - - - 4 April 2023 52 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - variable is a null string, then the basename is the basename of the main tex file. (At present, the string in $jobname should not contain spaces.) @@ -3458,6 +3491,17 @@ LATEXMK(1) General Commands Manual LATEXMK(1) latexmk -pdf *.tex + + + 6 November 2023 53 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + both files will be compiled. The .aux, .log, and .pdf files will have basenames test1-MSWin32 ante test2-MSWin32 on a MS- Windows system, test1-darwin and test2-darwin on an OS-X system, @@ -3490,18 +3534,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) $kpsewhich_show [0] Whether to show diagnostics about invocations of kpsewhich: the - - - - 4 April 2023 53 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - command line use to invoke it and the results. These diagnos- tics are shown if $kpsewhich_show is non-zero or if diagnostics mode is on. (But in the second case, lots of other diagnostics @@ -3524,6 +3556,18 @@ LATEXMK(1) General Commands Manual LATEXMK(1) To do a coordinated setting of all of $dvilualatex, $latex, $pdflatex, $lualatex, and $xelatex, see the section "Advanced + + + + 6 November 2023 54 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + Configuration". @@ -3555,22 +3599,10 @@ LATEXMK(1) General Commands Manual LATEXMK(1) add the extension 'asdf to latex_input_extensions. (Naturally with such an extension, you should have made an appropriate cus- - tom dependency for latexmk, and should also have done the - - - - 4 April 2023 54 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - - appropriate programming in the LaTeX source file to enable the - file to be read. The standard extensions are handled by LaTeX - and its graphics/graphicx packages.) + tom dependency for latexmk, and should also have done the appro- + priate programming in the LaTeX source file to enable the file + to be read. The standard extensions are handled by LaTeX and + its graphics/graphicx packages.) $latex_silent_switch ["-interaction=batchmode"] Switch(es) for the LaTeX processing program when silent mode is @@ -3590,6 +3622,18 @@ LATEXMK(1) General Commands Manual LATEXMK(1) Under MS-Windows (unlike UNIX/Linux), there is no standard pro- gram for printing files. But there are ways you can do it. For example, if you have gsview installed, you could use it with the + + + + 6 November 2023 55 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + option "/p": $lpr = '"c:/Program Files/Ghostgum/gsview/gsview32.exe" /p'; @@ -3622,18 +3666,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) $lualatex ["lualatex %O %S"] Specifies the command line for the LaTeX processing program that - - - - 4 April 2023 55 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - is to be used when the lualatex program is called for (e.g., by the option -lualatex. @@ -3656,6 +3688,18 @@ LATEXMK(1) General Commands Manual LATEXMK(1) fault extensions are 'tex', 'pdf', 'jpg, and 'png'. See details of the %latex_input_extensions for other information + + + + 6 November 2023 56 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + that equally applies to %lualatex_input_extensions. $lualatex_silent_switch ["-interaction=batchmode"] @@ -3688,18 +3732,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) bail out, rather than rerunning *latex again to resolve cross- references, etc. The default value covers all normal cases. - - - - 4 April 2023 56 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - (Note that the "etc" covers a lot of cases where one run of *la- tex generates files to be read in on a later run.) @@ -3721,10 +3753,22 @@ LATEXMK(1) General Commands Manual LATEXMK(1) stitution from "/" to "\", by default. However there are also programs on MS-Windows for which a back - slash "\" is interpreted differently than as a directory separa- - tor; for these the directory separator should be "/". Programs - with this behavior include all the *latex programs in the - TeXLive implementation (but not the MiKTeX implementation). + slash "\" is interpreted differently than as a directory + + + + 6 November 2023 57 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + + separator; for these the directory separator should be "/". + Programs with this behavior include all the *latex programs in + the TeXLive implementation (but not the MiKTeX implementation). Hence if you use TeXLive on MS-Windows, then $MSWin_back_slash should be set to zero. @@ -3755,17 +3799,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - - - 4 April 2023 57 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - $pdf_mode [0] If zero, do NOT generate a pdf version of the document. If equal to 1, generate a pdf version of the document using pdfla- @@ -3788,6 +3821,17 @@ LATEXMK(1) General Commands Manual LATEXMK(1) Specifies the command line for the LaTeX processing program in a version that makes a pdf file instead of a dvi file. + + + 6 November 2023 58 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + An example use of this variable is to add certain options to the command line for the program, e.g., @@ -3820,18 +3864,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) See details of the %latex_input_extensions for other information that equally applies to %pdflatex_input_extensions. - - - - 4 April 2023 58 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - $pdflatex_silent_switch ["-interaction=batchmode"] Switch(es) for the pdflatex program (specified in the variable $pdflatex) when silent mode is on. @@ -3854,6 +3886,18 @@ LATEXMK(1) General Commands Manual LATEXMK(1) preview, which is quite satisfactory. WARNING: Problem under MS-Windows: if acroread is used as the + + + + 6 November 2023 59 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + pdf previewer, and it is actually viewing a pdf file, the pdf file cannot be updated. Thus makes acroread a bad choice of previewer if you use latexmk's previous-continuous mode (option @@ -3887,17 +3931,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) Note that acroread under MS-Windows (but not UNIX) locks the pdf file, so the default value is then 3. - - - 4 April 2023 59 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - Arranging to use a command to get a previewer explicitly updated requires three variables to be set. For example: @@ -3918,6 +3951,19 @@ LATEXMK(1) General Commands Manual LATEXMK(1) variable $pdf_update_method. The default value is the one ap- propriate for gv on a UNIX system. + + + + + 6 November 2023 60 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + $pid_position[1 under UNIX, -1 under MS-Windows] The variable $pid_position is used to specify which word in lines of the output from $pscmd corresponds to the process ID. @@ -3953,17 +3999,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) - - - 4 April 2023 60 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - $preview_continuous_mode [0] If nonzero, run a previewer to view the document, and continue running latexmk to keep .dvi up-to-date. Equivalent to the -pvc @@ -3982,6 +4017,19 @@ LATEXMK(1) General Commands Manual LATEXMK(1) mended not to be set from an RC file, otherwise you could waste lots of paper. + + + + + 6 November 2023 61 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + $print_type = ["auto"] Type of file to printout: possibilities are "auto", "dvi", "none", "pdf", or "ps". See the option -print= for the meaning @@ -4018,18 +4066,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) Note that gv could be used with the -watch option updates its display whenever the postscript file changes, whereas ghostview - - - - 4 April 2023 61 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - does not. However, different versions of gv have slightly dif- ferent ways of writing this option. You can configure this variable appropriately. @@ -4049,6 +4085,17 @@ LATEXMK(1) General Commands Manual LATEXMK(1) in yourself, whenever it is needed. + + + 6 November 2023 62 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + $ps_previewer_landscape ["start gv -swap %O %S", but start %O %S under MS-Windows] The command to invoke a ps-previewer in landscape mode. @@ -4085,17 +4132,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) The period of inactivity, in minutes, after which pvc mode times out. This is used if $pvc_timeout is nonzero. - - - 4 April 2023 62 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - $pvc_view_file_via_temporary [1] The same as $always_view_file_via_temporary, except that it only applies in preview-continuous mode (-pvc option). @@ -4115,6 +4151,17 @@ LATEXMK(1) General Commands Manual LATEXMK(1) correctly treated by the operating system in passing arguments to programs.) + + + 6 November 2023 63 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + $rc_report [1] After initialization, whether to give a list of the RC files read. @@ -4150,18 +4197,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) [Comment to technically savvy readers: *latex doesn't actually need the modified search path. But, surprisingly, dvipdf and - - - - 4 April 2023 63 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - dvips do, because sometimes graphics files get generated in the output or aux directories.] @@ -4181,6 +4216,18 @@ LATEXMK(1) General Commands Manual LATEXMK(1) Note: On MS Windows, this is clock time. On other OSs it is the CPU time used (by latexmk and the child processes it invokes). + + + + 6 November 2023 64 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + The OS-dependence is because of a limitation of Windows. If you wish to force the use of clock instead of CPU time, you can set @@ -4217,17 +4264,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) A value of exactly 0 gives no delay, and typically results in 100% CPU usage, which may not be desirable. - - - 4 April 2023 64 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - $texfile_search [""] This is an obsolete variable, replaced by the @default_files variable. @@ -4245,10 +4281,22 @@ LATEXMK(1) General Commands Manual LATEXMK(1) while running. The default under MSWindows (including cygwin), is to set $tm- - pdir to the value of the first of whichever of the system envi- - ronment variables TMPDIR or TEMP exists, otherwise to the cur- - rent directory. Under other operating systems (expected to be - UNIX/Linux, including OS-X), the default is the value of the + pdir to the value of the first of whichever of the system + + + + 6 November 2023 65 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + + environment variables TMPDIR or TEMP exists, otherwise to the + current directory. Under other operating systems (expected to + be UNIX/Linux, including OS-X), the default is the value of the system environment variable TMPDIR if it exists, otherwise "/tmp". @@ -4282,18 +4330,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) When the variable is non-zero, latexmk at the end of its run will return a non-zero status code to the operating system if - - - - 4 April 2023 65 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - any of the files processed gives a warning about problems with citations or references (i.e., undefined citations or references or multiply defined references). This is after latexmk has com- @@ -4312,6 +4348,18 @@ LATEXMK(1) General Commands Manual LATEXMK(1) ings as errors that require the overall build process to be aborted. Of course, since multiple runs of *latex are generally needed to resolve references and citations, what matters is not + + + + 6 November 2023 66 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + the warnings on the first run, but the warnings on the last run; latexmk takes this into account appropriately. @@ -4348,18 +4396,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) Note about xelatex: latexmk uses xelatex to make an .xdv rather than .pdf file, with the .pdf file being created in a separate - - - - 4 April 2023 66 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - step. This is enforced by the use of the -no-pdf option. If %O is part of the command for invoking xelatex, then latexmk will insert the -no-pdf option automatically, otherwise you must pro- @@ -4378,6 +4414,18 @@ LATEXMK(1) General Commands Manual LATEXMK(1) not been found, and the file is given without an extension. This typically happens when LaTeX commands of the form \in- put{file} or \includegraphics{figure}, when the relevant source + + + + 6 November 2023 67 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + file does not exist. In this situation, latexmk searches for custom dependencies to @@ -4415,17 +4463,6 @@ CUSTOM DEPENDENCIES A better method is to use the subroutines that allow convenient manipu- lations of the custom dependency list. These are - - - 4 April 2023 67 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - add_cus_dep( fromextension, toextension, must, subroutine ) remove_cus_dep( fromextension, toextension ) show_cus_dep() @@ -4443,6 +4480,18 @@ LATEXMK(1) General Commands Manual LATEXMK(1) must: If non-zero, the file from which we are converting must exist, if it doesn't exist latexmk will give an error message and exit unless the -f option is specified. If must is zero and the file + + + + 6 November 2023 68 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + we are converting from doesn't exist, then no action is taken. Generally, the appropriate value of must is zero. @@ -4480,18 +4529,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) rule is invoked, with an argument that is the base name of the files in question. Simple cases just involve a subroutine invoking an external program; this can be done by following the templates below, even by - - - - 4 April 2023 68 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - those without knowledge of the Perl programming language. Of course, experts could do something much more elaborate. @@ -4509,6 +4546,18 @@ LATEXMK(1) General Commands Manual LATEXMK(1) Note for advanced usage: The operating system's environment variable TEXINPUTS can be used to specify a search path for finding files by la- tex etc. Correspondingly, when a missing file is reported, latexmk + + + + 6 November 2023 69 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + looks in the directories specified in TEXINPUTS as well as in the cur- rent directory, to find a source file from which an instance of a cus- tom dependency can be used to make the missing file. @@ -4546,18 +4595,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) of the form of a variable name, $_[0] in this case, is to be substi- tuted by its value. - - - - 4 April 2023 69 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - If the return value of the subroutine is non-zero, then latexmk will assume an error occurred during the execution of the subroutine. In the above example, no explicit return value is given, and instead the @@ -4575,6 +4612,18 @@ LATEXMK(1) General Commands Manual LATEXMK(1) } Note 1: In the command lines given in the system commands in the above + + + + 6 November 2023 70 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + examples, double quotes have been inserted around the file names (im- plemented by '\"' in the Perl language). They immunize the running of the program against special characters in filenames. Very often these @@ -4613,17 +4662,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) remove_cus_dep( 'fig', 'eps' ); - - - 4 April 2023 70 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - If you have complicated sets of custom dependencies, you may want to get a listing of the custom dependencies. This is done by using the line @@ -4639,13 +4677,25 @@ LATEXMK(1) General Commands Manual LATEXMK(1) file. This method has been available since very old versions of la- texmk, and many examples can be found, e.g., on the web. - However in later versions of latexmk the internal structure of the im- - plementation of its "rules" for the steps of processing, including cus- - tom dependencies, became much more powerful. The function implementing - a custom dependency is executed within a special context where a number - of extra variables and subroutines are defined. Publicly documented - ones, intended to be long-term stable, are listed below, under the - heading "Variables and subroutines for processing a rule". + However in later versions of latexmk the internal structure of the + + + + 6 November 2023 71 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + + implementation of its "rules" for the steps of processing, including + custom dependencies, became much more powerful. The function imple- + menting a custom dependency is executed within a special context where + a number of extra variables and subroutines are defined. Publicly doc- + umented ones, intended to be long-term stable, are listed below, under + the heading "Variables and subroutines for processing a rule". Examples of their use is given in the following examples, concerning multiple index files and glossaries. @@ -4678,18 +4728,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) function to simplify the definitions to use a single function: add_cus_dep( 'ndx', 'nnd', 0, 'dx2nd' ); - - - - 4 April 2023 71 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - add_cus_dep( 'adx', 'and', 0, 'dx2nd' ); sub dx2nd { return Run_subst( "makeindex -o %D %S" ); @@ -4706,6 +4744,18 @@ LATEXMK(1) General Commands Manual LATEXMK(1) push @generated_exts, 'ndx', 'nnd', 'adx', 'and'; This last example uses the command specification in $makeindex, and so + + + + 6 November 2023 72 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + any customization you have made for the standard index also applies to your extra indexes. @@ -4744,18 +4794,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) } This method still works, and is almost equivalent to the code given - - - - 4 April 2023 72 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - earlier that used the add_cus_dep subroutine. However, the old method doesn't delete any previous custom-dependency for the same conversion. So the new method is preferable. @@ -4771,8 +4809,20 @@ Advanced configuration: Some extra resources and advanced tricks See also the section DEALING WITH ERRORS, PROBLEMS, ETC. See also the examples in the directory example_rcfiles in the latexmk distributions. - Even if none of the examples apply to your case, they may give you use- - ful ideas + Even if none of the examples apply to your case, they may give you + + + + 6 November 2023 73 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + + useful ideas Utility subroutines @@ -4809,20 +4859,8 @@ Advanced configuration: Some extra resources and advanced tricks nal" -- see the section FORMAT OF COMMAND SPECIFICATIONS. When you use a subroutine for processing a rule, all the possibilities - of Perl programming are available, of course. In addition, some of - - - - 4 April 2023 73 - - - - - -LATEXMK(1) General Commands Manual LATEXMK(1) - - - latexmk's internal variables and subroutines are available. The ones + of Perl programming are available, of course. In addition, some of la- + texmk's internal variables and subroutines are available. The ones listed below are intended to be available to (advanced) users, and their specifications will generally have stability under upgrades. Gen- erally, the variables should be treated as read-only: Changing their @@ -4837,17 +4875,87 @@ LATEXMK(1) General Commands Manual LATEXMK(1) This gives the name of the primary source file. Note the double dollar signs. + + + + + 6 November 2023 74 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + $$Pdest This gives the name of the main output file if any. Note the double dollar signs. + + pushd( path ), popd() + These subroutines are used when it is needed to temporarily + change the working directory, as in + + pushd( 'some_directory' ); + ... Processing done with 'some_directory' as the working + directory + popd() + + They perform exactly the same function as the commands of the + same names in operating system command shells like bash on Unix, + and cmd.exe on the Windows. + + + rdb_add_generated( file, ... ) + This subroutine is to be used in the context of a rule, that is, + from within a subroutine that is carrying out processing of a + rule. Such is the case for the subroutine implementing a custom + dependency, or the subroutine invoked by using the "internal" + keyword in the command specification like that in the variable + $latex. + + Its arguments are a sequence of filenames which are generated + during the running of the rule. The names might arise from an + analysis of the results of the run, e.g., in a log file, or from + knowledge of properties of the specific rule. Calling + rdb_add_generated with these filenames ensures that these files + are flagged as generated by the rule in latexmk's internal data + structures. Basically, no action is taken if the files have al- + ready been flagged as generated. + + A main purpose of using this subroutine is for the situation + when a generated file is also the source file for some rule, so + that latexmk can correctly link the dependency information in + its network of rules. + + Note: Unlike some other subroutines in this section, there is no + argument for a rule for rdb_add_generated. Instead, the subrou- + tine is to be invoked during the processing of a rule when la- + texmk has set up an appropriate context (i.e., appropriate vari- + ables). In contrast, subroutines with a rule argument can be + used also outside a rule context. + + rdb_ensure_file( $rule, file ) - This a subroutine that ensures that the given file is among the - source files for the specified rule. It is typically used when, - during the processing of a rule, it is known that a particular - extra file is among the dependencies that latexmk should know, - but its default methods don't find the dependency. Almost always - the first argument is the name of the rule currently being pro- + This subroutine ensures that the given file is among the source + files for the specified rule. It is typically used when, during + the processing of a rule, it is known that a particular extra + file is among the dependencies that latexmk should know, but its + + + + 6 November 2023 75 + + + + + +LATEXMK(1) General Commands Manual LATEXMK(1) + + + default methods don't find the dependency. Almost always the + first argument is the name of the rule currently being pro- cessed, so it is then appropriate to specify it by $rule. For examples of its use, see some of the files in the directory @@ -4857,16 +4965,34 @@ LATEXMK(1) General Commands Manual LATEXMK(1) where latexmk's normal processing fails to detect certain extra source files. + Note that rdb_ensure_file only has one filename argument, unlike + other subroutines in this section. If you want to apply its ac- + tion to multiple files, you will need one call to rdb_en- + sure_file for each file. + + rdb_remove_files( $rule, file, ... ) - This subroutine removes one or more files from the dependency + This subroutine removes one or more files from the dependency list for the given rule. + + rdb_remove_generated( file, ... ) + This subroutine is to be used in the context of a rule, that is, + from within a subroutine that is carrying out processing of a + rule. It performs the opposite action to rdb_add_generated. + Its effect is to ensure that the given filenames are not listed + in latexmk's internal data structures as being generated by the + rule. + + rdb_list_source( $rule ) This subroutine returns the list of source files (i.e., the de- pendency list) for the given rule. + rdb_set_source( $rule, file, ... ) + rdb_set_source( $rule, @files ) This subroutine sets the dependency list for the given rule to be the specified files. Files that are already in the list have @@ -4876,10 +5002,16 @@ LATEXMK(1) General Commands Manual LATEXMK(1) dency list. + Run_subst( command_spec ) + This subroutine runs the command specified by command_spec. The + specification is a string in the format listed in the section + "Format of Command Specifications". An important action of the + Run_subst is to make substitutions of placeholders, e.g., %S and + %D for source and destination files; these get substituted - 4 April 2023 74 + 6 November 2023 76 @@ -4888,14 +5020,8 @@ LATEXMK(1) General Commands Manual LATEXMK(1) LATEXMK(1) General Commands Manual LATEXMK(1) - Run_subst( command_spec ) - This subroutine runs the command specified by command_spec. The - specification is a string in the format listed in the section - "Format of Command Specifications". An important action of the - Run_subst is to make substitutions of placeholders, e.g., %S and - %D for source and destination files; these get substituted be- - fore the command is run. In addition, the command after substi- - tution is printed to the screen unless latexmk is running in + before the command is run. In addition, the command after sub- + stitution is printed to the screen unless latexmk is running in silent mode. @@ -4942,10 +5068,16 @@ LATEXMK(1) General Commands Manual LATEXMK(1) Note that when '%O' appears after the added option, as here, options provided on the command line to latexmk can override the supplied one. + A more general command line can be set up by using the placeholder '%C' + in CMD_SPEC. The '%C' is substituted by the basic name of the command, + i.e., whichever of 'latex', 'pdflatex', etc is appropriate. (More than + one occurrence of '%C' is allowed.) For example to use the develop- + ment/pre-release versions of latex, etc, which have names, 'latex-dev', + 'pdflatex-dev', etc, you could use - 4 April 2023 75 + 6 November 2023 77 @@ -4954,13 +5086,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) LATEXMK(1) General Commands Manual LATEXMK(1) - A more general command line can be set up by using the placeholder '%C' - in CMD_SPEC. The '%C' is substituted by the basic name of the command, - i.e., whichever of 'latex', 'pdflatex', etc is appropriate. (More than - one occurrence of '%C' is allowed.) For example to use the develop- - ment/pre-release versions of latex, etc, which have names, 'latex-dev', - 'pdflatex-dev', etc, you could use - set_tex_cmds( '%C-dev %O %S' ); This results in $latex = 'latex-dev %O %S', etc. (The pre-release pro- @@ -5008,25 +5133,25 @@ LATEXMK(1) General Commands Manual LATEXMK(1) suitable Makefile is like .PHONY : FORCE_MAKE + all : try.pdf + %.pdf : %.tex FORCE_MAKE + latexmk -pdf -dvi- -ps- $< + (Note: the last line must be introduced by a tab for the Makefile to + function correctly!) Naturally, if making try.pdf from its associated + LaTeX file try.tex were the only task to be performed, a direct use of - 4 April 2023 76 + 6 November 2023 78 -LATEXMK(1) General Commands Manual LATEXMK(1) +LATEXMK(1) General Commands Manual LATEXMK(1) - all : try.pdf - %.pdf : %.tex FORCE_MAKE - latexmk -pdf -dvi- -ps- $< - (Note: the last line must be introduced by a tab for the Makefile to - function correctly!) Naturally, if making try.pdf from its associated - LaTeX file try.tex were the only task to be performed, a direct use of latexmk without a Makefile would normally be better. The benefit of using a Makefile for a LaTeX document would be in a larger project, where lines such as the above would be only be a small part of a larger @@ -5074,10 +5199,17 @@ LATEXMK(1) General Commands Manual LATEXMK(1) dles automatic dependency tracking of C source files. After each run of latexmk, dependency information is put in a file in + the .deps subdirectory. The Makefile causes these dependency files to + be read by make, which now has the full dependency information for each + target .pdf file. To make things less trivial it is specificed that + two files document1.pdf and document2.pdf are the targets. The depen- + dency files are .deps/document1.pdfP and .deps/document2.pdfP. + + There is now no need for the phony prerequisite for the rule to make - 4 April 2023 77 + 6 November 2023 79 @@ -5086,13 +5218,6 @@ LATEXMK(1) General Commands Manual LATEXMK(1) LATEXMK(1) General Commands Manual LATEXMK(1) - the .deps subdirectory. The Makefile causes these dependency files to - be read by make, which now has the full dependency information for each - target .pdf file. To make things less trivial it is specificed that - two files document1.pdf and document2.pdf are the targets. The depen- - dency files are .deps/document1.pdfP and .deps/document2.pdfP. - - There is now no need for the phony prerequisite for the rule to make .pdf files from .tex files. But I have added a rule to make .pdf files from .fig files produced by the xfig program; these are commonly used for graphics insertions in LaTeX documents. Latexmk is arranged to @@ -5140,24 +5265,23 @@ NON_ASCII CHARACTERS IN FILENAMES, RC FILES, ETC names on Windows, even though there were no corresponding problems on macOS and Linux. These problems are corrected in the present version. + DETAILS TO BE FILLED IN - 4 April 2023 78 - +SEE ALSO + latex(1), bibtex(1), lualatex(1), pdflatex(1), xelatex(1). -LATEXMK(1) General Commands Manual LATEXMK(1) + 6 November 2023 80 - DETAILS TO BE FILLED IN -SEE ALSO - latex(1), bibtex(1), lualatex(1), pdflatex(1), xelatex(1). +LATEXMK(1) General Commands Manual LATEXMK(1) BUGS (SELECTED) @@ -5186,12 +5310,12 @@ THANKS TO dard form to avoid being harvested too easily.) AUTHOR - Current version, by John Collins (Version 4.80). Report bugs etc to + Current version, by John Collins (Version 4.81). Report bugs etc to his e-mail (jcc8 at psu.edu). Released version can be obtained from CTAN: <http://www.ctan.org/pkg/latexmk/>, and from the author's website - <http://www.personal.psu.edu/jcc8/latexmk/>. + <https://www.cantab.net/users/johncollins/latexmk/>. Modifications and enhancements by Evan McLean (Version 2.0) Original script called "go" by David J. Musliner (RCS Version 3.2) @@ -5209,6 +5333,14 @@ AUTHOR - 4 April 2023 79 + + + + + + + + + 6 November 2023 81 diff --git a/Master/texmf-dist/scripts/latexmk/latexmk.pl b/Master/texmf-dist/scripts/latexmk/latexmk.pl index 434da3529c6..9583f45a3fa 100755 --- a/Master/texmf-dist/scripts/latexmk/latexmk.pl +++ b/Master/texmf-dist/scripts/latexmk/latexmk.pl @@ -42,8 +42,8 @@ use warnings; $my_name = 'latexmk'; $My_name = 'Latexmk'; -$version_num = '4.80'; -$version_details = "$My_name, John Collins, 4 Apr. 2023. Version $version_num"; +$version_num = '4.81'; +$version_details = "$My_name, John Collins, 6 Nov. 2023. Version $version_num"; use Config; use File::Basename; @@ -82,7 +82,7 @@ use Cwd "chdir"; # Ensure $ENV{PWD} tracks cwd. use Digest::MD5; # **WARNING**: Don't import time; that overrides core function time(), and messes up -# +# somethings use Time::HiRes; ################################################# @@ -312,6 +312,7 @@ sub fprint8 { # v. pdflatexmk, etc): (our $invoked_name) = fileparseA($0); +# Save name, since I override it if I don't recognize it our $invoked_kind = $invoked_name; print "$My_name: Invoked as '$invoked_name'\n" if ($invoked_name ne 'latexmk'); @@ -360,6 +361,11 @@ else { # It is the parameter max_print_line in the TeX program. (tex.web) $log_wrap = 79; +# Expected biggest construct in log file in bytes. +# Use to limit number of (potentially) wrapped lines to combine into single line. +$max_log_construct = 600; + + ######################################################################### ## Default parsing and file-handling settings @@ -372,8 +378,8 @@ $log_wrap = 79; ## push @file_not_found, '^No data file found `([^\\\']*)\\\''; ## will give match to line starting "No data file found `filename'" @file_not_found = ( - '^No file\\s*(.*)\\.$', - '^No file\\s*(.+)\s*$', + '^No file\\s+(.*)\\.$', + '^No file\\s+(.+)\s*$', '^\\! LaTeX Error: File `([^\\\']*)\\\' not found\\.', '^\\! I can\\\'t find file `([^\\\']*)\\\'\\.', '.*?:\\d*: LaTeX Error: File `([^\\\']*)\\\' not found\\.', @@ -559,7 +565,7 @@ $input_extensions{xelatex} = $input_extensions{pdflatex}; # and because of the possibility of extra bibtex/biber rules with # non-standard basename. @generated_exts = ( 'aux', 'bcf', 'fls', 'idx', 'ind', 'lof', 'lot', - 'out', 'toc', + 'out', 'run.xml', 'toc', 'blg', 'ilg', 'log', 'xdv' ); @@ -1459,7 +1465,7 @@ our $times_are_clock = ($^O eq "MSWin32" ); # Data for 1 run and global (ending in '0'): -our ( $processing_time1, $processing_time0, @timings1, @timings0); +our ( $clock1, $processing_time1, $processing_time0, @timings1, @timings0); &init_timing_all; @@ -1913,8 +1919,21 @@ elsif ($HOME ne '') { %rc_files_read2 = (); # Map **abs** filename to 1; used to check duplicate reads. # Options that are to be obeyed before rc files are read: +# Also under MSWin32 and msys, CL arguments sometimes get quotes in them. +# (Specific example: TeXLive 2023 with msys's perl and arguments containing +# both non-ASCII character, when latexmk.exe invoked from cmd.exe. In some +# other situations (powershell and msys's terminal+bash), it seems that both +# space and non-ASCII character are needed to trigger a problem.) foreach $_ ( @ARGV ) { + if ( ($^O eq "MSWin32") || ($^O eq 'msys') ) { + # "arg" -> arg. + # -..="arg" -> -..=arg. + # In both cases, only do this if there are no other ". Otherwise I + # my run afoul of " that are intended to be there. + s/^\"([^\"]+)\"$/$1/; + s/^(-[^\"=]+=)\"([^\"]+)\"$/$1$2/; + } if (/^-{1,2}norc$/ ) { $auto_rc_use = 0; } @@ -2020,8 +2039,18 @@ while (defined($_ = $ARGV[0])) { elsif (/^-diagnostics/) { $diagnostics = 1; } elsif (/^-dir-report$/) { $aux_out_dir_report = 1; } elsif (/^-dir-report-$/) { $aux_out_dir_report = 0; } - elsif (/^-dvi$/) { $dvi_mode = 1; } - elsif (/^-dvilua$/) { $dvi_mode = 2; } + elsif (/^-dvi$/) { $dvi_mode = 1; + if ( ($pdf_mode != 2) && ($pdf_mode != 3) ) { + # if pdf_mode is not via dvi or pdf, turn it off + $pdf_mode = 0; + } + } + elsif (/^-dvilua$/) { $dvi_mode = 2; + if ( ($pdf_mode != 2) && ($pdf_mode != 3) ) { + # if pdf_mode is not via dvi or pdf, turn it off + $pdf_mode = 0; + } + } elsif (/^-dvi-$/) { $dvi_mode = 0; } elsif ( /^-dvilualatex=(.*)$/ ) { $dvilualatex = $1; @@ -2101,7 +2130,10 @@ while (defined($_ = $ARGV[0])) { my $format = $1; if ($format eq 'dvi' ) { $dvi_mode = 1; - $pdf_mode = $postscript_mode = 0; + if ( ($pdf_mode != 2) && ($pdf_mode != 3) ) { + # if pdf_mode is not via dvi or pdf, turn it off + $pdf_mode = 0; + } } elsif ($format eq 'pdf' ) { $pdf_mode = 1; @@ -2117,12 +2149,12 @@ while (defined($_ = $ARGV[0])) { $preview_mode = 0; } elsif (/^-p-$/) { $printout_mode = 0; } - elsif (/^-pdf$/) { $pdf_mode = 1; } + elsif (/^-pdf$/) { $pdf_mode = 1; $dvi_mode = $postscript_mode = 0; } elsif (/^-pdf-$/) { $pdf_mode = 0; } elsif (/^-pdfdvi$/){ $pdf_mode = 3; } - elsif (/^-pdflua$/){ $pdf_mode = 4; } + elsif (/^-pdflua$/){ $pdf_mode = 4; $dvi_mode = $postscript_mode = 0; } elsif (/^-pdfps$/) { $pdf_mode = 2; } - elsif (/^-pdfxe$/) { $pdf_mode = 5; } + elsif (/^-pdfxe$/) { $pdf_mode = 5; $dvi_mode = $postscript_mode = 0; } elsif (/^-pdflatex$/) { $pdflatex = "pdflatex %O %S"; $pdf_mode = 1; @@ -2150,7 +2182,12 @@ while (defined($_ = $ARGV[0])) { &exit_help("$My_name: unknown print type '$value' in option '$_'"); } } - elsif (/^-ps$/) { $postscript_mode = 1; } + elsif (/^-ps$/) { $postscript_mode = 1; + if ( ($pdf_mode != 2) && ($pdf_mode != 3) ) { + # if pdf_mode is not via dvi or pdf, turn it off + $pdf_mode = 0; + } + } elsif (/^-ps-$/) { $postscript_mode = 0; } elsif (/^-pv$/) { $preview_mode = 1; $preview_continuous_mode = 0; # to avoid conflicts @@ -2391,7 +2428,10 @@ else { push( @file_list, $file) unless ( exists $excl{$file} ); } if ( !@file_list ) { - &exit_help( "No file name specified, and I couldn't find any"); + &exit_help( + "No file name(s) specified on command line, and no files match the\n". + "patterns in the default list." + ); } } @@ -2715,10 +2755,17 @@ foreach $filename ( @file_list ) $failure_msg = ''; # Indicate reason for failure if ( $do_cd ) { - ($filename, $path) = fileparse( $filename ); - print "$My_name: Changing directory to '$path'\n" - if !$silent; - pushd( dirname_no_tail( $path ) ); + # Use my fileparse routine rather than the built-in one, otherwise + # under msys, a directory separator \ won't be recognized by fileparse. + # My routines fix that. At this point, $filename ought to have had its + # \s changed to /s. But I won't leave boobytrapped code. + # I use fileparseB rather than fileparseA, because fileparseA changes + # path './' to '', but fileparseB keeps the fileparse behavior there. + # I have to supply an explicit pattern of '' to keep extension in $filename. + ($filename, $path) = fileparseB( $filename, '' ); + print "$My_name: Changing directory to '$path'\n" + if !$silent; + pushd( dirname_no_tail( $path ) ); } else { $path = ''; @@ -2853,7 +2900,7 @@ foreach $filename ( @file_list ) &init_timing1; if ($compiling_cmd) { Run_subst( $compiling_cmd ); } - $failure = &rdb_make; + $failure = rdb_make(); if ( ( $failure <= 0 ) || $force_mode ) { rdb_for_some( [keys %one_time], \&rdb_run1 ); } @@ -2896,7 +2943,7 @@ continue { push @failed_primaries, $filename; } &ifcd_popd; - if ($show_time) { &show_timing1; }; + if ($show_time && ! $preview_continuous_mode) { &show_timing1; }; print "\n"; } close($deps_handle) if ( $deps_handle ); @@ -2981,6 +3028,7 @@ sub init_timing1 { # Initialize timing for one run. @timings1 = (); $processing_time1 = processing_time(); + $clock1 = Time::HiRes::time(); } ############################ @@ -2997,8 +3045,17 @@ sub init_timing_all { sub show_timing1 { # Show timing for one run. my $processing_time = processing_time() - $processing_time1; + my $invoked_time = 0; + for (@timings1) { + if (/: time = (.*)\s$/) { + $invoked_time += $1; + }} print @timings1, "Processing time = ", - sprintf('%.2f', $processing_time), "\n"; + sprintf('%.2f', $processing_time), + ", of which invoked processes = $invoked_time, other = ", + sprintf( '%.2f', $processing_time-$invoked_time ), ".\n"; + print "Elapsed clock time = ", + sprintf( '%.2f', Time::HiRes::time()-$clock1 ), ".\n"; print "Number of rules run = ", 1+$#timings1, "\n"; } @@ -4194,7 +4251,7 @@ CHANGE: if ($compiling_cmd) { Run_subst( $compiling_cmd ); } - $failure = &rdb_make; + $failure = rdb_make(); if ( $MSWin_fudge_break && ($^O eq "MSWin32") ) { $SIG{BREAK} = $SIG{INT} = 'DEFAULT'; @@ -4381,7 +4438,16 @@ sub process_rc_file { my ($rc_file, $repeat_reaction) = @_; my $abs_rc = abs_path($rc_file); my $ret_code = 0; - if ( exists $rc_files_read2{$abs_rc} ) { + if ( (!-e $rc_file) || ( ! defined $abs_rc ) ) { + warn "$My_name: The rc-file '$rc_file' does not exist\n"; + return 1; + } + elsif ( -d $rc_file ) { + warn "$My_name: The supposed rc-file '$rc_file' is a directory; but it\n", + " should be a normal text file\n"; + return 1; + } + elsif ( exists $rc_files_read2{$abs_rc} ) { if ( $repeat_reaction ) { warn "$My_name: A user -r option asked me to process an rc file an extra time.\n", @@ -4407,16 +4473,7 @@ sub process_rc_file { # current versions of Perl (Nov. 2022), so "do latexmkrc;" for # latexmkrc in cwd fails. # So I'll read the rc file and eval its contents. - if ( !-e $rc_file ) { - warn "$My_name: The rc-file '$rc_file' does not exist\n"; - return 1; - } - elsif ( -d $rc_file ) { - warn "$My_name: The supposed rc-file '$rc_file' is a directory; but it\n", - " should be a normal text file\n"; - return 1; - } - elsif ( open( my $RCH, "<", $rc_file ) ) { + if ( open( my $RCH, "<", $rc_file ) ) { my $code = ''; # Read all contents of file into $code: { local $/ = undef; $code = <$RCH>;} @@ -5188,7 +5245,7 @@ sub set_names { #************************************************** -sub correct_aux_out_files { +sub correct_locations { # Deal with situations after a *latex run where files are in different # directories than expected (specifically aux v. output directory). # Do minimal fix ups to allow latexmk to analyze dependencies with log @@ -5279,7 +5336,7 @@ sub correct_aux_out_files { warn "$My_name: fls file doesn't appear to have been made.\n"; } } -} # END correct_aux_out_files +} # END correct_locations #----------------- @@ -6197,28 +6254,68 @@ sub get_log_file { # ref to array to receive lines, # ref to hash to receive diagnostic etc informaion ) # 3rd argument is optional - # Lines are unwrapped and converted to CS_system. + # Lines are unwrapped and converted to the CS_system coding system (so + # that filenames are suitable for use in file opening calls and on + # command line to invoked programs). + # + # **Complication**: When writing to the .log file, *latex converts + # lines longer than a given length (by default, 79) to a sequence + # of lines with at most the maximum length. + # This subroutine converts such sequences of lines to the original + # unwrapped form. + # **However**, + # 1. The algorithm for line wrapping differs between all of pdflatex, + # xelatex, and lualatex. See below for details. + # 2. It is possible to write an unwrapped line L1 of a relevant + # length followed by a shorter line L2, such that it is impossible + # to distingish it from a wrapped line whose contents were those + # of L1 concatenated with L2. + # So when it is determined that a line is potentially wrapped, + # several possibilities for the unwrapped lines are added to the + # output array of lines (referenced by the second argument), so that + # subsequent scanning of the lines in the subroutine parse_log picks + # up the possible diagnostic messages independently of complications + # in identifying wrapped lines versus unwrapped lines. my ($file, $PAlines, $PHinfo) = @_; - # Where lines are wrapped at. We'll sometimes override. local $log_wrap = $log_wrap; + # Lines held for wrapping: + my @held_lines = (); + # Routine for setting wrapped lines; setup by assignment to keep visibility + # in the enclosing subroutine, and to access its my-variables: + my $Pwrap_sub = + sub { + for ( my $i=0; $i <= $#held_lines; $i++ ) { + my $line = ''; + for ( my $j=$i; $j <= $#held_lines; $j++ ) { + last if ($j-$i > 1 + ($max_log_construct /$log_wrap) ); + $line .= $held_lines[$j]; + push @$PAlines, $line; + } + } + @held_lines = (); + }; + + my $engine = ''; my $tex_distribution = ''; - my ($line_num, $cont, $max_len) = ( 0, 0, 0 ); + my ($line_num, $max_len) = ( 0, 0 ); my $lua_mode = 0; # Whether to use luatex-specific wrapping method. - my $byte_wrapping = 1; # *latex does byte wrapping. Modify if we find - # log file is generated by a tex program that - # wrapping by Unicode code points. - + my $byte_wrapping = 1; # Assume by default that the wrapping occurs at + # a certain number of bytes. Modify this + # variable if we find that the log file was + # generated by a tex program that does wrapping + # at a certain number of Unicode code points. + # The details for the different programs (underlying the *latex programs): # File encoding: pdftex: UTF-8 but with wrapping at $log_wrap BYTES. # (So individual wrapped lines can be malformed # UTF-8, but we get valid UTF-8 after unwrapping.) # luatex: UTF-8 but with wrapping at APPROXIMATELY # $log_wrap bytes. Rest as pdftex # xetex: UTF-8 with wrapping at $log_wrap codepoints. - # So we read file as bytes + # So we read file as bytes. Then # first line gives which program was used and hence whether to wrap # according to byte or codepoint count. # wrapping is always performed on the encoded byte strings, but the @@ -6262,17 +6359,46 @@ sub get_log_file { } if ($len > $max_len) { $max_len = $len } - # Is this line continuation of previous line? - if ($cont) { $$PAlines[$#$PAlines] .= $_; } - else { push @$PAlines, $_ } - # Is this line wrapped? I.e., is next line to be appended to it? - # Allow for fact that luatex doesn't reliably wrap at std place, e.g., 79. - $cont = ($len == $log_wrap) + # 2 cases: + # pdflatex and xelatex wrap at exactly length $log_wrap + # (default 79), and normally append empty line when line + # is exactly of the maximimum length (so we shouldn't have a + # problem of distinguishing a wrapped line from a line of + # length exactly $log_wrap). + # lualatex: Wrap at a variable position dependent in a complicated + # way on contents. With default settings, wrapping occurs + # between 77 and 80 bytes, according to my tests. It preserves + # UTF-8 coding, and doesn't split multi-byte UTF-8 coding of + # a code point between lines, unlike pdflatex. But details + # of exactly where a line is wrapped is not clear. + # It is not possible in all cases to distinguish whether + # a pair of lines arise from wrapping of a longer line + # or from actual writing of a pair of lines. + # Determine whether line is potentially wrapped: + my $cont = ($len == $log_wrap) || ( $lua_mode && ($len >= $log_wrap-2) && ($len <= $log_wrap+1) ); - if ($cont && $diagnostics ) { - print "====Continuing line $line_num of length $len\n$_\n"; + if ($cont) { + # Save lines that may be continued onto @held_lines + print "====Continuing line $line_num of length $len\n$_\n" + if $diagnostics; + push @held_lines, $_; + } + elsif (@held_lines) { + # No more continuation lines after this: + push @held_lines, $_; + # Put possibilities for lines before wrapping onto the main + # array and then clear @held_lines + &$Pwrap_sub(); } + else { + push @$PAlines, $_; + } + } + if (@held_lines) { + # Get here if the last line of the file is of a length that + # it may be a wrapped. + &$Pwrap_sub(); } close($fh); foreach (@$PAlines) { $_ = utf8_to_mine($_); } @@ -6330,7 +6456,7 @@ sub parse_fls { # is produced by MS-Windows program (e.g., in MiKTeX) with CRLF line ends, # but is read by Unix Perl (which treats LF as line end, and preserves CRLF # in read-in lines): - # And convert '\' + # And convert '\' to '/' s/\r?\n$//; s[\\][/]g; $line_no++; @@ -6340,10 +6466,17 @@ sub parse_fls { } else { # Deal with MS-Win issues when system CP isn't UTF-8 - if ( ($^O eq 'MSWin32') && /PWD/ && ! is_valid_utf8($_) ) { - # TeXLive on MSWin produces PWD in CS_system not UTF-8. - # ???? Later get tex_distribution before analyzing fls file, so do better test. - print "PWD line not in UTF-8. This is normal for TeXLive. I will handle it.\n"; + # Situation is that the fls file should be in UTF-8 and + # needs to be converted to system CP to fit with latexmk's + # convention (determined by file-system calls). + # However, under Windows' TeXLive 2021 (and maybe earlier) the + # PWD uses the system CP while the rest of the file is UTF-8. + # In TeXLive 2022 and 2023, the whole file, including the PWD + # line is UTF-8. + # So give special treatment to PWD line under Windows. + # Also to guard against any other problems, check for non-UTF-8 lines. + if ( ($^O eq 'MSWin32') && /PWD/ && ! is_valid_utf8($_) ) { print + "PWD line not in UTF-8. This is normal for older TeXLives (2021 and earlier).\n". "I will handle it.\n"; # Assume in CS_system, no change needed. } elsif ( ! is_valid_utf8($_) ) { @@ -6548,8 +6681,12 @@ sub normalize_filename { sub normalize_filename_abs { # Convert filename to be either # absolute path in canonical form - # or relative to cwd. - return normalize_filename( abs_path($_[0]) ); + # or relative to cwd, if possible. + # abs_path returns undef if it doesn't know how to get an absolute path. + # Just work with the original path in that case. + my $abs = abs_path($_[0]); + if (! defined $abs) { $abs = $_[0]; } + return normalize_filename( $abs ); } #----------------------------- @@ -6770,7 +6907,7 @@ sub parse_bcf { return 2; } - show_array( "$My_name: Bibliography file(s) form .bcf file:", @$Pbib_files ) + show_array( "$My_name: Bibliography file(s) from .bcf file:", @$Pbib_files ) unless $silent; if (@not_found_bib) { show_array( @@ -8175,6 +8312,10 @@ DEP: " I'll try making it with allowed extensions \n"; foreach my $try_ext ( keys %$Pinput_extensions ) { my $new_dest = "$file.$try_ext"; + if (-e $new_dest) { + # A file that exists cannot have been the missing file. + next; + } &Run_subst( "$make $quote$new_dest$quote" ); if ( -e $new_dest ) { print "SUCCESS in making '$new_dest'\n", @@ -8462,31 +8603,27 @@ sub rdb_make { # no error in the run, the source-file-state is **not** updated # after the rule is run. Then on a subsequent pass through # rdb_make's main loop, when the rule is tested for a rerun, any - # change in source file contents is cause for running the rule - # again. - # 8. But after a run giving an error, the state of the generated - # files (i.e., non-user files) is updated to the current state. - # This is because the error (under normal circumstances) must be - # corrected by user action: e.g., correcting a source file, and - # possibly deleting some corrupted auxiliary file. Files (e.g., - # .aux by *latex) generated by the rule just run may well have - # changed, so updating their state to the current state prevents - # another run before a user change. If a file was generated by - # another rule, it won't have changed its state, so updating its - # state won't matter. But a non-generated file is a - # user-created file, and a rerun is entailed if its contents - # changed compared with the start of the run; it's the - # start-of-run contents that were used in the error run. - # 9. Note: an error may be caused by a problem with a file - # generated by another rule, e.g., a bbl file created by bibtex - # and read by *latex, but with no error reported by bibtex. To - # correct the error a source file (possibly more than once - # removed must be changed). That triggers a rerun of the - # producing rule, and after that the resulting change causes a - # rerun of the original rule that had the error. E.g., - # correcting a .bib file causes bibtex to run, producing a - # corrected .bbl file, after which *latex is caused to be run. - # 10. With circular dependencies, there is a choice of which order + # change in source file contents since the start of the previous + # run is cause for running the rule again. + # 8. When there is an error, and force_mode is off, processing of + # all further rules is terminated. A problem is then caused for + # a later invocation of latexmk (or, in -pvc mode, the next + # scanning of source-file status): It may be that a generated + # file from a run of some rule changed compared with its status + # before the run. Because of the termination of processing + # there was no rerun of the rule. New runs should only be made + # after a change in the user-written files, which give the + # possibility of correcting the error. But on a subsequent + # invocation of latexmk it could appear that some rule(s) is/are + # out-of-date because of the changed generated files, which + # would result in unneeded extra runs, which will tend to + # pollute the screen output with misleading downstream + # consequences of the original error. + # To avoid this problem, after an error-generating round of + # compilations, the cached state of generated files is updated + # to their state after the compilations. Then only user-caused + # file changes will be cause for new runs. + # 9. With circular dependencies, there is a choice of which order # to examine the rules. Generally, primary rules are more # time-consuming than most others, so the choice of the order of # examination of rules to check out-of-dateness is to try to @@ -8495,7 +8632,7 @@ sub rdb_make { # graphics. These are normally outside a dependency loop, so # those are left to last. Even if they are inside a dependency # loop, they need the primary rule to have been run first. - # 11. After rdb_make is run, all non-user source files are updated + # 10. After rdb_make is run, all non-user source files are updated # to their current state. Rules are considered up-to-date # here. On a subsequent call to rdb_make, subsequent changes are # relevant to what is to be done. Note: the states of user @@ -8625,7 +8762,7 @@ sub rdb_make { } if ( ($runs > 0) && ! $too_many_passes ) { $retry_msg = 0; - if ( $force_mode || (! $failure) || $switched_primary_output ) { + if ( $force_mode || (! $failure) ) { next PASS; } # Get here on failure, without being in force_mode @@ -8673,7 +8810,31 @@ sub rdb_make { # but do not change primaries. # Problem is that %current_primaries gets altered &rdb_set_rule_net; - } #End PASS + } #End PASS + + if ($failure ) { + # Update state of generated source files, but not non-generated, + # i.e., user source files. Without that, when there was a termination of + # processing because of an error, it could be some generated files changed + # without reruns of the relevant rule(s) being triggered; that's because + # with an error and with force_mode off, the reruns are blocked. + # But that situation would cause reruns either when latexmk is reinvoked + # or at the next examination of file state (in -pvc mode). But those runs + # (almost certainly) won't improve the error situation in the absence of + # a change in user files, since the error is ultimately due to a problem + # with a user file. + # By updating the state of generated source files, reruns are not + # triggered until a user file is changed. + # Also turn $$Pout_of_date off for the rules. It may have been set + # at some point to trigger a rerun, but that information is now + # out-of-date, given that an error occurred. + rdb_for_some( [&rdb_accessible()], + sub{ + &rdb_update_gen_files; + $$Pout_of_date = 0; + } + ); + } rdb_for_some( [@unusual_one_time], \&rdb_make1 ); @@ -8839,7 +9000,7 @@ sub rdb_make1 { # Is this needed? Yes; rdb_make1 is called on a sequence of rules and # if one gives an error, then it provides source files directly or # indirectly to later rules, which should not be run. - if ($failure & ! $force_mode) {return;} + if ($failure && ! $force_mode) {return;} # Rule may have been created since last run. Just in case we didn't, # define $pass{$rule} elsewhere, do it here: @@ -8922,6 +9083,7 @@ sub rdb_make1 { warn_running( "Run number $pass{$rule} of rule '$rule'" ); $return = &rdb_run1; } + if ($$Pchanged) { $newrule_nofile = 1; $return = 0; @@ -8972,15 +9134,6 @@ sub rdb_make1 { if ( !$$Plast_message ) { $$Plast_message = "Run of rule '$rule' gave a non-zero error code"; } - # Update state of generated source files, but not non-generated, - # i.e., user source files. Thus any change in the rule's own - # generated source files during the run will not cause a - # rerun. Files generated by another rule should not have been - # changed during the run, so updating their saved state in this - # rule is a NOP. But any change in user files since the **start** - # of the run is a cause for a rerun, so their saved state must not - # be updated. - rdb_update_gen_files(); } foreach ( keys %$PHsource_rules ) { $$PHsource_rules{$_} = $pass{$_}; @@ -9074,7 +9227,7 @@ sub rdb_run1 { # $$Pout_of_date = $$Pout_of_date_user = 0; if ($latex_like) { - &correct_aux_out_files; + &correct_locations; run_hooks( 'after_xlatex' ); $return = analyze_latex_run( $return ); run_hooks( 'after_xlatex_analysis' ); @@ -9490,7 +9643,6 @@ sub rdb_rerun_needed { # # ???!!!! # Check all uses!!!!!!!!!!!!! - our ($rule, %pass); local our $PHchanges = shift; @@ -9628,9 +9780,7 @@ sub rdb_rerun_needed { } $$Pno_history = 0; # See comments in definition of %rule_db. if ($rerun_needed) { - $$Pout_of_date = 1; push @{$$PHchanges{rules_to_apply}}, $rule; - if (@{$$PHchanges{changed_user}}) {$$Pout_of_date_user = 1;} } return $rerun_needed; } #END rdb_rerun_needed @@ -10500,37 +10650,6 @@ sub Parray { #************************************************************ -sub analyze_string { - # Show information about string: utf8 flag or not, length(s!), byte content - my ($m,$s) = @_; - - print "=== $m "; - my $length = length($s); - if (utf8::is_utf8($s)) { - my $encoded = encode( $CS_system, $s, Encode::FB_WARN | Encode::LEAVE_SRC ); - my $len_chars = 0; - my $len_bytes = 0; - { no bytes; $len_chars = length($s); } - { use bytes; $len_bytes = length($s); } - print "'$encoded':\n", - "utf8, len = $length; chars = $len_chars; bytes = $len_bytes\n"; - } - else { - print "'$s':\n", - "NOT utf8, len = $length\n"; - } - - print join ' ', to_hex($s), "\n"; -} - -#---------------------------- - -sub to_hex { - return map { sprintf('%4X', $_) } unpack( 'U*', shift ); -} - -#================== - sub glob_list1 { # Glob a collection of filenames. # But no sorting or elimination of duplicates @@ -10691,24 +10810,30 @@ sub get_checksum_md5 { # We won't use checksum for directory return 0; } - else { - open( $input, '<:bytes', $source ) - or return 0; - my ($base, $path, $ext) = fileparseA( $source ); - $ext =~ s/^\.//; - if ( exists $hash_calc_ignore_pattern{$ext} ) { - $ignore_pattern = $hash_calc_ignore_pattern{$ext}; - } + open( $input, '<:bytes', $source ) + or return 0; + my ($base, $path, $ext) = fileparseA( $source ); + $ext =~ s/^\.//; + if ( exists $hash_calc_ignore_pattern{$ext} ) { + $ignore_pattern = $hash_calc_ignore_pattern{$ext}; } - if ( defined $ignore_pattern ) { - while (<$input>) { - if ( ! /$ignore_pattern/ ){ - $md5->add($_); + eval { + # Trap any errors that occur during reading, even though the file + # was successfully opened. + # Such errors have been known to occur under OneDrive on macOS. + if ( defined $ignore_pattern ) { + while (<$input>) { + if ( ! /$ignore_pattern/ ){ + $md5->add($_); + } } } - } - else { - $md5->addfile($input); + else { + $md5->addfile($input); + } + }; + if ($@) { + warn "$My_name: Attempt to get md5 of '$source' failed. Error=\n$@"; } close $input; return $md5->hexdigest(); @@ -11184,7 +11309,12 @@ sub ext_no_period { sub fileparseA { # Like fileparse but replace $path for current dir ('./' or '.\') by '' # Also default second argument to get normal extension. + # With msys, change all \ to / in given name since with msys, fileparse + # doesn't recognize \ as directory separator. my $given = $_[0]; + if ( $^O eq 'msys' ) { + $given =~ s[\\][/]g; + } my $pattern = '\.[^\.]*'; if ($#_ > 0 ) { $pattern = $_[1]; } my ($base_name, $path, $ext) = fileparse( $given, $pattern ); @@ -11198,7 +11328,12 @@ sub fileparseA { sub fileparseB { # Like fileparse but with default second argument for normal extension + # With msys, change all \ to / in given name since with msys, fileparse + # doesn't recognize \ as directory separator. my $given = $_[0]; + if ( $^O eq 'msys' ) { + $given =~ s[\\][/]g; + } my $pattern = '\.[^\.]*'; if ($#_ > 0 ) { $pattern = $_[1]; } my ($base_name, $path, $ext) = fileparse( $given, $pattern ); @@ -11551,7 +11686,11 @@ sub cache_good_cwd { } # Normalized if ($normalize_names) { - $cwd = abs_path($cwd); + my $abs = abs_path($cwd); + # It's conceivable that abs_path doesn't know how to convert to an + # absolute path of a standard normalization. Then it returns undef. + # In that case, it's probably good not to try normalizing $cwd. + if (defined $abs) { $cwd = $abs; } } $cache{cwd} = $cwd; } # END cache_good_cwd |