latexmkrc (5596B)
1 # Settings 2 $xdvipdfmx = "xdvipdfmx -z 6 -o %D %O %S"; 3 4 ############################### 5 # Post processing of pdf file # 6 ############################### 7 8 # assume the jobname is 'output' for sharelatex 9 my $ORIG_PDF_AGE = -M "output.pdf"; # get age of existing pdf if present 10 11 END { 12 my $NEW_PDF_AGE = -M "output.pdf"; 13 return if !defined($NEW_PDF_AGE); # bail out if no pdf file 14 return if defined($ORIG_PDF_AGE) && $NEW_PDF_AGE == $ORIG_PDF_AGE; # bail out if pdf was not updated 15 $qpdf //= "/usr/local/bin/qpdf"; 16 $qpdf = $ENV{QPDF} if defined($ENV{QPDF}) && -x $ENV{QPDF}; 17 return if ! -x $qpdf; # check that qpdf exists 18 $qpdf_opts //= "--linearize --newline-before-endstream"; 19 $qpdf_opts = $ENV{QPDF_OPTS} if defined($ENV{QPDF_OPTS}); 20 my $status = system($qpdf, split(' ', $qpdf_opts), "output.pdf", "output.pdf.opt"); 21 my $exitcode = ($status >> 8); 22 print "qpdf exit code=$exitcode\n"; 23 # qpdf returns 0 for success, 3 for warnings (output pdf still created) 24 return if !($exitcode == 0 || $exitcode == 3); 25 print "Renaming optimised file to output.pdf\n"; 26 rename("output.pdf.opt", "output.pdf"); 27 } 28 29 ############## 30 # Glossaries # 31 ############## 32 add_cus_dep( 'glo', 'gls', 0, 'glo2gls' ); 33 add_cus_dep( 'acn', 'acr', 0, 'glo2gls'); # from Overleaf v1 34 sub glo2gls { 35 system("makeglossaries $_[0]"); 36 } 37 38 ############# 39 # makeindex # 40 ############# 41 @ist = glob("*.ist"); 42 if (scalar(@ist) > 0) { 43 $makeindex = "makeindex -s $ist[0] %O -o %D %S"; 44 } 45 46 ################ 47 # nomenclature # 48 ################ 49 add_cus_dep("nlo", "nls", 0, "nlo2nls"); 50 sub nlo2nls { 51 system("makeindex $_[0].nlo -s nomencl.ist -o $_[0].nls -t $_[0].nlg"); 52 } 53 54 ######### 55 # Knitr # 56 ######### 57 my $root_file = $ARGV[-1]; 58 59 add_cus_dep( 'Rtex', 'tex', 0, 'rtex_to_tex'); 60 sub rtex_to_tex { 61 do_knitr("$_[0].Rtex"); 62 } 63 64 sub do_knitr { 65 my $dirname = dirname $_[0]; 66 my $basename = basename $_[0]; 67 system("Rscript -e \"library('knitr'); setwd('$dirname'); knit('$basename')\""); 68 } 69 70 my $rtex_file = $root_file =~ s/\.tex$/.Rtex/r; 71 unless (-e $root_file) { 72 if (-e $rtex_file) { 73 do_knitr($rtex_file); 74 } 75 } 76 77 ########## 78 # feynmf # 79 ########## 80 push(@file_not_found, '^feynmf: Files .* and (.*) not found:$'); 81 add_cus_dep("mf", "tfm", 0, "mf_to_tfm"); 82 sub mf_to_tfm { system("mf '\\mode:=laserjet; input $_[0]'"); } 83 84 push(@file_not_found, '^feynmf: Label file (.*) not found:$'); 85 add_cus_dep("mf", "t1", 0, "mf_to_label1"); 86 sub mf_to_label1 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t1"); } 87 add_cus_dep("mf", "t2", 0, "mf_to_label2"); 88 sub mf_to_label2 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t2"); } 89 add_cus_dep("mf", "t3", 0, "mf_to_label3"); 90 sub mf_to_label3 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t3"); } 91 add_cus_dep("mf", "t4", 0, "mf_to_label4"); 92 sub mf_to_label4 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t4"); } 93 add_cus_dep("mf", "t5", 0, "mf_to_label5"); 94 sub mf_to_label5 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t5"); } 95 add_cus_dep("mf", "t6", 0, "mf_to_label6"); 96 sub mf_to_label6 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t6"); } 97 add_cus_dep("mf", "t7", 0, "mf_to_label7"); 98 sub mf_to_label7 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t7"); } 99 add_cus_dep("mf", "t8", 0, "mf_to_label8"); 100 sub mf_to_label8 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t8"); } 101 add_cus_dep("mf", "t9", 0, "mf_to_label9"); 102 sub mf_to_label9 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t9"); } 103 104 ########## 105 # feynmp # 106 ########## 107 push(@file_not_found, '^dvipdf: Could not find figure file (.*); continuing.$'); 108 add_cus_dep("mp", "1", 0, "mp_to_eps"); 109 sub mp_to_eps { 110 system("mpost $_[0]"); 111 return 0; 112 } 113 114 ############# 115 # asymptote # 116 ############# 117 sub asy {return system("asy --offscreen '$_[0]'");} 118 add_cus_dep("asy","eps",0,"asy"); 119 add_cus_dep("asy","pdf",0,"asy"); 120 add_cus_dep("asy","tex",0,"asy"); 121 122 ############# 123 # metapost # # from Overleaf v1 124 ############# 125 add_cus_dep('mp', '1', 0, 'mpost'); 126 sub mpost { 127 my $file = $_[0]; 128 my ($name, $path) = fileparse($file); 129 pushd($path); 130 my $return = system "mpost $name"; 131 popd(); 132 return $return; 133 } 134 135 ########## 136 # chktex # 137 ########## 138 unlink 'output.chktex' if -f 'output.chktex'; 139 if (defined $ENV{'CHKTEX_OPTIONS'}) { 140 use File::Basename; 141 use Cwd; 142 143 # identify the main file 144 my $target = $ARGV[-1]; 145 my $file = basename($target); 146 147 if ($file =~ /\.tex$/) { 148 # change directory for a limited scope 149 my $orig_dir = cwd(); 150 my $subdir = dirname($target); 151 chdir($subdir); 152 # run chktex on main file 153 $status = system("/usr/bin/run-chktex.sh", $orig_dir, $file); 154 # go back to original directory 155 chdir($orig_dir); 156 157 # in VALIDATE mode we always exit after running chktex 158 # otherwise we exit if EXIT_ON_ERROR is set 159 160 if ($ENV{'CHKTEX_EXIT_ON_ERROR'} || $ENV{'CHKTEX_VALIDATE'}) { 161 # chktex doesn't let us access the error info via exit status 162 # so look through the output 163 open(my $fh, "<", "output.chktex"); 164 my $errors = 0; 165 { 166 local $/ = "\n"; 167 while(<$fh>) { 168 if (/^\S+:\d+:\d+: Error:/) { 169 $errors++; 170 print; 171 } 172 } 173 } 174 close($fh); 175 exit(1) if $errors > 0; 176 exit(0) if $ENV{'CHKTEX_VALIDATE'}; 177 } 178 } 179 }