-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlatexmk
executable file
·12342 lines (11311 loc) · 505 KB
/
latexmk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/perl
use warnings;
use strict;
## Copyright John Collins 1998-2024
## (username jcc8 at node psu.edu)
## (and thanks to David Coppit (username david at node coppit.org)
## for suggestions)
## Copyright Evan McLean
## (modifications up to version 2)
## Copyright 1992 by David J. Musliner and The University of Michigan.
## (original version)
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
##
## See file CHANGES for list of main version-to-version changes.
##
## Modified by Evan McLean (no longer available for support)
## Original script (RCS version 2.3) called "go" written by David J. Musliner
##
##-----------------------------------------------------------------------
## Explicit exit codes:
## 10 = bad command line arguments
## 11 = file specified on command line not found
## or other file not found
## 12 = failure in some part of making files
## 13 = error in initialization file
## 20 = probable bug
## or retcode from called program.
our ($my_name, $My_name, $version_num, $version_details);
BEGIN {
# Make sure the following are available when printing diagnostics in BEGIN
# blocks.
$my_name = 'latexmk';
$My_name = 'Latexmk';
$version_num = '4.83';
$version_details = "$My_name, John Collins, 31 Jan. 2024. Version $version_num";
}
use Config;
use File::Basename;
use File::Copy;
use File::Spec::Functions qw( catfile file_name_is_absolute rel2abs );
# If possible, use better glob, which does not use space as item separator.
# It's either File::Glob::bsd_glob or File::Glob::glob
# The first does not exist in old versions of Perl, while the second
# is deprecated in more recent versions and will be removed
our $have_bsd_glob = 0;
use File::Glob;
if ( eval{ File::Glob->import('bsd_glob'); 1; } ) {
# Success in importing bsd_glob
$have_bsd_glob = 1;
}
elsif ( eval{ File::Glob->import('glob'); 1; } ) {
warn( "$My_name: I could not import File::Glob:bsd_glob, probably because your\n",
" Perl is too old. I have arranged to use the deprecated File::Glob:glob\n",
" instead.\n",
" WARNING: It may malfunction on clean up operation on filenames containing\n",
" spaces.\n" );
$have_bsd_glob = 0;
}
else {
die "Could not import 'File::Glob:bsd_glob' or 'File::Glob:glob'\n";
}
use File::Path 2.08 qw( make_path );
use FileHandle;
use File::Find;
use List::Util qw( max );
use Cwd;
use Cwd "abs_path";
use Cwd "chdir"; # Ensure $ENV{PWD} tracks cwd.
use Digest::MD5;
our %HiRes_non_imports;
use Time::HiRes;
BEGIN {
# Import some HiRes functions to override standard ones.
# However, Time::HiRes's documentation says that some of its functions
# may be unimplemented on some systems.
# So take precautions in case the ones I need aren't implemented.
# I must do the import in a BEGIN block, i.e., during compilation
# phase, else calls to time() etc get compiled to use std time(), i.e.,
# CORE::time(), instead of the HiRes versions.
%HiRes_non_imports = ();
foreach ( ( qw( time stat sleep ) ) ) {
if ( ! eval{ Time::HiRes->import($_); 1; } ) {
$HiRes_non_imports{$_} = 1;
warn "$My_name: Cannot import Time::HiRes::$_ on this system\n",
"$@";
}
}
}
#################################################
#
# Unicode set up to be used in latexmk
#
use Encode qw( decode encode );
use Unicode::Normalize;
use utf8; # Strings are coded in UTF-8 in this file, stored internally
# decoded into Perl's internal character representation.
use feature 'unicode_strings';
use feature 'say';
# Coding:
# 1. $CS_system = CS for file names in file system calls, and for CL.
# It's to be UTF-8 on all except: MSWin when the MSWin system code page is
# not 65001.
# 2. Internally use CS_system generally, and especially for filenames.
# Then standard file system calls, print to terminal don't need encoding,
# and things in rc files work unchanged from earlier versions of latexmk,
# when I didn't treat non-ASCII coding issues explicitly.
# 3. But must set console codepage to system codepage on MSWin, otherwise
# display on terminal is garbled.
# 4. fdb_latexmk: write and read UTF-8, convert to and from CS_system for
# strings.
# 5. .fls, .log, .aux are all UTF-8, so if necessary convert to CS_system.
# 6. However, with TeXLive on MSWin with system CP not equal to 65001,
# the PWD is in CS_system on all but most recent *latex (that's a bug).
# Convert file/path names to CS_system.
# 7. Don't support non-UTF-8 on *nix.
# 8. Do NOT do any conversion to a NF for Unicode: File systems and OS calls
# to access them are **either** normalization-sensitive (I think, e.g.,
# ext4) and we need to preserve normalization, **or** they are
# normalization-insensitve (e.g., hfs+, apfs), in which case we can access
# a file with any normalization for its name.
#
# N.B. I18N::Langinfo often doesn't give useful enough information.
# My default CSs: UTF-8
our $CS_system = 'UTF-8';
# Quick short cut for tests of whether conversions needed:
our $no_CP_conversions = 1;
# Win32 specific CP **numbers**. Initialize to 65001 (utf-8), and change
# by results of system calls.
# Corresponding CS name: Prefix by 'CP'.
# Preserve intial values for console/terminal to allow restore on exit.
our ($CP_Win_system, $CP_init_Win_console_in, $CP_init_Win_console_out);
$CP_Win_system = $CP_init_Win_console_in = $CP_init_Win_console_out = '65001';
# Whether to revert Windows console CPs on exit:
our $Win_revert_settings = 0;
if ($^O eq "MSWin32") {
eval { require Win32;
$CP_Win_system = Win32::GetACP();
$CS_system = 'CP' . $CP_Win_system;
$CP_init_Win_console_in = Win32::GetConsoleCP();
$CP_init_Win_console_out = Win32::GetConsoleOutputCP();
if ( Win32::SetConsoleOutputCP($CP_Win_system)
&& Win32::SetConsoleCP($CP_Win_system) ) {
} else {
warn "Cannot set Windows Console Output CP to $CP_Win_system.\n";
}
};
if ($@) { warn "Trouble finding and setting code pages used by Windows:\n",
" $@",
" I'LL CONTINUE WITH UTF-8.\n";
}
else {
$Win_revert_settings =
($CP_init_Win_console_in ne $CP_Win_system)
|| ($CP_init_Win_console_out ne $CP_Win_system);
print
"Initial Win CP for (console input, console output, system): ",
"(CP$CP_init_Win_console_in, CP$CP_init_Win_console_out, CP$CP_Win_system)\n",
"I changed them all to CP$CP_Win_system\n";
}
}
$no_CP_conversions = ($CS_system eq 'UTF-8') || ($CS_system eq 'CP65001');
# Ensure that on ctrl/C interruption, etc, Windows console CPs are restored:
use sigtrap qw(die untrapped normal-signals);
END {
if ($Win_revert_settings ) {
warn "Reverting Windows console CPs to ",
"(in,out) = ($CP_init_Win_console_in,$CP_init_Win_console_out)\n";
Win32::SetConsoleCP($CP_init_Win_console_in);
Win32::SetConsoleOutputCP($CP_init_Win_console_out);
}
}
########################################################
################################################################
################################################################
#============ Deal with how I'm invoked: name and CL args:
# Name that I'm invoked with indicates default behavior (latexmk
# 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');
# Map my invoked name to pointer to array of default values for $dvi_mode,
# $postscript_mode, $pdf_mode, $xdv_mode. These are used if after processing
# rc files and CL args, no values are set for any of these variables.
# Thus default compilation for latexmk is by latex,
# for pdflatexmk is by pdflatex, etc.
our %compilation_defaults =
( 'latexmk' => [1,0,0,0],
'lualatexmk' => [0,0,4,0],
'pdflatexmk' => [0,0,1,0],
'xelatexmk' => [0,0,5,0],
);
# If name isn't in canonical set, change it to a good default:
unless (exists $compilation_defaults{$invoked_name}) { $invoked_name = 'latexmk'; }
#==================
################################################################
################################################################
# Translation of signal names to numbers and vv:
our %signo = ();
our @signame = ();
if ( defined $Config{sig_name} ) {
my $i = 0;
foreach my $name (split('\s+', $Config{sig_name})) {
$signo{$name} = $i;
$signame[$i] = $name;
$i++;
}
}
else {
warn "Something wrong with the perl configuration: No signals?\n";
}
# Line length in log file that indicates wrapping.
# This number EXCLUDES line-end characters, and is one-based.
# It is the parameter max_print_line in the TeX program. (tex.web)
our $log_wrap = 79;
# Expected biggest construct in log file in bytes.
# Use to limit number of (potentially) wrapped lines to combine into single line.
our $max_log_construct = 600;
# Whether to search for ^^ notation in log file for non-7-bit characters,
# and convert to bytes. (Note: ^^ notation is produced by hilatex in
# TeXLive 2023, and by pdflatex in MiKTeX 22.1 if no special option is
# used (-enable-8bit-chars). (Also pdflatex in TeXLive 2023 (and earlier)
# gives it if -translate-file=empty is used.)
# Should also do same with aux files, but I've not done that yet. ????
# fls file is always UTF-8.
our $conv_hathat = 1;
#########################################################################
## Default parsing and file-handling settings
## Array of reg-exps for patterns in log-file for file-not-found
## Each item is the string in a regexp, without the enclosing slashes.
## First parenthesized part is the filename.
## Note the need to quote slashes and single right quotes to make them
## appear in the regexp.
## Add items by push, e.g.,
## push @file_not_found, '^No data file found `([^\\\']*)\\\'';
## will give match to line starting "No data file found `filename'"
our @file_not_found = (
'^No file\\s+(.*)\\.$',
'^No file\\s+(.+)\s*$',
'^\\! LaTeX Error: File `([^\\\']*)\\\' not found\\.',
'^\\! I can\\\'t find file `([^\\\']*)\\\'\\.',
'.*?:\\d*: LaTeX Error: File `([^\\\']*)\\\' not found\\.',
'^LaTeX Warning: File `([^\\\']*)\\\' not found',
'^Package .* [fF]ile `([^\\\']*)\\\' not found',
'^Package .* No file `([^\\\']*)\\\'',
'Error: pdflatex \(file ([^\)]*)\): cannot find image file',
': File (.*) not found:\s*$',
'! Unable to load picture or PDF file \\\'([^\\\']+)\\\'.',
);
# Array of reg-exps for patterns in log file for certain latex warnings
# that we will call bad warnings. They are not treated as errors by
# *latex, but depending on the $bad_warning_is_error setting
# we will treat as if they were actual errors.
our @bad_warnings = (
# Remember: \\ in perl inside single quotes gives a '\', so we need
# '\\\\' to get '\\' in the regexp.
'^\(\\\\end occurred when .* was incomplete\)',
'^\(\\\\end occurred inside .*\)',
);
our $bad_warning_is_error = 0;
# Characters that we won't allow in the name of a TeX file.
# Notes: Some are disallowed by TeX itself.
# '\' results in TeX macro expansion
# '$' results in possible variable substitution by kpsewhich called from tex.
# '"' gets special treatment.
# See subroutine test_fix_texnames and its call for their use.
our $illegal_in_texname = "\x00\t\f\n\r\$%\\~\x7F";
# Whether to normalize aux_dir and out_dir where possible.
# This is important when these directories aren't subdirectories of the cwd,
# and TeXLive's makeindex and/or bibtex are used.
our $normalize_names = 2; # Strongest kind.
## Hash mapping file extension (w/o period, e.g., 'eps') to a single regexp,
# whose matching by a line in a file with that extension indicates that the
# line is to be ignored in the calculation of the hash number (md5 checksum)
# for the file. Typically used for ignoring datestamps in testing whether
# a file has changed.
# Add items e.g., by
# $hash_calc_ignore_pattern{'eps'} = '^%%CreationDate: ';
# This makes the hash calculation for an eps file ignore lines starting with
# '%%CreationDate: '
# ?? Note that a file will be considered changed if
# (a) its size changes
# or (b) its hash changes
# So it is useful to ignore lines in the hash calculation only if they
# are of a fixed size (as with a date/time stamp).
our %hash_calc_ignore_pattern =();
# Specification of templates for extra rules.
# See subroutine rdb_initialize_rules for examples of rule templates, and
# how they get used to construct rules.
# (Documentation obviously needs to be improved!)
our %extra_rule_spec = ();
#??????? !!!!!!!!! If @aux_hooks and @latex_file_hooks are still needed,
# should I incorporate them into the general hook hash???
#
# Hooks for customized extra processing on aux files. The following
# variable is an array of references to functions. Each function is
# invoked in turn when a line of an aux file is processed (if none
# of the built-in actions have been done). On entry to the function,
# the following variables are set:
# $_ = current line of aux file
# $rule = name of rule during the invocation of which, the aux file
# was supposed to have been generated.
our @aux_hooks = ();
#
# Hooks for customized processing on lists of source and missing files.
# The following variable is an array of references to functions. Each
# function is invoked in turn after a run of latex (or pdflatex etc) and
# latexmk has analyzed the .log and .fls files for dependency information.
# On entry to each called function, the following variables are set:
# $rule = name of *latex rule
# %dependents: maps source files and possible source files to a status.
# See begining of sub parse_log for possible values.
our @latex_file_hooks = ();
#
# Single hash for various stacks of hooks:
our %hooks = ();
for ( 'before_xlatex', 'after_xlatex', 'after_xlatex_analysis' ) {
$hooks{$_} = [];
}
$hooks{aux_hooks} = \@aux_hooks;
$hooks{latex_file_hooks} = \@latex_file_hooks;
#########################################################################
## Default document processing programs, and related settings,
## These are mostly the same on all systems.
## Most of these variables represents the external command needed to
## perform a certain action. Some represent switches.
## Which TeX distribution is being used
## E.g., "MiKTeX 2.9", "TeX Live 2018"
## "" means not determined. Obtain from first line of .log file.
our $tex_distribution = '';
# List of known *latex rules:
our %possible_primaries = ( 'dvilualatex' => 'primary', 'hilatex' => 'primary',
'latex' => 'primary',
'lualatex' => 'primary', 'pdflatex' => 'primary',
'xelatex' => 'primary' );
# Command strings for them:
our ($dvilualatex, $hilatex, $latex, $lualatex, $pdflatex, $xelatex );
std_tex_cmds();
# Possible code to execute by *latex before inputting source file.
# Not used by default.
our $pre_tex_code = '';
## Default switches:
our $hilatex_default_switches = '';
our $latex_default_switches = '';
our $pdflatex_default_switches = '';
our $dvilualatex_default_switches = '';
our $lualatex_default_switches = '';
# Note that xelatex is used to give xdv file, not pdf file, hence
# we need the -no-pdf option.
our $xelatex_default_switches = '-no-pdf';
## Switch(es) to make them silent:
our $hilatex_silent_switch = '-interaction=batchmode';
our $latex_silent_switch = '-interaction=batchmode';
our $pdflatex_silent_switch = '-interaction=batchmode';
our $dvilualatex_silent_switch = '-interaction=batchmode';
our $lualatex_silent_switch = '-interaction=batchmode';
our $xelatex_silent_switch = '-interaction=batchmode';
# Whether to emulate -aux-directory, so we can use it on system(s) (TeXLive)
# that don't support it:
our $emulate_aux = 1;
# Whether emulate_aux had to be switched on during a run:
our $emulate_aux_switched = 0;
#--------------------
# Specification of extensions/files that need special treatment,
# e.g., in cleanup or in analyzing missing dependent files.
#
# %input_extensions maps primary_rule_name to pointer to hash of file extensions
# used for extensionless files specified in the source file by constructs
# like \input{file} \includegraphics{file}
our %input_extensions = ();
set_input_ext( 'latex', 'tex', 'eps' );
set_input_ext( 'pdflatex', 'tex', 'jpg', 'pdf', 'png' );
$input_extensions{lualatex} = $input_extensions{pdflatex};
$input_extensions{xelatex} = $input_extensions{pdflatex};
# Save these values as standards to be used when switching output,
# i.e., when actual primary rule differs from standard.
our %standard_input_extensions = %input_extensions;
# Possible extensions for main output file of *latex:
our %allowed_output_ext = ( ".dvi" => 1, ".xdv" => 1, ".pdf" => 1 );
# Extensions etc, of special use by latexmk
our $save_error_suffix = '-SAVE-ERROR'; # Suffix to be added to filename, when an
# erroneous file is saved insted of being deleted.
our $fdb_ext = 'fdb_latexmk'; # Extension for the file for latexmk's
# file-database
# Make it long to avoid possible collisions.
our $fdb_ver = 4; # Version number for kind of fdb_file.
# Variables relevant to specifying cleanup.
# The first set of variables is intended to be user configurable.
#
# The @generated_exts array contains list of extensions (without
# period) for files that are generated by rules run by latexmk.
#
# Instead of an extension, an item in the array can be a string containing
# the placeholder %R for the root of the filenames. This is used for more
# general patterns. Such a pattern may contain wildcards (bsd_glob
# definitions).
#
# By default, it excludes "final output files" that
# are normally only deleted on a full cleanup, not a small cleanup.
# These files get two kinds of special treatment:
# 1. In clean up, where depending on the kind of clean up, some
# or all of these generated files are deleted.
# (Note that special treatment is given to aux files.)
# 2. In analyzing the results of a run of *LaTeX, to
# determine if another run is needed. With an error free run,
# a rerun should be provoked by a change in any source file,
# whether a user file or a generated file. But with a run
# that ends in an error, only a change in a user file during
# the run (which might correct the error) should provoke a
# rerun, but a change in a generated file should not.
# Also at the start of a round of processing, only user-file
# changes are relevant.
# Special cases for extensions aux and bbl
# aux files beyond the standard one are found by a special analysis
# bbl files get special treatment because their deletion is conditional
# and because of the possibility of extra bibtex/biber rules with
# non-standard basename.
our @generated_exts = ( 'aux', 'bcf', 'bcf'.$save_error_suffix, 'fls',
'idx', 'ind', 'lof', 'lot',
'out', 'run.xml', 'toc',
'blg', 'ilg', 'log',
'xdv'
);
# N.B. 'out' is generated by hyperref package
our $clean_ext = ""; # For backward compatibility: Space separated
# extensions to be added to @generated_exts after
# startup (and rc file reading).
# Extensions of files to be deleted by -C, but aren't normally included
# in the small clean up by -c. Analogous to @generated_exts and $clean_ext,
# except that pattern rules (with %R) aren't applied.
our @final_output_exts = ( 'dvi', 'dviF', 'hnt', 'ps', 'psF', 'pdf',
'synctex', 'synctex.gz' );
our $clean_full_ext = "";
# Set of extra specific files to be deleted in small cleanup. These are
# ones that get generated under some kinds of error conditions. All cases:
# Relative to current directory, and relative to aux and out directories.
our @std_small_cleanup_files = ( 'texput.log', "texput.aux", "missfont.log" );
#-------------------------
# Information about options to latex and pdflatex that latexmk will simply
# pass through to *latex
# Option without arg. maps to itself.
# Option with arg. maps the option part to the full specification
# e.g., -kpathsea-debug => -kpathsea-debug=NUMBER
our %allowed_latex_options = ();
our %allowed_latex_options_with_arg = ();
foreach (
#####
# TeXLive options
"-draftmode switch on draft mode (generates no output PDF)",
"-enc enable encTeX extensions such as \\mubyte",
"-etex enable e-TeX extensions",
"-file-line-error enable file:line:error style messages",
"-no-file-line-error disable file:line:error style messages",
"-fmt=FMTNAME use FMTNAME instead of program name or a %& line",
"-halt-on-error stop processing at the first error",
"-interaction=STRING set interaction mode (STRING=batchmode/nonstopmode/\n".
" scrollmode/errorstopmode)",
"-ipc send DVI output to a socket as well as the usual\n".
" output file",
"-ipc-start as -ipc, and also start the server at the other end",
"-kpathsea-debug=NUMBER set path searching debugging flags according to\n".
" the bits of NUMBER",
"-mktex=FMT enable mktexFMT generation (FMT=tex/tfm/pk)",
"-no-mktex=FMT disable mktexFMT generation (FMT=tex/tfm/pk)",
"-mltex enable MLTeX extensions such as \charsubdef",
"-output-comment=STRING use STRING for DVI file comment instead of date\n".
" (no effect for PDF)",
"-parse-first-line enable parsing of first line of input file",
"-no-parse-first-line disable parsing of first line of input file",
"-progname=STRING set program (and fmt) name to STRING",
"-shell-escape enable \\write18{SHELL COMMAND}",
"-no-shell-escape disable \\write18{SHELL COMMAND}",
"-shell-restricted enable restricted \\write18",
"-src-specials insert source specials into the DVI file",
"-src-specials=WHERE insert source specials in certain places of\n".
" the DVI file. WHERE is a comma-separated value\n".
" list: cr display hbox math par parend vbox",
"-synctex=NUMBER generate SyncTeX data for previewers if nonzero",
"-translate-file=TCXNAME use the TCX file TCXNAME",
"-8bit make all characters printable by default",
#####
# MikTeX options not in TeXLive
"-alias=app pretend to be app",
"-buf-size=n maximum number of characters simultaneously present\n".
" in current lines",
"-c-style-errors C-style error messages",
"-disable-installer disable automatic installation of missing packages",
"-disable-pipes disable input (output) from (to) child processes",
"-disable-write18 disable the \\write18{command} construct",
"-dont-parse-first-line disable checking whether the first line of the main\n".
" input file starts with %&",
"-enable-enctex enable encTeX extensions such as \\mubyte",
"-enable-installer enable automatic installation of missing packages",
"-enable-mltex enable MLTeX extensions such as \charsubdef",
"-enable-pipes enable input (output) from (to) child processes",
"-enable-write18 fully enable the \\write18{command} construct",
"-error-line=n set the width of context lines on terminal error\n".
" messages",
"-extra-mem-bot=n set the extra size (in memory words) for large data\n".
" structures",
"-extra-mem-top=n set the extra size (in memory words) for chars,\n".
" tokens, et al",
"-font-max=n set the maximum internal font number",
"-font-mem-size=n set the size, in TeX memory words, of the font memory",
"-half-error-line=n set the width of first lines of contexts in terminal\n".
" error messages",
"-hash-extra=n set the extra space for the hash table of control\n".
" sequences",
"-job-time=file set the time-stamp of all output files equal to\n".
" file's time-stamp",
"-main-memory=n change the total size (in memory words) of the main\n".
" memory array",
"-max-in-open=n set the maximum number of input files and error\n".
" insertions that can be going on simultaneously",
"-max-print-line=n set the width of longest text lines output",
"-max-strings=n set the maximum number of strings",
"-nest-size=n set the maximum number of semantic levels\n".
" simultaneously active",
"-no-c-style-errors standard error messages",
"-param-size=n set the the maximum number of simultaneous macro\n".
" parameters",
"-pool-size=n set the maximum number of characters in strings",
"-record-package-usages=file record all package usages and write them into\n".
" file",
"-restrict-write18 partially enable the \\write18{command} construct",
"-save-size=n set the the amount of space for saving values\n".
" outside of current group",
"-stack-size=n set the maximum number of simultaneous input sources",
"-string-vacancies=n set the minimum number of characters that should be\n".
" available for the user's control sequences and font\n".
" names",
"-tcx=name process the TCX table name",
"-time-statistics show processing time statistics",
"-trace enable trace messages",
"-trace=tracestreams enable trace messages. The tracestreams argument is\n".
" a comma-separated list of trace stream names",
"-trie-size=n set the amount of space for hyphenation patterns",
"-undump=name use name as the name of the format to be used,\n".
" instead of the name by which the program was\n".
" called or a %& line.",
#####
# Options passed to *latex that have special processing by latexmk,
# so they are commented out here.
#-jobname=STRING set the job name to STRING
#-aux-directory=dir Set the directory dir to which auxiliary files are written
#-output-directory=DIR use existing DIR as the directory to write files in
# "-output-format=FORMAT use FORMAT for job output; FORMAT is `dvi\" or `pdf\"",
#-quiet
#-recorder enable filename recorder
#
# Options with different processing by latexmk than *latex
#-help
#-version
#
# Options NOT used by latexmk
#-includedirectory=dir prefix dir to the search path
#-initialize become the INI variant of the compiler
#-ini be pdfinitex, for dumping formats; this is implicitly
# true if the program name is `pdfinitex'
) {
if ( /^([^\s=]+)=/ ) {
$allowed_latex_options_with_arg{$1} = $_;
}
elsif ( /^([^\s=]+)\s/ ) {
$allowed_latex_options{$1} = $_;
}
}
# Arrays of options that will be added to latex and pdflatex.
# These need to be stored until after the command line parsing is finished,
# in case the values of $latex and/or $pdflatex change after an option
# is added.
our @extra_dvilualatex_options = ();
our @extra_hilatex_options = ();
our @extra_latex_options = ();
our @extra_pdflatex_options = ();
our @extra_lualatex_options = ();
our @extra_xelatex_options = ();
## Command to invoke biber & bibtex
our $biber = 'biber %O %S';
our $bibtex = 'bibtex %O %S';
# Switch(es) to make biber & bibtex silent:
our $biber_silent_switch = '--onlylog';
our $bibtex_silent_switch = '-terse';
our $bibtex_use = 1; # Whether to actually run bibtex to update bbl files.
# This variable is also used in deciding whether to
# delete bbl files in clean up operations.
# 0: Never run bibtex.
# Do NOT delete bbl files on clean up.
# 1: Run bibtex only if the bibfiles exists
# according to kpsewhich, and the bbl files
# appear to be out-of-date.
# Do NOT delete bbl files on clean up.
# 1.5: Run bibtex only if the bibfiles exists
# according to kpsewhich, and the bbl files
# appear to be out-of-date.
# Only delete bbl files on clean up if bibfiles exist.
# 2: Run bibtex when the bbl files are out-of-date
# Delete bbl files on clean up.
#
# In any event bibtex is only run if the log file
# indicates that the document uses bbl files.
our $bibtex_fudge = 1; # Whether or not to cd to aux dir when running bibtex.
# If the cd is not done, and bibtex is passed a
# filename with a path component, then it can easily
# happen that (a) bibtex refuses to write bbl and blg
# files to the aux directory, for security reasons,
# and/or (b) bibtex in pre-2019 versions fails to find
# some input file(s). But in some other cases, the cd
# method fails.
## Command to invoke makeindex
our $makeindex = 'makeindex %O -o %D %S';
# Switch(es) to make makeinex silent:
our $makeindex_silent_switch = '-q';
our $makeindex_fudge = 1; # Whether or not to cd to aux dir when running makeindex.
# Set to 1 to avoid security-related prohibition on
# makeindex writing to aux_dir when it is not specified
# as a subdirectory of cwd.
## Command to convert dvi file to pdf file directly.
# Use option -dALLOWPSTRANSPARENCY so that it works with documents
# using pstricks etc:
our $dvipdf = 'dvipdf -dALLOWPSTRANSPARENCY %O %S %D';
# N.B. Standard dvipdf runs dvips and gs with their silent switch, so for
# standard dvipdf $dvipdf_silent_switch is unneeded, but innocuous.
# But dvipdfmx can be used instead, and it has a silent switch (-q).
# So implementing $dvipdf_silent_switch is useful.
our $dvipdf_silent_switch = '-q';
## Command to convert dvi file to ps file:
our $dvips = 'dvips %O -o %D %S';
## Command to convert dvi file to ps file in landscape format:
our $dvips_landscape = 'dvips -tlandscape %O -o %D %S';
# Switch(es) to get dvips to make ps file suitable for conversion to good pdf:
# (If this is not used, ps file and hence pdf file contains bitmap fonts
# (type 3), which look horrible under acroread. An appropriate switch
# ensures type 1 fonts are generated. You can put this switch in the
# dvips command if you prefer.)
our $dvips_pdf_switch = '-P pdf';
# Switch(es) to make dvips silent:
our $dvips_silent_switch = '-q';
## Command to convert ps file to pdf file.
# Use option -dALLOWPSTRANSPARENCY so that it works with documents
# using pstricks etc:
our $ps2pdf = 'ps2pdf -dALLOWPSTRANSPARENCY %O %S %D';
## Command to convert xdv file to pdf file
our $xdvipdfmx = 'xdvipdfmx -E -o %D %O %S';
our $xdvipdfmx_silent_switch = '-q';
## Command to search for tex-related files
our $kpsewhich = 'kpsewhich %S';
## Command to run make:
our $make = 'make';
##Printing:
our $print_type = 'auto'; # When printing, print the postscript file.
# Possible values: 'dvi', 'ps', 'pdf', 'auto', 'none'
# 'auto' ==> set print type according to the printable
# file(s) being made: priority 'ps', 'pdf', 'dvi'
# Viewers. These are system dependent, so default to none:
our ( $pdf_previewer, $ps_previewer, $ps_previewer_landscape, $dvi_previewer,
$dvi_previewer_landscape, $hnt_previewer );
$pdf_previewer = $ps_previewer = $ps_previewer_landscape = $dvi_previewer = $dvi_previewer_landscape = $hnt_previewer = "NONE";
# The following variables are assigned once and then used in symbolic
# references, so we need to avoid warnings 'name used only once':
our ( $aux_dir_requested, $out_dir_requested );
our $dvi_update_signal = undef;
our $ps_update_signal = undef;
our $pdf_update_signal = undef;
our $dvi_update_command = undef;
our $ps_update_command = undef;
our $pdf_update_command = undef;
# Viewer update methods:
# 0 => auto update: viewer watches file (e.g., gv)
# 1 => manual update: user must do something: e.g., click on window.
# (e.g., ghostview, MSWIN previewers, acroread under UNIX)
# 2 => send signal. Number of signal in $dvi_update_signal,
# $ps_update_signal, $pdf_update_signal
# 3 => viewer can't update, because it locks the file and the file
# cannot be updated. (acroread under MSWIN)
# 4 => run a command to force the update. The commands are
# specified by the variables $dvi_update_command,
# $ps_update_command, $pdf_update_command
our $dvi_update_method = 1;
our $hnt_update_method = 1;
our $ps_update_method = 1;
our $pdf_update_method = 1;
our $allow_subdir_creation = 1;
our $new_viewer_always = 0; # If 1, always open a new viewer in pvc mode.
# If 0, only open a new viewer if no previous
# viewer for the same file is detected.
# Commands for use in pvc mode for compiling, success, warnings, and failure;
# they default to empty, i.e., not to use:
our ($compiling_cmd, $success_cmd, $warning_cmd, $failure_cmd) =
( '', '', '', '' );
# Commands for printing are highly system dependent, so default to NONE:
our $lpr = 'NONE $lpr variable is not configured to allow printing of ps files';
our $lpr_dvi = 'NONE $lpr_dvi variable is not configured to allow printing of dvi files';
our $lpr_pdf = 'NONE $lpr_pdf variable is not configured to allow printing of pdf files';
# The $pscmd below holds a **system-dependent** command to list running
# processes. It is used to find the process ID of the viewer looking at
# the current output file. The output of the command must include the
# process number and the command line of the processes, since the
# relevant process is identified by the name of file to be viewed.
# Its use is not essential.
our $pscmd = 'NONE $pscmd variable is not configured to detect running processes';
our $pid_position = -1; # offset of PID in output of pscmd.
# Negative means I cannot use ps
our $quote_filenames = 1; # Quote filenames in external commands
our $del_dir = ''; # Directory into which cleaned up files are to be put.
# If $del_dir is '', just delete the files in a clean up.
our @rc_system_files = ();
#########################################################################
################################################################
## Special variables for system-dependent fudges, etc.
# ???????? !!!!!!!!!!
our $log_file_binary = 0; # Whether to treat log file as binary
# Normally not, since the log file SHOULD be pure text.
# But Miktex 2.7 sometimes puts binary characters
# in it. (Typically in construct \OML ... after
# overfull box with mathmode.)
# Sometimes there is ctrl/Z, which is not only non-text,
# but is end-of-file marker for MS-Win in text mode.
our $MSWin_fudge_break = 1; # Give special treatment to ctrl/C and ctrl/break
# in -pvc mode under MSWin
# Under MSWin32 (at least with perl 5.8 and WinXP)
# when latexmk is running another program, and the
# user gives ctrl/C or ctrl/break, to stop the
# daughter program, not only does it reach
# the daughter, but also latexmk/perl, so
# latexmk is stopped also. In -pvc mode,
# this is not normally desired. So when the
# $MSWin_fudge_break variable is set,
# latexmk arranges to ignore ctrl/C and
# ctrl/break during processing of files;
# only the daughter programs receive them.
# This fudge is not applied in other
# situations, since then having latexmk also
# stopping because of the ctrl/C or
# ctrl/break signal is desirable.
# The fudge is not needed under UNIX (at least
# with Perl 5.005 on Solaris 8). Only the
# daughter programs receive the signal. In
# fact the inverse would be useful: In
# normal processing, as opposed to -pvc, if
# force mode (-f) is set, a ctrl/C is
# received by a daughter program does not
# also stop latexmk. Under tcsh, we get
# back to a command prompt, while latexmk
# keeps running in the background!
## Substitute backslashes in file and directory names for
## MSWin command line
our $MSWin_back_slash = 0;
## Separator of elements in search_path. Default is unix value
our $search_path_separator = ':';
# Directory for temporary files. Default to current directory.
our $tmpdir = ".";
# Latexmk does tests on whether a particular generated file, e.g., log or
# fls, has been generated on a current run of a rule, especially *latex, or
# is leftover from previous runs. An expected file can fail to be
# generated or generated in other than the expected place because of errors
# or because of misconfiguration of latexmk. There are also files (notably
# bcf files) that are generated or not according to the current set of
# packages, options, etc used by a document.
#
# The test for whether a file was generated on the current run of a rule is
# that the modification time of the file is at least as recent as the
# system time at the start of the run. A file with a modification time
# significantly less than the time at the start of the run is presumably
# left over from a previous run and not generated in the currrent run. (An
# allowance is made in this comparison for the effects of granularity of
# file-system times. Such granularity can make a file time a second or two
# earlier than the system time at which the file was last modified.)
#
# But generated files may be on a file system hosted by a server computer
# that is different than the computer running latexmk. There may be an
# offset between the time on the two computers; this can make it
# incorrectly appear that the generated files were made before the
# run. Most of the time, this problem does not arise, since (a) typical
# usage of latexmk is with a local file system, and (b) current-day
# computers and operating systems have their time synchronized accurately
# with a time server. Difficulties are most acute with small documents
# compiled on a fast computer, e.g., with sub-second compilation times.
#
# When latexmk sees symptoms of an excessive offset, it measures the offset
# between the filesystem time and the system time. This involves writing a
# temporary file, getting its modification time, and deleting it. Then
# when testing for whether a file was made on the current run or not, an
# allowance is then made for the measured time offset between the two
# computers.
#
# Note that typically an invocation of latexmk's processing of a document
# occurs after some human action, e.g., editting a document or a
# configuration file. So a file that is left over from a previous run and
# not overwritten on the current run will have a file time at least many
# seconds less than the current time, corresponding to the time scale for a
# human run-edit-run cycle. So one does NOT have to particularly precise
# about time differences.
#
# Granularity of file system etc:
# FAT file system: 2 sec granularity. Others 1 sec or often much less.
#
# Functions available to latexmk from Perl:
# mtime from Perl's CORE::stat: 1 sec, but 2 sec on FAT file system;
# mtime from Time_HiRes::stat: can be much less than 1 sec, if the
# combination of Perl, the OS and the file system support it.
# system time from CORE::time(): 1 sec;
# system time from Time::HiRes::time(): Much less than 1 sec.
# Variables controlling the assessment of time offset between file system
# and computer:
our $filetime_causality_threshold = 5;
# This is the size of time differences below which latexmk doesn't
# worry. It allows for (a) different granularity between system time
# and filesystem time, (b) for a modest mismatch between file and system
# time. This allowance can be generous; it merely needs to be below the
# human time-scale for editing documents, reconfiguring (or
# misconfiguring) latexmk, etc.
our $filetime_offset_measured = 0; # Measurement not yet done.
our $filetime_offset = 0; # Filetime relative to system time.
# Assume zero to start (corresponding to
# local file system).
# Will be updated if necessary.
our $filetime_offset_report_threshold = 10; # Threshold beyond which filetime offsets
# are reported at end of run; large
# offsets indicate incorrect system
# time on at least one system.
################################################################
################################################################
# System-dependent overrides:
# Currently, the cases I have tests for are: MSWin32, cygwin, linux and
# darwin, msys, with the main complications being for MSWin32 and cygwin.
# Further special treatment may also be useful for MSYS (for which $^O reports
# "msys"). This is another *nix-emulation/system for MSWindows. At
# present it is treated as unix-like, but the environment variables
# are those of Windows. (The test for USERNAME as well as USER was
# to make latexmk work under MSYS's perl.)
#
our $start_NT = 'NONE';
if ( $^O eq "MSWin32" ) {
# Pure MSWindows configuration
## Configuration parameters:
## Use first existing case for $tmpdir:
$tmpdir = $ENV{TMPDIR} || $ENV{TEMP} || '.';
$log_file_binary = 1; # Protect against ctrl/Z in log file from
# Miktex 2.7.
## List of possibilities for the system-wide initialization file.
## The first one found (if any) is used.
@rc_system_files = ( "C:/latexmk/LatexMk", "C:/latexmk/latexmkrc" );
$search_path_separator = ';'; # Separator of elements in search_path
# For a pdf-file, "start x.pdf" starts the pdf viewer associated with
# pdf files, so no program name is needed:
$pdf_previewer = 'start %O %S';
$ps_previewer = 'start %O %S';
$ps_previewer_landscape = $ps_previewer;
$dvi_previewer = 'start %O %S';
$dvi_previewer_landscape = "$dvi_previewer";
$hnt_previewer = 'start %O %S';
$pdf_update_method = 3; # acroread locks the pdf file
}
elsif ( $^O eq "cygwin" ) {
# The problem is a mixed MSWin32 and UNIX environment.
# Perl decides the OS is cygwin in two situations:
# 1. When latexmk is run from a cygwin shell under a cygwin
# environment. Perl behaves in a UNIX way. This is OK, since
# the user is presumably expecting UNIXy behavior.
# 2. When CYGWIN exectuables are in the path, but latexmk is run
# from a native NT shell. Presumably the user is expecting NT
# behavior. But perl behaves more UNIXy. This causes some
# clashes.
# The issues to handle are:
# 1. Perl sees both MSWin32 and cygwin filenames. This is
# normally only an advantage.
# 2. Perl uses a UNIX shell in the system command
# This is a nasty problem: under native NT, there is a
# start command that knows about NT file associations, so that
# we can do, e.g., (under native NT) system("start file.pdf");
# But this won't work when perl has decided the OS is cygwin,
# even if it is invoked from a native NT command line. An
# NT command processor must be used to deal with this.
# 3. External executables can be native NT (which only know
# NT-style file names) or cygwin executables (which normally
# know both cygwin UNIX-style file names and NT file names,
# but not always; some do not know about drive names, for
# example).
# Cygwin executables for tex and latex may only know cygwin
# filenames.
# 4. The BIBINPUTS environment variables may be