Debian Codegraph @

texmf-dist/doc/latex/ktbox/data/LatexMk

raw
1 # Settings
2 $xdvipdfmx = "xdvipdfmx -z 6 -i dvipdfmx-unsafe.cfg -o %D %O %S";
3
4 ###############################
5 # Post processing of pdf file #
6 ###############################
7
8 $compiling_cmd = "internal overleaf_pre_process %T %D";
9 $success_cmd = "internal overleaf_post_process %T %D";
10 $failure_cmd = $success_cmd;
11
12 # equivalent to -gt option. Used to prevent latexmk from skipping recompilation
13 # of output.log and output.pdf
14 $go_mode = 3;
15
16 # equivalent to -bibtex option. Run bibtex unconditionally when bbl files are
17 # out of date.
18 $bibtex_use = 2;
19
20 my $ORIG_PDF_AGE;
21
22 sub overleaf_pre_process {
23 my $source_file = $_[0];
24 my $output_file = $_[1];
25
26 # get age of existing pdf if present
27 $ORIG_PDF_AGE = -M $output_file
28 }
29
30 sub overleaf_post_process {
31 my $source_file = $_[0];
32 my $output_file = $_[1];
33 my $source_without_ext = $source_file =~ s/\.tex$//r;
34 my $output_without_ext = $output_file =~ s/\.pdf$//r;
35
36 # Look for a knitr concordance file
37 my $concordance_file = "${source_without_ext}-concordance.tex";
38 if (-e $concordance_file) {
39 print "Patching synctex file for knitr...\n";
40 system("patchSynctex.R", $source_without_ext, $output_without_ext);
41 }
42
43 # Return early if pdf file doesn't exist or wasn't updated
44 my $NEW_PDF_AGE = -M $output_file;
45 return if !defined($NEW_PDF_AGE);
46 return if defined($ORIG_PDF_AGE) && $NEW_PDF_AGE == $ORIG_PDF_AGE;
47
48 # Figure out where qpdf is
49 $qpdf //= "/usr/bin/qpdf";
50 $qpdf = $ENV{QPDF} if defined($ENV{QPDF}) && -x $ENV{QPDF};
51 return if ! -x $qpdf;
52 $qpdf_opts //= "--linearize --newline-before-endstream";
53 $qpdf_opts = $ENV{QPDF_OPTS} if defined($ENV{QPDF_OPTS});
54
55 # Run qpdf
56 my $optimised_file = "${output_file}.opt";
57 system($qpdf, split(' ', $qpdf_opts), $output_file, $optimised_file);
58 $qpdf_exit_code = ($? >> 8);
59 print "qpdf exit code=$qpdf_exit_code\n";
60
61 # Replace the output file if qpdf was successful
62 # qpdf returns 0 for success, 3 for warnings (output pdf still created)
63 return if !($qpdf_exit_code == 0 || $qpdf_exit_code == 3);
64 print "Renaming optimised file to $output_file\n";
65 rename($optimised_file, $output_file);
66
67 print "Extracting xref table for $output_file\n";
68 my $xref_file = "${output_file}xref";
69 system("$qpdf --show-xref ${output_file} > ${xref_file}");
70 $qpdf_xref_exit_code = ($? >> 8);
71 print "qpdf --show-xref exit code=$qpdf_xref_exit_code\n";
72 }
73
74 ##############
75 # Glossaries #
76 ##############
77 add_cus_dep( 'glo', 'gls', 0, 'glo2gls' );
78 add_cus_dep( 'acn', 'acr', 0, 'glo2gls'); # from Overleaf v1
79 sub glo2gls {
80 system("makeglossaries $_[0]");
81 }
82
83 #############
84 # makeindex #
85 #############
86 @ist = glob("*.ist");
87 if (scalar(@ist) > 0) {
88 $makeindex = "makeindex -s $ist[0] %O -o %D %S";
89 }
90
91 ################
92 # nomenclature #
93 ################
94 add_cus_dep("nlo", "nls", 0, "nlo2nls");
95 sub nlo2nls {
96 system("makeindex $_[0].nlo -s nomencl.ist -o $_[0].nls -t $_[0].nlg");
97 }
98
99 #########
100 # Knitr #
101 #########
102 add_cus_dep( 'Rtex', 'tex', 0, 'do_knitr');
103 add_cus_dep( 'Rnw', 'tex', 0, 'do_knitr');
104 sub do_knitr {
105 Run_subst(qq{Rscript -e '
106 library("knitr");
107 opts_knit\$set(concordance=T);
108 knitr::knit(%S, output=%D);
109 '}
110 );
111 }
112
113 ##########
114 # feynmf #
115 ##########
116 push(@file_not_found, '^feynmf: Files .* and (.*) not found:$');
117 add_cus_dep("mf", "tfm", 0, "mf_to_tfm");
118 sub mf_to_tfm { system("mf '\\mode:=laserjet; input $_[0]'"); }
119
120 push(@file_not_found, '^feynmf: Label file (.*) not found:$');
121 add_cus_dep("mf", "t1", 0, "mf_to_label1");
122 sub mf_to_label1 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t1"); }
123 add_cus_dep("mf", "t2", 0, "mf_to_label2");
124 sub mf_to_label2 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t2"); }
125 add_cus_dep("mf", "t3", 0, "mf_to_label3");
126 sub mf_to_label3 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t3"); }
127 add_cus_dep("mf", "t4", 0, "mf_to_label4");
128 sub mf_to_label4 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t4"); }
129 add_cus_dep("mf", "t5", 0, "mf_to_label5");
130 sub mf_to_label5 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t5"); }
131 add_cus_dep("mf", "t6", 0, "mf_to_label6");
132 sub mf_to_label6 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t6"); }
133 add_cus_dep("mf", "t7", 0, "mf_to_label7");
134 sub mf_to_label7 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t7"); }
135 add_cus_dep("mf", "t8", 0, "mf_to_label8");
136 sub mf_to_label8 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t8"); }
137 add_cus_dep("mf", "t9", 0, "mf_to_label9");
138 sub mf_to_label9 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t9"); }
139
140 ##########
141 # feynmp #
142 ##########
143 push(@file_not_found, '^dvipdf: Could not find figure file (.*); continuing.$');
144 add_cus_dep("mp", "1", 0, "mp_to_eps");
145 sub mp_to_eps {
146 system("mpost $_[0]");
147 return 0;
148 }
149
150 #############
151 # asymptote #
152 #############
153
154 sub asy {return system("asy \"$_[0]\"");}
155 add_cus_dep("asy","eps",0,"asy");
156 add_cus_dep("asy","pdf",0,"asy");
157 add_cus_dep("asy","tex",0,"asy");
158
159 #############
160 # metapost # # from Overleaf v1
161 #############
162 add_cus_dep('mp', '1', 0, 'mpost');
163 sub mpost {
164 my $file = $_[0];
165 my ($name, $path) = fileparse($file);
166 pushd($path);
167 my $return = system "mpost $name";
168 popd();
169 return $return;
170 }
171
172 ##########
173 # chktex #
174 ##########
175 unlink 'output.chktex' if -f 'output.chktex';
176 if (defined $ENV{'CHKTEX_OPTIONS'}) {
177 use File::Basename;
178 use Cwd;
179
180 # identify the main file
181 my $target = $ARGV[-1];
182 my $file = basename($target);
183
184 if ($file =~ /\.tex$/) {
185 # change directory for a limited scope
186 my $orig_dir = cwd();
187 my $subdir = dirname($target);
188 chdir($subdir);
189 # run chktex on main file
190 $status = system("/usr/local/bin/run-chktex.sh", $orig_dir, $file);
191 # go back to original directory
192 chdir($orig_dir);
193
194 # in VALIDATE mode we always exit after running chktex
195 # otherwise we exit if EXIT_ON_ERROR is set
196
197 if ($ENV{'CHKTEX_EXIT_ON_ERROR'} || $ENV{'CHKTEX_VALIDATE'}) {
198 # chktex doesn't let us access the error info via exit status
199 # so look through the output
200 open(my $fh, "<", "output.chktex");
201 my $errors = 0;
202 {
203 local $/ = "\n";
204 while(<$fh>) {
205 if (/^\S+:\d+:\d+: Error:/) {
206 $errors++;
207 print;
208 }
209 }
210 }
211 close($fh);
212 exit(1) if $errors > 0;
213 exit(0) if $ENV{'CHKTEX_VALIDATE'};
214 }
215 }
216 }