[1208] | 1 | #!/usr/local/bin/perl |
---|
| 2 | ## latexmk - version 2.0 |
---|
| 3 | ## |
---|
| 4 | ## Modified by Evan McLean (emm@rdt.monash.edu.au) |
---|
| 5 | ## Original script (RCS version 2.3) called "go" written by David J. Musliner |
---|
| 6 | ## |
---|
| 7 | ## - fully automated LaTeX document generation routine. |
---|
| 8 | ## - checks to see if .bib or .tex source files (or included other files) |
---|
| 9 | ## have been changed since last run (which made .aux). |
---|
| 10 | ## - see sub print_help for info. |
---|
| 11 | ## |
---|
| 12 | ## LatexMk is no longer supported by the author. With changes in work |
---|
| 13 | ## situation, the author no longer uses latex, and hence does not use |
---|
| 14 | ## LatexMk. Having no access to latex also makes it difficult to test fixes. |
---|
| 15 | ## |
---|
| 16 | ##----------------------------------------------------------------------- |
---|
| 17 | ## Here's the copyright notice that Mr. Musliner required to be |
---|
| 18 | ## kept here. |
---|
| 19 | ##----------------------------------------------------------------------- |
---|
| 20 | ##Copyright 1992 by David J. Musliner and The University of Michigan. |
---|
| 21 | ## |
---|
| 22 | ## All Rights Reserved |
---|
| 23 | ## |
---|
| 24 | ##Permission to use, copy, modify, and distribute this software and its |
---|
| 25 | ##documentation for any purpose and without fee is hereby granted, |
---|
| 26 | ##provided that the above copyright notice and this permission notice appear in |
---|
| 27 | ##all copies and modified versions. |
---|
| 28 | ## |
---|
| 29 | ##THE COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
---|
| 30 | ##INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT |
---|
| 31 | ##SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
---|
| 32 | ##CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
---|
| 33 | ##DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
---|
| 34 | ##TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
---|
| 35 | ##PERFORMANCE OF THIS SOFTWARE. |
---|
| 36 | ##----------------------------------------------------------------------- |
---|
| 37 | ##While I am not copyrighting my modifications (I don't even know if I |
---|
| 38 | ##can) I do include my own disclaimer: |
---|
| 39 | ## |
---|
| 40 | ##THE AUTHOR/MODIFIER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
---|
| 41 | ##INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT |
---|
| 42 | ##SHALL THE AUTHOR/MODIFIER(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
---|
| 43 | ##CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
---|
| 44 | ##DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
---|
| 45 | ##TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
---|
| 46 | ##PERFORMANCE OF THIS SOFTWARE. |
---|
| 47 | ##----------------------------------------------------------------------- |
---|
| 48 | $version_num = '2.0'; |
---|
| 49 | ##Modification History: |
---|
| 50 | ## 2.0 - Final release, no enhancements. LatexMk is no longer supported |
---|
| 51 | ## by the author. |
---|
| 52 | ## 1.9 - Fixed bug that was introduced in 1.8 with path name fix. |
---|
| 53 | ## - Fixed buglet in man page. |
---|
| 54 | ## 1.8 - Add not about announcement mailling list above. |
---|
| 55 | ## - Added texput.dvi and texput.aux to files deleted with -c and/or |
---|
| 56 | ## the -C options. |
---|
| 57 | ## - Added landscape mode (-l option and a bunch of RC variables). |
---|
| 58 | ## - Added sensing of "\epsfig{file=...}" forms in dependency generation. |
---|
| 59 | ## - Fixed path names when specified tex file is not in the current |
---|
| 60 | ## directory. |
---|
| 61 | ## - Fixed combined use of -pvc and -s options. |
---|
| 62 | ## - Fixed a bunch of speling errors in the source. :-) |
---|
| 63 | ## - Fixed bugs in xdvi patches in contrib directory. |
---|
| 64 | ## 1.7 - Fixed -pvc continuous viewing to reattach to pre-existing |
---|
| 65 | ## process correctly. |
---|
| 66 | ## - Added $pscmd to allow changing process grepping for different |
---|
| 67 | ## systems. |
---|
| 68 | ## 1.6 - Fixed buglet in help message |
---|
| 69 | ## - Fixed bugs in detection of input and include files. |
---|
| 70 | ## 1.5 - Removed test message I accidentally left in version 1.4 |
---|
| 71 | ## - Made dvips use -o option instead of stdout redirection as some |
---|
| 72 | ## people had problems with dvips not going to stdout by default. |
---|
| 73 | ## - Fixed bug in input and include file detection |
---|
| 74 | ## - Fixed dependency resolution process so it detects new .toc file |
---|
| 75 | ## and makeindex files properly. |
---|
| 76 | ## - Added dvi and postscript filtering options -dF and -pF. |
---|
| 77 | ## - Added -v version commmand. |
---|
| 78 | ## 1.4 - Fixed bug in -pvc option. |
---|
| 79 | ## - Made "-F" option include non-existant file in the dependency list. |
---|
| 80 | ## (RC variable: $force_include_mode) |
---|
| 81 | ## - Added .lot and .lof files to clean up list of extentions. |
---|
| 82 | ## - Added file "texput.log" to list of files to clean for -c. |
---|
| 83 | ## - LatexMk now handles file names in a similar fashion to latex. |
---|
| 84 | ## The ".tex" extention is no longer enforced. |
---|
| 85 | ## - Added $texfile_search RC variable to look for default files. |
---|
| 86 | ## - Fixed \input and \include so they add ".tex" extention if necessary. |
---|
| 87 | ## - Allow intermixing of file names and options. |
---|
| 88 | ## - Added "-d" and banner options (-bm, -bs, and -bi). |
---|
| 89 | ## (RC variables: $banner, $banner_message, $banner_scale, |
---|
| 90 | ## $banner_intensity, $tmpdir) |
---|
| 91 | ## - Fixed "-r" option to detect an command line syntax errors better. |
---|
| 92 | ## 1.3 - Added "-F" option, patch supplied by Patrick van der Smagt. |
---|
| 93 | ## 1.2 - Added "-C" option. |
---|
| 94 | ## - Added $clean_ext and $clean_full_ext variables for RC files. |
---|
| 95 | ## - Added custom dependency generation capabilities. |
---|
| 96 | ## - Added command line and variable to specify custom RC file. |
---|
| 97 | ## - Added reading of rc file in current directly. |
---|
| 98 | ## 1.1 - Fixed bug where Dependency file generation header is printed |
---|
| 99 | ## rependatively. |
---|
| 100 | ## - Fixed bug where TEXINPUTS path is searched for file that was |
---|
| 101 | ## specified with absolute an pathname. |
---|
| 102 | ## 1.0 - Ripped from script by David J. Musliner (RCS version 2.3) called "go" |
---|
| 103 | ## - Fixed a couple of file naming bugs |
---|
| 104 | ## e.g. when calling latex, left the ".tex" extention off the end |
---|
| 105 | ## of the file name which could do some interesting things |
---|
| 106 | ## with some file names. |
---|
| 107 | ## - Redirected output of dvips. My version of dvips was a filter. |
---|
| 108 | ## - Cleaned up the rc file mumbo jumbo and created a dependency file |
---|
| 109 | ## instead. Include dependencies are always searched for if a |
---|
| 110 | ## dependency file doesn't exist. The -i option regenerates the |
---|
| 111 | ## dependency file. |
---|
| 112 | ## Getting rid of the rc file stuff also gave the advantage of |
---|
| 113 | ## not being restricted to one tex file per directory. |
---|
| 114 | ## - Can specify multiple files on the command line or no files |
---|
| 115 | ## on the command line. |
---|
| 116 | ## - Removed lpr options stuff. I would guess that generally, |
---|
| 117 | ## you always use the same options in which case they can |
---|
| 118 | ## be set up from an rc file with the $lpr variable. |
---|
| 119 | ## - Removed the dviselect stuff. If I ever get time (or money :-) ) |
---|
| 120 | ## I might put it back in if I find myself needing it or people |
---|
| 121 | ## express interest in it. |
---|
| 122 | ## - Made it possible to view dvi or postscript file automatically |
---|
| 123 | ## depending on if -ps option selected. |
---|
| 124 | ## - Made specification of dvi file viewer seperate for -pv and -pvc |
---|
| 125 | ## options. |
---|
| 126 | ##----------------------------------------------------------------------- |
---|
| 127 | |
---|
| 128 | ## default document processing programs. |
---|
| 129 | $latex = 'latex'; |
---|
| 130 | $bibtex = 'bibtex'; |
---|
| 131 | $slitex = 'slitex'; |
---|
| 132 | $makeindex = 'makeindex'; |
---|
| 133 | $dvips = 'dvips'; |
---|
| 134 | $dvips_landscape = 'dvips -tlandscape'; |
---|
| 135 | $dviselect = 'dviselect'; |
---|
| 136 | $ps_previewer = 'gv'; |
---|
| 137 | $ps_previewer_landscape = 'gv -swap'; |
---|
| 138 | $dvi_previewer = 'xdvi -s 4'; |
---|
| 139 | $dvi_previewer_landscape = 'xdvi -s 4 -paper a4r'; |
---|
| 140 | $dvi_cont_previewer = 'xtex'; |
---|
| 141 | $dvi_cont_previewer_landscape = 'xtex'; |
---|
| 142 | $lpr = 'lpr'; |
---|
| 143 | $tmpdir = '/usr/tmp'; |
---|
| 144 | $pscmd = 'ps -x'; # This works for SunOs. Solaris should just be 'ps' |
---|
| 145 | |
---|
| 146 | ## default flag settings. |
---|
| 147 | $bibtex_mode = 0; # is there a bibliography needing bibtexing? |
---|
| 148 | $index_mode = 0; # is there an index needing makeindex run? |
---|
| 149 | $landscape_mode = 0; # default to portrait mode |
---|
| 150 | $sleep_time = 2; # time to sleep b/w checks for file changes in -pvc mode |
---|
| 151 | $banner = 0; # Non-zero if we have a banner to insert |
---|
| 152 | $banner_scale = 220; # Original default scale |
---|
| 153 | $banner_intensity = 0.95; # Darkness of the banner message |
---|
| 154 | $banner_message = 'DRAFT'; # Original default message |
---|
| 155 | $dvi_filter = ''; # DVI filter command |
---|
| 156 | $ps_filter = ''; # Postscript filter command |
---|
| 157 | |
---|
| 158 | ## Read rc files. |
---|
| 159 | # Read system rc file. |
---|
| 160 | $rcfile = '/usr/local/lib/latexmk/LatexMk'; |
---|
| 161 | if ( -e $rcfile ) |
---|
| 162 | { |
---|
| 163 | # Read the system rc file |
---|
| 164 | do "$rcfile"; |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | # Read user rc file. |
---|
| 168 | $rcfile = "$ENV{'HOME'}/.latexmkrc"; |
---|
| 169 | if ( -e $rcfile ) |
---|
| 170 | { |
---|
| 171 | # Read the user rc file |
---|
| 172 | do "$rcfile"; |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | # Read rc file in current directory. |
---|
| 176 | $rcfile = "latexmkrc"; |
---|
| 177 | if ( -e $rcfile ) |
---|
| 178 | { |
---|
| 179 | # Read the user rc file |
---|
| 180 | do "$rcfile"; |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | |
---|
| 184 | ## Process command line args. |
---|
| 185 | @the_file_list = ( ); |
---|
| 186 | while ($_ = $ARGV[0]) |
---|
| 187 | { |
---|
| 188 | shift; |
---|
| 189 | if (/^-c$/) { $cleanup_mode = 1; } |
---|
| 190 | elsif (/^-C$/) { $cleanup_mode = 1; $cleanup_full_mode = 1; } |
---|
| 191 | elsif (/^-d$/) { $banner = 1; } |
---|
| 192 | elsif (/^-f$/) { $force_mode = 1; } |
---|
| 193 | elsif (/^-F$/) { $force_include_mode = 1; } |
---|
| 194 | elsif (/^-g$/) { $go_mode = 1; } |
---|
| 195 | elsif (/^-h$/) { &print_help; } |
---|
| 196 | elsif (/^-i$/) { $generate_and_save_includes = 1; } |
---|
| 197 | elsif (/^-I$/) { $force_generate_and_save_includes = 1; } |
---|
| 198 | elsif (/^-l$/) { $landscape_mode = 1; } |
---|
| 199 | elsif (/^-pvc$/) { $preview_continuous_mode = 1; } |
---|
| 200 | elsif (/^-pv$/) { $preview_mode = 1; } |
---|
| 201 | elsif (/^-ps$/) { $postscript_mode = 1; } |
---|
| 202 | elsif (/^-p$/) { $printout_mode = 1; } |
---|
| 203 | elsif (/^-s$/) { $slide_mode = 1; } |
---|
| 204 | elsif (/^-v$/) { warn "\nLatexMk $version_num\n"; exit; } |
---|
| 205 | elsif (/^-r$/) { if ( $ARGV[0] eq '' ) { |
---|
| 206 | warn "LatexMk: No RC file specified\n"; &print_help; } |
---|
| 207 | if ( -e $ARGV[0] ) { |
---|
| 208 | do "$ARGV[0]"; } else { |
---|
| 209 | die "LatexMk: RC file [$ARGV[0]] does not exist\n"; } |
---|
| 210 | shift; } |
---|
| 211 | elsif (/^-bm$/) { if ( $ARGV[0] eq '' ) { |
---|
| 212 | warn "LatexMk: No message specified\n"; &print_help; } |
---|
| 213 | $banner = 1; $banner_message = $ARGV[0]; |
---|
| 214 | shift; } |
---|
| 215 | elsif (/^-bi$/) { if ( $ARGV[0] eq '' ) { |
---|
| 216 | warn "LatexMk: No intensity specified\n"; &print_help; } |
---|
| 217 | $banner_intensity = $ARGV[0]; |
---|
| 218 | shift; } |
---|
| 219 | elsif (/^-bs$/) { if ( $ARGV[0] eq '' ) { |
---|
| 220 | warn "LatexMk: No scale specified\n"; &print_help; } |
---|
| 221 | $banner_scale = $ARGV[0]; |
---|
| 222 | shift; } |
---|
| 223 | elsif (/^-dF$/) { if ( $ARGV[0] eq '' ) { |
---|
| 224 | warn "LatexMk: No dvi filter specified\n"; &print_help; } |
---|
| 225 | $dvi_filter = $ARGV[0]; |
---|
| 226 | shift; } |
---|
| 227 | elsif (/^-pF$/) { if ( $ARGV[0] eq '' ) { |
---|
| 228 | warn "LatexMk: No ps filter specified\n"; &print_help; } |
---|
| 229 | $ps_filter = $ARGV[0]; |
---|
| 230 | shift; } |
---|
| 231 | elsif (/^-/) { warn "LatexMk: $_ bad option\n"; } |
---|
| 232 | else { @the_file_list = ( @the_file_list, $_ ); } |
---|
| 233 | } |
---|
| 234 | @ARGV = @the_file_list; |
---|
| 235 | |
---|
| 236 | # Check we haven't selected mutually exclusive modes. |
---|
| 237 | # Note that -c overides all other options, but doesn't cause |
---|
| 238 | # an error if they are selected. |
---|
| 239 | if (($printout_mode && ( $preview_mode || $preview_continuous_mode )) |
---|
| 240 | || ( $preview_mode && $preview_continuous_mode )) |
---|
| 241 | { |
---|
| 242 | warn "LatexMk: Conflicting options (-p, -pv, -pvc) selected\n"; |
---|
| 243 | &print_help; |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | |
---|
| 247 | # If seleced a previewer mode, make sure one and only one filename was specified |
---|
| 248 | if ($preview_mode || $preview_continuous_mode) |
---|
| 249 | { |
---|
| 250 | if (($ARGV[0] eq '') || ($ARGV[1] ne '')) |
---|
| 251 | { |
---|
| 252 | warn"LatexMk: Need to specify one and only one filename for previewer mode\n"; |
---|
| 253 | &print_help; |
---|
| 254 | } |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | # If no files specified, try and find some |
---|
| 258 | if ($ARGV[0] eq '') |
---|
| 259 | { |
---|
| 260 | @ARGV=<*.tex $texfile_search>; |
---|
| 261 | } |
---|
| 262 | # If still no files, exit. |
---|
| 263 | if ($ARGV[0] eq '') |
---|
| 264 | { |
---|
| 265 | warn "LatexMk: No file name specified\n"; |
---|
| 266 | &print_help; ## print_help function exits. |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | # If landscape mode, change modes |
---|
| 270 | if ( $landscape_mode ) |
---|
| 271 | { |
---|
| 272 | $dvips = $dvips_landscape; |
---|
| 273 | $dvi_previewer = $dvi_previewer_landscape; |
---|
| 274 | $dvi_cont_previewer = $dvi_cont_previewer_landscape; |
---|
| 275 | $ps_previewer = $ps_previewer_landscape; |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | # Process for each file. |
---|
| 279 | foreach $filename ( @ARGV ) |
---|
| 280 | { |
---|
| 281 | ## remove extention from filename if was given. |
---|
| 282 | if ( &find_basename($filename, $root_filename, $texfile_name) ) |
---|
| 283 | { |
---|
| 284 | die "LatexMk: Could not find file [$texfile_name]\n"; |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | if ($cleanup_mode) |
---|
| 288 | { |
---|
| 289 | ## Do clean if necessary |
---|
| 290 | &cleanup; |
---|
| 291 | if ($cleanup_full_mode) |
---|
| 292 | { |
---|
| 293 | &cleanup_full; |
---|
| 294 | } |
---|
| 295 | } |
---|
| 296 | else |
---|
| 297 | { |
---|
| 298 | ## Make file. ## |
---|
| 299 | ## Find includes. |
---|
| 300 | $includes = ''; |
---|
| 301 | $read_depend = 0; # True to read depend file, false to generate it. |
---|
| 302 | $depfile = "$root_filename.dep"; |
---|
| 303 | |
---|
| 304 | ## Figure out if we read the dependency file or generate a new one. |
---|
| 305 | if ( ! $force_generate_and_save_includes ) |
---|
| 306 | { |
---|
| 307 | if ( $generate_and_save_includes ) |
---|
| 308 | { |
---|
| 309 | if ( -e $depfile ) |
---|
| 310 | { |
---|
| 311 | # Compare timestamp of dependency file and root tex file. |
---|
| 312 | $dep_mtime = &get_mtime("$depfile"); |
---|
| 313 | $tex_mtime = &get_mtime("$texfile_name"); |
---|
| 314 | if ( $tex_mtime < $dep_mtime ) |
---|
| 315 | { |
---|
| 316 | $read_depend = 1; |
---|
| 317 | } |
---|
| 318 | } |
---|
| 319 | } |
---|
| 320 | elsif ( -e $depfile ) # If dependency file already exists. |
---|
| 321 | { |
---|
| 322 | $read_depend = 1; |
---|
| 323 | } |
---|
| 324 | } |
---|
| 325 | |
---|
| 326 | if ( $read_depend ) |
---|
| 327 | { |
---|
| 328 | # Read the dependency file |
---|
| 329 | open(depfile) || die "LatexMk: Couldn't open dependency file [$root_filename.dep]\n"; |
---|
| 330 | while(<depfile>) { eval; } |
---|
| 331 | close(depfile); |
---|
| 332 | } |
---|
| 333 | else |
---|
| 334 | { |
---|
| 335 | # Generate dependency file. |
---|
| 336 | # get search paths for includes. |
---|
| 337 | $psfigsearchpath = '.'; |
---|
| 338 | $TEXINPUTS = $ENV{'TEXINPUTS'}; |
---|
| 339 | if (!$TEXINPUTS) { $TEXINPUTS = '.'; } |
---|
| 340 | $BIBINPUTS = $ENV{'BIBINPUTS'}; |
---|
| 341 | if (!$BIBINPUTS) { $BIBINPUTS = $TEXINPUTS; } |
---|
| 342 | |
---|
| 343 | &scan_for_includes("$texfile_name"); |
---|
| 344 | &update_depend_file; |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | ## put root tex file into list of includes. |
---|
| 348 | $includes .= " $texfile_name"; |
---|
| 349 | |
---|
| 350 | ## before munging, save existing .aux file. |
---|
| 351 | ## - if latex bombs, kill .aux, restore this backup to get back most |
---|
| 352 | ## useful bib/ref info. |
---|
| 353 | system("cp -p $root_filename.aux $root_filename.aux.bak > /dev/null 2>&1"); |
---|
| 354 | |
---|
| 355 | #************************************************************ |
---|
| 356 | |
---|
| 357 | &make_dependents("$includes"); |
---|
| 358 | if ($slide_mode) |
---|
| 359 | { |
---|
| 360 | &make_slitex_dvi; |
---|
| 361 | } |
---|
| 362 | else |
---|
| 363 | { |
---|
| 364 | &make_latex_dvi; |
---|
| 365 | } |
---|
| 366 | &make_dvi_filtered; |
---|
| 367 | &make_preview_continous; |
---|
| 368 | &make_postscript; |
---|
| 369 | &make_preview; |
---|
| 370 | &make_printout; |
---|
| 371 | } |
---|
| 372 | } |
---|
| 373 | |
---|
| 374 | #************************************************************ |
---|
| 375 | #### Subroutines |
---|
| 376 | #************************************************************ |
---|
| 377 | |
---|
| 378 | sub make_latex_dvi |
---|
| 379 | { |
---|
| 380 | $changed_dvi = 0 ; # flag if anything changed. |
---|
| 381 | ## get initial last modified times. |
---|
| 382 | $tex_mtime = &get_latest_mtime($includes); |
---|
| 383 | $aux_mtime = &get_mtime("$root_filename.aux"); |
---|
| 384 | $bbl_mtime = &get_mtime("$root_filename.bbl"); |
---|
| 385 | $ilg_mtime = &get_mtime("$root_filename.ilg"); |
---|
| 386 | $ind_mtime = &get_mtime("$root_filename.ind"); |
---|
| 387 | |
---|
| 388 | ## - if no dvi file, or .aux older than tex file or bib file, run latex. |
---|
| 389 | if ( $go_mode || !(-e "$root_filename.dvi") |
---|
| 390 | || ($aux_mtime < $tex_mtime) |
---|
| 391 | || ($aux_mtime < $bbl_mtime) |
---|
| 392 | || ($aux_mtime < $ilg_mtime) |
---|
| 393 | || ($aux_mtime < $ind_mtime) |
---|
| 394 | || !(-e "$root_filename.aux")) |
---|
| 395 | { |
---|
| 396 | warn "------------\nRunning first $latex [$texfile_name]\n------------\n"; |
---|
| 397 | &backup_toc; |
---|
| 398 | $return = system("$latex $texfile_name"); |
---|
| 399 | $changed_dvi = 1; |
---|
| 400 | |
---|
| 401 | if (!$force_mode && $return) |
---|
| 402 | { |
---|
| 403 | &exit_msg('Latex encountered an error',1); |
---|
| 404 | } |
---|
| 405 | |
---|
| 406 | if ($index_mode) |
---|
| 407 | { |
---|
| 408 | warn "------------\nRunning $makeindex [$root_filename]\n------------\n"; |
---|
| 409 | $return = system("$makeindex $root_filename"); |
---|
| 410 | |
---|
| 411 | if (!$force_mode && $return) |
---|
| 412 | { |
---|
| 413 | &exit_msg('Makeindex encountered an error'); |
---|
| 414 | } |
---|
| 415 | $ilg_mtime = &get_mtime("$root_filename.ilg"); |
---|
| 416 | $ind_mtime = &get_mtime("$root_filename.ind"); |
---|
| 417 | } |
---|
| 418 | } |
---|
| 419 | |
---|
| 420 | $bib_mtime = &get_latest_mtime($bib_files); |
---|
| 421 | ## if no .bbl or .bib changed since last bibtex run, run bibtex. |
---|
| 422 | if ($bibtex_mode && (&check_for_bad_citation || !(-e "$root_filename.bbl") |
---|
| 423 | || ($bbl_mtime < $bib_mtime))) |
---|
| 424 | { |
---|
| 425 | warn "------------\nRunning $bibtex [$root_filename]\n------------\n"; |
---|
| 426 | $return = system("$bibtex $root_filename"); |
---|
| 427 | $bbl_mtime = &get_mtime("$root_filename.bbl"); |
---|
| 428 | } |
---|
| 429 | |
---|
| 430 | if ($bibtex_mode && &check_for_bibtex_errors) |
---|
| 431 | { |
---|
| 432 | if (!$force_mode) |
---|
| 433 | { |
---|
| 434 | # touch a .bib file so that will rerun bibtex to fix errors. |
---|
| 435 | @split_bib_files = split(' ',$bib_files); |
---|
| 436 | system("touch $split_bib_files[0]"); |
---|
| 437 | &exit_msg('Bibtex reported an error'); |
---|
| 438 | } |
---|
| 439 | } |
---|
| 440 | |
---|
| 441 | ## now, if need to, rerun latex up to twice to generate valid .dvi |
---|
| 442 | ## w/ citations resolved. |
---|
| 443 | |
---|
| 444 | $dvi_mtime = &get_mtime("$root_filename.dvi"); |
---|
| 445 | if ( ($dvi_mtime <= $bbl_mtime) || &check_for_reference_change |
---|
| 446 | || ($dvi_mtime <= $ilg_mtime) |
---|
| 447 | || ($dvi_mtime <= $ind_mtime) |
---|
| 448 | || (&check_toc)) |
---|
| 449 | { |
---|
| 450 | warn "------------\nRunning second $latex [$texfile_name]\n------------\n"; |
---|
| 451 | &backup_toc; |
---|
| 452 | $return = system("$latex $texfile_name"); |
---|
| 453 | $changed_dvi = 1; |
---|
| 454 | } |
---|
| 455 | |
---|
| 456 | if (!$force_mode && $return) |
---|
| 457 | { |
---|
| 458 | &exit_msg('Latex encountered an error',1); |
---|
| 459 | } |
---|
| 460 | |
---|
| 461 | if (&check_for_reference_change || &check_toc) |
---|
| 462 | { |
---|
| 463 | warn "------------\nRunning third $latex [$texfile_name]\n------------\n"; |
---|
| 464 | &backup_toc; |
---|
| 465 | $return = system("$latex $texfile_name"); |
---|
| 466 | $changed_dvi = 1; |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | if (!$force_mode && &check_for_bad_reference) |
---|
| 470 | { |
---|
| 471 | &exit_msg('Latex could not resolve all references'); |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | if (!$force_mode && &check_for_bad_citation) |
---|
| 475 | { |
---|
| 476 | &exit_msg('Latex could not resolve all citations or labels'); |
---|
| 477 | } |
---|
| 478 | |
---|
| 479 | return(1); |
---|
| 480 | } |
---|
| 481 | |
---|
| 482 | #************************************************************ |
---|
| 483 | |
---|
| 484 | sub make_slitex_dvi |
---|
| 485 | { |
---|
| 486 | $tex_mtime = &get_latest_mtime($includes); |
---|
| 487 | $dvi_mtime = &get_mtime("$root_filename.dvi"); |
---|
| 488 | if ( $go_mode || !(-e "$root_filename.dvi") || ($dvi_mtime < $tex_mtime) ) |
---|
| 489 | { |
---|
| 490 | warn "------------\nRunning $slitex [$texfile_name]\n------------\n"; |
---|
| 491 | $return = system("$slitex $texfile_name"); |
---|
| 492 | } |
---|
| 493 | if (!$force_mode && $return) |
---|
| 494 | { |
---|
| 495 | &exit_msg('Slitex encountered an error'); |
---|
| 496 | } |
---|
| 497 | } |
---|
| 498 | |
---|
| 499 | #************************************************************ |
---|
| 500 | |
---|
| 501 | sub make_dvi_filtered |
---|
| 502 | { |
---|
| 503 | return if ( length($dvi_filter) == 0 ); |
---|
| 504 | warn "------------\nRunning $dvi_filter [$root_filename]\n------------\n"; |
---|
| 505 | system("$dvi_filter < $root_filename.dvi > $root_filename.dviF"); |
---|
| 506 | } |
---|
| 507 | |
---|
| 508 | #************************************************************ |
---|
| 509 | # Finds the basename of the root file |
---|
| 510 | # Arguments: |
---|
| 511 | # 1 - Filename to breakdown |
---|
| 512 | # 2 - Where to place base file |
---|
| 513 | # 3 - Where to place tex file |
---|
| 514 | # Returns non-zero if tex file exists |
---|
| 515 | sub find_basename |
---|
| 516 | { |
---|
| 517 | local($base_name,$ch,$ext,$base_path); |
---|
| 518 | |
---|
| 519 | $ch = ''; |
---|
| 520 | $ext = ''; |
---|
| 521 | $base_path = $_[0]; |
---|
| 522 | while (( $ch ne '.' ) && ( $ch ne '/' ) && ( $base_path ne '' )) |
---|
| 523 | { |
---|
| 524 | $ext = $ch . $ext; |
---|
| 525 | $ch = chop $base_path; |
---|
| 526 | } |
---|
| 527 | if (( $ch eq '.' ) && ( $base_path ne '' )) |
---|
| 528 | { |
---|
| 529 | ## Found extention stuff |
---|
| 530 | $_[2] = $base_path . '.' . $ext; |
---|
| 531 | } |
---|
| 532 | else |
---|
| 533 | { |
---|
| 534 | ## No extention |
---|
| 535 | $base_path = $_[0]; |
---|
| 536 | $_[2] = $_[0]; |
---|
| 537 | } |
---|
| 538 | $ch = ''; |
---|
| 539 | $base_name = ''; |
---|
| 540 | while (( $ch ne '/' ) && ( $base_path ne '' )) |
---|
| 541 | { |
---|
| 542 | $ch = chop $base_path; |
---|
| 543 | if ( $ch ne '/' ) |
---|
| 544 | { |
---|
| 545 | $base_name = $ch . $base_name; |
---|
| 546 | } |
---|
| 547 | } |
---|
| 548 | $_[1] = $base_name; |
---|
| 549 | if ( ! -e $_[2] ) |
---|
| 550 | { |
---|
| 551 | ## File does not exist, try adding a ".tex" extention |
---|
| 552 | if ( -e "$_[2].tex" ) |
---|
| 553 | { |
---|
| 554 | # Adding the extention works, so put the extention back on the |
---|
| 555 | # basename |
---|
| 556 | $_[1] = $_[2]; |
---|
| 557 | $_[2] .= '.tex'; |
---|
| 558 | return(0); |
---|
| 559 | } |
---|
| 560 | return(1); |
---|
| 561 | } |
---|
| 562 | return(0); |
---|
| 563 | } |
---|
| 564 | |
---|
| 565 | #************************************************************ |
---|
| 566 | |
---|
| 567 | sub make_dependents |
---|
| 568 | { |
---|
| 569 | local($file,$dep,$base_name,$ch,$toext,$fromext,$proptoext,$must,$func_name,$return); |
---|
| 570 | |
---|
| 571 | foreach $file (split(' ',$_[0])) |
---|
| 572 | { |
---|
| 573 | $ch = ''; |
---|
| 574 | $toext = ''; |
---|
| 575 | $base_name = $file; |
---|
| 576 | while (( $ch ne '.' ) && ( $ch ne '/' ) && ( $base_name ne '' )) |
---|
| 577 | { |
---|
| 578 | $toext = $ch . $toext; |
---|
| 579 | $ch = chop $base_name; |
---|
| 580 | } |
---|
| 581 | if (( $ch eq '.' ) && ( $base_name ne '' )) |
---|
| 582 | { |
---|
| 583 | #Extracted proper extention. |
---|
| 584 | foreach $dep ( @cus_dep_list ) |
---|
| 585 | { |
---|
| 586 | ($fromext,$proptoext,$must,$func_name) = split(' ',$dep); |
---|
| 587 | if ( $toext eq $proptoext ) |
---|
| 588 | { |
---|
| 589 | # Found match |
---|
| 590 | if ( -e "$base_name.$fromext" ) |
---|
| 591 | { |
---|
| 592 | # From file exists, now check if it is newer |
---|
| 593 | if (( ! (-e "$base_name.$toext" )) |
---|
| 594 | || ( &get_mtime("$base_name.$toext") |
---|
| 595 | < &get_mtime("$base_name.$fromext") )) |
---|
| 596 | { |
---|
| 597 | warn "------------\nRunning $func_name [$base_name]\n------------\n"; |
---|
| 598 | $return = &$func_name($base_name); |
---|
| 599 | if ( !$force_mode && $return ) |
---|
| 600 | { |
---|
| 601 | &exit_msg("$func_name encountered an error"); |
---|
| 602 | } |
---|
| 603 | } |
---|
| 604 | } |
---|
| 605 | else |
---|
| 606 | { |
---|
| 607 | if ( !$force_mode && ( $must != 0 )) |
---|
| 608 | { |
---|
| 609 | &exit_msg("File '$base_name.$fromext' does not exist to build '$base_name.$toext'\n"); |
---|
| 610 | } |
---|
| 611 | } |
---|
| 612 | } |
---|
| 613 | } |
---|
| 614 | } |
---|
| 615 | } |
---|
| 616 | } |
---|
| 617 | |
---|
| 618 | #************************************************************ |
---|
| 619 | |
---|
| 620 | sub make_printout |
---|
| 621 | { |
---|
| 622 | return if (!$printout_mode); |
---|
| 623 | local ($ext); |
---|
| 624 | if ( length($ps_filter) == 0 ) |
---|
| 625 | { |
---|
| 626 | $ext = '.ps'; |
---|
| 627 | } |
---|
| 628 | else |
---|
| 629 | { |
---|
| 630 | $ext = '.psF'; |
---|
| 631 | } |
---|
| 632 | warn "------------\nPrinting using $lpr [$root_filename]\n------------\n"; |
---|
| 633 | system("$lpr $root_filename$ext"); |
---|
| 634 | } |
---|
| 635 | |
---|
| 636 | #************************************************************ |
---|
| 637 | |
---|
| 638 | sub make_postscript |
---|
| 639 | { |
---|
| 640 | if ( ! $banner ) |
---|
| 641 | { |
---|
| 642 | return if (!$postscript_mode && !$printout_mode); |
---|
| 643 | } |
---|
| 644 | local ($tmpfile,$header,$dvi_file); |
---|
| 645 | |
---|
| 646 | # Figure out the dvi file name |
---|
| 647 | if ( length($dvi_filter) == 0 ) |
---|
| 648 | { |
---|
| 649 | $dvi_file = "$root_filename.dvi"; |
---|
| 650 | } |
---|
| 651 | else |
---|
| 652 | { |
---|
| 653 | $dvi_file = "$root_filename.dviF"; |
---|
| 654 | } |
---|
| 655 | |
---|
| 656 | # Do banner stuff |
---|
| 657 | if ( $banner ) |
---|
| 658 | { |
---|
| 659 | ## Make temp banner file |
---|
| 660 | local(*INFILE,*OUTFILE,$count); |
---|
| 661 | |
---|
| 662 | $tmpfile = "$tmpdir/latexmk.$$"; |
---|
| 663 | $count = 0; |
---|
| 664 | while ( -e $tmpfile ) |
---|
| 665 | { |
---|
| 666 | $count = $count + 1; |
---|
| 667 | $tmpfile = "$tmpdir/latexmk.$$.$count"; |
---|
| 668 | } |
---|
| 669 | if ( ! open(OUTFILE, ">$tmpfile") ) { |
---|
| 670 | die "LatexMk: Could not open temporary file [$tmpfile]\n"; } |
---|
| 671 | print OUTFILE "userdict begin /bop-hook{gsave 200 30 translate\n"; |
---|
| 672 | print OUTFILE "65 rotate /Times-Roman findfont $banner_scale scalefont setfont\n"; |
---|
| 673 | print OUTFILE "0 0 moveto $banner_intensity setgray ($banner_message) show grestore}def end\n"; |
---|
| 674 | close(OUTFILE); |
---|
| 675 | $header = "-h $tmpfile"; |
---|
| 676 | } |
---|
| 677 | else |
---|
| 678 | { |
---|
| 679 | $header = ''; |
---|
| 680 | } |
---|
| 681 | |
---|
| 682 | $ps_mtime = &get_mtime("$root_filename.ps"); |
---|
| 683 | $dvi_mtime = &get_mtime("$dvi_file"); |
---|
| 684 | if (( $ps_mtime < $dvi_mtime ) || $banner ) |
---|
| 685 | { |
---|
| 686 | warn "------------\nRunning $dvips [$root_filename]\n------------\n"; |
---|
| 687 | system("$dvips $header $dvi_file -o $root_filename.ps"); |
---|
| 688 | } |
---|
| 689 | |
---|
| 690 | if ( $banner ) |
---|
| 691 | { |
---|
| 692 | unlink("$tmpfile"); |
---|
| 693 | } |
---|
| 694 | |
---|
| 695 | ## Do we have postscript filtering? |
---|
| 696 | if ( length($ps_filter) != 0 ) |
---|
| 697 | { |
---|
| 698 | warn "------------\nRunning $ps_filter [$root_filename]\n------------\n"; |
---|
| 699 | system("$ps_filter < $root_filename.ps > $root_filename.psF"); |
---|
| 700 | } |
---|
| 701 | } |
---|
| 702 | |
---|
| 703 | #************************************************************ |
---|
| 704 | # run appropriate previewer. |
---|
| 705 | |
---|
| 706 | sub make_preview |
---|
| 707 | { |
---|
| 708 | return if (!$preview_mode); |
---|
| 709 | $viewer = $dvi_previewer; |
---|
| 710 | $ext = '.dvi'; |
---|
| 711 | if ($postscript_mode) |
---|
| 712 | { |
---|
| 713 | $viewer = $ps_previewer; |
---|
| 714 | $ext = '.ps'; |
---|
| 715 | if ( length($ps_filter) != 0 ) |
---|
| 716 | { |
---|
| 717 | $ext = '.psF'; |
---|
| 718 | } |
---|
| 719 | } |
---|
| 720 | else |
---|
| 721 | { |
---|
| 722 | if ( length($dvi_filter) != 0 ) |
---|
| 723 | { |
---|
| 724 | $ext = '.dviF'; |
---|
| 725 | } |
---|
| 726 | } |
---|
| 727 | warn "------------\nStarting previewer: $viewer $root_filename$ext\n------------\n"; |
---|
| 728 | exec("$viewer $root_filename$ext"); |
---|
| 729 | warn "LatexMk: Could not start previewer [$viewer $root_filename$ext]"; |
---|
| 730 | exit; |
---|
| 731 | } |
---|
| 732 | |
---|
| 733 | sub backup_toc |
---|
| 734 | { |
---|
| 735 | if ( -e "$root_filename.toc" ) |
---|
| 736 | { |
---|
| 737 | system( |
---|
| 738 | "cp -p $root_filename.toc $root_filename.toc.bak > /dev/null 2>&1"); |
---|
| 739 | } |
---|
| 740 | } |
---|
| 741 | |
---|
| 742 | #************************************************************ |
---|
| 743 | # Compare the toc file with the backup. If they differ then |
---|
| 744 | # return non-zero. |
---|
| 745 | sub check_toc |
---|
| 746 | { |
---|
| 747 | local($return); |
---|
| 748 | |
---|
| 749 | if ( -e "$root_filename.toc" ) |
---|
| 750 | { |
---|
| 751 | if ( -e "$root_filename.toc.bak" ) |
---|
| 752 | { |
---|
| 753 | $return = system( |
---|
| 754 | "diff $root_filename.toc.bak $root_filename.toc > /dev/null 2>&1"); |
---|
| 755 | } |
---|
| 756 | else |
---|
| 757 | { |
---|
| 758 | $return = 1; |
---|
| 759 | } |
---|
| 760 | } |
---|
| 761 | else |
---|
| 762 | { |
---|
| 763 | $return = 0; |
---|
| 764 | } |
---|
| 765 | return($return); |
---|
| 766 | } |
---|
| 767 | |
---|
| 768 | #************************************************************ |
---|
| 769 | # arg1 = name |
---|
| 770 | |
---|
| 771 | sub find_process_id |
---|
| 772 | { |
---|
| 773 | local(@command, $lookingfor); |
---|
| 774 | @ps_output = `$pscmd`; |
---|
| 775 | shift(@ps_output); # Discard the header line from ps |
---|
| 776 | foreach (@ps_output) |
---|
| 777 | { |
---|
| 778 | # s/\s+/ /g; #Compress multiple spaces. |
---|
| 779 | ($pid,$tt,$stat,$time,@command) = split(' ',$_); |
---|
| 780 | if ("@command" eq "$_[0]") |
---|
| 781 | { |
---|
| 782 | return($pid); |
---|
| 783 | } |
---|
| 784 | } |
---|
| 785 | return(0); |
---|
| 786 | } |
---|
| 787 | |
---|
| 788 | #************************************************************ |
---|
| 789 | |
---|
| 790 | sub make_preview_continous |
---|
| 791 | { |
---|
| 792 | return if (!$preview_continuous_mode); |
---|
| 793 | # |
---|
| 794 | local ($dvi_file); |
---|
| 795 | # get the value of SIGUSR1, defaults to SPARC value. |
---|
| 796 | if (!(do 'signal.ph')) |
---|
| 797 | { |
---|
| 798 | eval 'sub SIGUSR1 {30;}'; |
---|
| 799 | } |
---|
| 800 | # Figure out the dvi file name |
---|
| 801 | if ( length($dvi_filter) == 0 ) |
---|
| 802 | { |
---|
| 803 | $dvi_file = "$root_filename.dvi"; |
---|
| 804 | } |
---|
| 805 | else |
---|
| 806 | { |
---|
| 807 | $dvi_file = "$root_filename.dviF"; |
---|
| 808 | } |
---|
| 809 | # note, we only launch a previewer if one isnt already running... |
---|
| 810 | # otherwise we'll send reopen signals to the existing previewer. |
---|
| 811 | if ($previewer_pid = &find_process_id("$dvi_cont_previewer $dvi_file")) |
---|
| 812 | { |
---|
| 813 | warn "------------\nReattached to existing previewer, pid=$pid\n------------\n"; |
---|
| 814 | kill &SIGUSR1,$previewer_pid; |
---|
| 815 | } |
---|
| 816 | else |
---|
| 817 | { |
---|
| 818 | if (!($previewer_pid = fork)) |
---|
| 819 | { |
---|
| 820 | # in forked child, close off from parent so previewer runs on |
---|
| 821 | # after parent 'latexmk' dies. |
---|
| 822 | setpgrp($$,0); |
---|
| 823 | warn "------------\n$dvi_cont_previewer $dvi_file\n------------\n"; |
---|
| 824 | exec("$dvi_cont_previewer $dvi_file"); |
---|
| 825 | warn "LatexMk: Failed to exec file viewer\n"; |
---|
| 826 | exit; |
---|
| 827 | } |
---|
| 828 | } |
---|
| 829 | # Loop forever, rebuilding .dvi as necessary. |
---|
| 830 | while ( 1 ) |
---|
| 831 | { |
---|
| 832 | sleep($sleep_time); |
---|
| 833 | if ($slide_mode) |
---|
| 834 | { |
---|
| 835 | &make_slitex_dvi; |
---|
| 836 | } |
---|
| 837 | else |
---|
| 838 | { |
---|
| 839 | &make_latex_dvi; |
---|
| 840 | } |
---|
| 841 | if ($changed_dvi) |
---|
| 842 | { |
---|
| 843 | kill &SIGUSR1,$previewer_pid; |
---|
| 844 | } |
---|
| 845 | } |
---|
| 846 | } |
---|
| 847 | |
---|
| 848 | #************************************************************ |
---|
| 849 | |
---|
| 850 | sub get_mtime |
---|
| 851 | { |
---|
| 852 | local ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime, |
---|
| 853 | $ctime,$blksize,$blocks) = stat($_[0]); |
---|
| 854 | $mtime; |
---|
| 855 | } |
---|
| 856 | |
---|
| 857 | #************************************************************ |
---|
| 858 | |
---|
| 859 | sub check_for_reference_change |
---|
| 860 | { |
---|
| 861 | local($logfile) = "$root_filename.log"; |
---|
| 862 | open(logfile) || die "LatexMk: Could not open log file to check for reference check\n"; |
---|
| 863 | while(<logfile>) |
---|
| 864 | { |
---|
| 865 | if (/Rerun to get/) { return 1; } |
---|
| 866 | } |
---|
| 867 | 0; |
---|
| 868 | } |
---|
| 869 | |
---|
| 870 | #************************************************************ |
---|
| 871 | |
---|
| 872 | sub check_for_bad_reference |
---|
| 873 | { |
---|
| 874 | local($logfile) = "$root_filename.log"; |
---|
| 875 | open(logfile) || die "LatexMk: Could not open log file to check for bad reference\n"; |
---|
| 876 | while (<logfile>) |
---|
| 877 | { |
---|
| 878 | if (/LaTeX Warning: Reference[^\001]*undefined./) { return 1; } |
---|
| 879 | } |
---|
| 880 | 0; |
---|
| 881 | } |
---|
| 882 | |
---|
| 883 | #************************************************************ |
---|
| 884 | # check for citation which latex couldnt resolve. |
---|
| 885 | |
---|
| 886 | sub check_for_bad_citation |
---|
| 887 | { |
---|
| 888 | local($logfile) = "$root_filename.log"; |
---|
| 889 | open(logfile) || die "LatexMk: Could not open log file to check for bad citation\n"; |
---|
| 890 | while (<logfile>) |
---|
| 891 | { |
---|
| 892 | if (/LaTeX Warning: Citation[^\001]*undefined./) { return 1; } |
---|
| 893 | } |
---|
| 894 | 0; |
---|
| 895 | } |
---|
| 896 | |
---|
| 897 | #************************************************************ |
---|
| 898 | # check for citation which bibtex didnt find. |
---|
| 899 | |
---|
| 900 | sub check_for_bibtex_errors |
---|
| 901 | { |
---|
| 902 | local($logfile) = "$root_filename.blg"; |
---|
| 903 | open(logfile) || die "LatexMk: Could not open bibtex log file error check\n"; |
---|
| 904 | while (<logfile>) |
---|
| 905 | { |
---|
| 906 | if (/Warning--/) { return 1; } |
---|
| 907 | if (/error message/) { return 1; } |
---|
| 908 | } |
---|
| 909 | 0; |
---|
| 910 | } |
---|
| 911 | |
---|
| 912 | #************************************************************ |
---|
| 913 | # cleanup |
---|
| 914 | # - erases all generated files, exits w/ no other processing. |
---|
| 915 | |
---|
| 916 | sub cleanup |
---|
| 917 | { |
---|
| 918 | unlink("$root_filename.aux"); |
---|
| 919 | unlink("$root_filename.aux.bak"); |
---|
| 920 | unlink("$root_filename.bbl"); |
---|
| 921 | unlink("$root_filename.blg"); |
---|
| 922 | unlink("$root_filename.log"); |
---|
| 923 | unlink("$root_filename.ind"); |
---|
| 924 | unlink("$root_filename.idx"); |
---|
| 925 | unlink("$root_filename.ilg"); |
---|
| 926 | unlink("$root_filename.toc"); |
---|
| 927 | unlink("$root_filename.toc.bak"); |
---|
| 928 | unlink("$root_filename.lof"); |
---|
| 929 | unlink("$root_filename.lot"); |
---|
| 930 | unlink("$root_filename.dep"); |
---|
| 931 | unlink("texput.log"); |
---|
| 932 | unlink("texput.aux"); |
---|
| 933 | |
---|
| 934 | # .aux files are also made for \include'd files |
---|
| 935 | foreach $include (split(' ',$includes)) |
---|
| 936 | { |
---|
| 937 | $include =~ s/\.[^\.]*$/.aux/; |
---|
| 938 | unlink($include); |
---|
| 939 | } |
---|
| 940 | # Do any other file extentions specified |
---|
| 941 | foreach $ext (split(' ',$clean_ext)) |
---|
| 942 | { |
---|
| 943 | unlink("$root_filename.$ext"); |
---|
| 944 | } |
---|
| 945 | } |
---|
| 946 | |
---|
| 947 | #************************************************************ |
---|
| 948 | sub cleanup_full |
---|
| 949 | { |
---|
| 950 | unlink("$root_filename.dvi"); |
---|
| 951 | unlink("$root_filename.ps"); |
---|
| 952 | unlink("$root_filename.dviF"); |
---|
| 953 | unlink("$root_filename.psF"); |
---|
| 954 | unlink("texput.dvi"); |
---|
| 955 | # Do any other file extentions specified |
---|
| 956 | foreach $ext (split(' ',$clean_full_ext)) |
---|
| 957 | { |
---|
| 958 | unlink("$root_filename.$ext"); |
---|
| 959 | } |
---|
| 960 | } |
---|
| 961 | |
---|
| 962 | #************************************************************ |
---|
| 963 | sub print_help |
---|
| 964 | { |
---|
| 965 | warn "LatexMk $version_num: Automatic LaTeX document generation routine\n\n"; |
---|
| 966 | warn "Usage: latexmk [latexmk_options] [filename ...]\n\n"; |
---|
| 967 | warn " LatexMk_options:\n"; |
---|
| 968 | warn " -bm <message> - Print message across the page when converting to postscript\n"; |
---|
| 969 | warn " -bi <intensity> - Set contrast or intensity of banner\n"; |
---|
| 970 | warn " -bs <scale> - Set scale for banner\n"; |
---|
| 971 | warn " -c - clean up (remove) all nonessential files\n"; |
---|
| 972 | warn " -C - clean up (remove) all nonessential files\n"; |
---|
| 973 | warn " including dvi and postscript files\n"; |
---|
| 974 | warn " -d - Print `DRAFT' across the page when converting to postscript\n"; |
---|
| 975 | warn " -dF <filter> - Filter to apply to dvi file\n"; |
---|
| 976 | warn " -f - force continued processing past errors\n"; |
---|
| 977 | warn " -F - Ignore non-existent files when making dependencies\n"; |
---|
| 978 | warn " -g - process regardless of file timestamps\n"; |
---|
| 979 | warn " -h - print help\n"; |
---|
| 980 | warn " -i - rescan for includes if depenancy file older than tex file\n"; |
---|
| 981 | warn " -I - force rescan for includes\n"; |
---|
| 982 | warn " -l - force landscape mode\n"; |
---|
| 983 | warn " -ps - generate postscript\n"; |
---|
| 984 | warn " -pF <filter> - Filter to apply to postscript file\n"; |
---|
| 985 | warn " -p - print document after generating postscript\n"; |
---|
| 986 | warn " -pv - preview document\n"; |
---|
| 987 | warn " -pvc - preview document and continuously update\n"; |
---|
| 988 | warn " -r <file> - Read custom RC file\n"; |
---|
| 989 | warn " -s - set slide mode\n"; |
---|
| 990 | warn " -v - display program version\n"; |
---|
| 991 | warn " filename = the root filename of LaTeX document\n"; |
---|
| 992 | warn "\n -p, -pv and -pvc are mutually exclusive\n"; |
---|
| 993 | warn " -h, -c and -C overides all other options.\n"; |
---|
| 994 | warn " -pv and -pvc require one and only one filename specified\n"; |
---|
| 995 | warn " Contents of RC file specified by -r overrides options specified\n"; |
---|
| 996 | warn " before the -r option on the command line\n"; |
---|
| 997 | |
---|
| 998 | exit; |
---|
| 999 | } |
---|
| 1000 | |
---|
| 1001 | #************************************************************ |
---|
| 1002 | # - stats all files listed in first arg, returns most recent modify time of all. |
---|
| 1003 | |
---|
| 1004 | sub get_latest_mtime |
---|
| 1005 | { |
---|
| 1006 | local($return_mtime) = 0; |
---|
| 1007 | foreach $include (split(' ',$_[0])) |
---|
| 1008 | { |
---|
| 1009 | $include_mtime = &get_mtime($include); |
---|
| 1010 | if ($include_mtime > $return_mtime) |
---|
| 1011 | { |
---|
| 1012 | $return_mtime = $include_mtime; |
---|
| 1013 | } |
---|
| 1014 | } |
---|
| 1015 | $return_mtime; |
---|
| 1016 | } |
---|
| 1017 | |
---|
| 1018 | #************************************************************ |
---|
| 1019 | # - looks recursively for included & inputted and psfig'd files and puts |
---|
| 1020 | # them into $includes. |
---|
| 1021 | # - note only primitive comment removal: cannot deal with escaped %s, but then, |
---|
| 1022 | # when would they occur in any line important to LatexMk?? |
---|
| 1023 | |
---|
| 1024 | sub scan_for_includes |
---|
| 1025 | { |
---|
| 1026 | warn "------------\nGenerating Dependency File [$root_filename]\n------------\n"; |
---|
| 1027 | &scan_for_includes_($_[0]); |
---|
| 1028 | } |
---|
| 1029 | |
---|
| 1030 | sub scan_for_includes_ |
---|
| 1031 | { |
---|
| 1032 | local(*FILE,$orig_filename,$full_filename1,$full_filename2); |
---|
| 1033 | if (!open(FILE,$_[0])) |
---|
| 1034 | { |
---|
| 1035 | warn "LatexMk: could not open input file [$_[0]]\n"; |
---|
| 1036 | return; |
---|
| 1037 | } |
---|
| 1038 | while(<FILE>) |
---|
| 1039 | { |
---|
| 1040 | ($_,$junk) = split('%',$_); # primitive comment removal. |
---|
| 1041 | if (/\\include[{\s]+([^\001\040\011}]*)[\s}]/) |
---|
| 1042 | { |
---|
| 1043 | $full_filename = $1; |
---|
| 1044 | $orig_filename = $full_filename; |
---|
| 1045 | $full_filename1 = &find_file($full_filename,$TEXINPUTS,'1'); |
---|
| 1046 | |
---|
| 1047 | if (( $full_filename1 eq '' ) || ( ! -e $full_filename1 )) |
---|
| 1048 | { |
---|
| 1049 | $full_filename2 = &find_file("$full_filename.tex",$TEXINPUTS,'1'); |
---|
| 1050 | if (( $full_filename2 ne '' ) && ( -e $full_filename2 )) |
---|
| 1051 | { |
---|
| 1052 | $full_filename = $full_filename2; |
---|
| 1053 | } |
---|
| 1054 | else |
---|
| 1055 | { |
---|
| 1056 | $full_filename = $full_filename1; |
---|
| 1057 | } |
---|
| 1058 | } |
---|
| 1059 | else |
---|
| 1060 | { |
---|
| 1061 | $full_filename = $full_filename1; |
---|
| 1062 | } |
---|
| 1063 | |
---|
| 1064 | if ($full_filename) |
---|
| 1065 | { |
---|
| 1066 | $includes .= "$full_filename "; |
---|
| 1067 | if ( -e $full_filename ) |
---|
| 1068 | { |
---|
| 1069 | warn " Found include for file [$full_filename]\n"; |
---|
| 1070 | &scan_for_includes_($full_filename); |
---|
| 1071 | } |
---|
| 1072 | else |
---|
| 1073 | { |
---|
| 1074 | if ( $orig_filename =~ /^\// ) |
---|
| 1075 | { |
---|
| 1076 | warn "LatexMk: Could not find file [$orig_filename]\n"; |
---|
| 1077 | } |
---|
| 1078 | else |
---|
| 1079 | { |
---|
| 1080 | warn "LatexMk: Could not find file [$orig_filename] in path [$TEXINPUTS]\n"; |
---|
| 1081 | warn " assuming in current directory ($full_filename)\n"; |
---|
| 1082 | } |
---|
| 1083 | } |
---|
| 1084 | } |
---|
| 1085 | else |
---|
| 1086 | { |
---|
| 1087 | if ( ! $force_include_mode ) |
---|
| 1088 | { |
---|
| 1089 | if ( $orig_filename =~ /^\// ) |
---|
| 1090 | { |
---|
| 1091 | die "LatexMk: Could not find file [$orig_filename]\n"; |
---|
| 1092 | } |
---|
| 1093 | else |
---|
| 1094 | { |
---|
| 1095 | die "LatexMk: Could not find file [$orig_filename] in path [$TEXINPUTS]\n"; |
---|
| 1096 | } |
---|
| 1097 | } |
---|
| 1098 | } |
---|
| 1099 | } |
---|
| 1100 | elsif (/\\input[{\s]+([^\001\040\011}]*)[\s}]/) |
---|
| 1101 | { |
---|
| 1102 | $full_filename = $1; |
---|
| 1103 | $orig_filename = $full_filename; |
---|
| 1104 | $full_filename1 = &find_file($full_filename,$TEXINPUTS,'1'); |
---|
| 1105 | |
---|
| 1106 | if (( $full_filename1 eq '' ) || ( ! -e $full_filename1 )) |
---|
| 1107 | { |
---|
| 1108 | $full_filename2 = &find_file("$full_filename.tex",$TEXINPUTS,'1'); |
---|
| 1109 | if (( $full_filename2 ne '' ) && ( -e $full_filename2 )) |
---|
| 1110 | { |
---|
| 1111 | $full_filename = $full_filename2; |
---|
| 1112 | } |
---|
| 1113 | else |
---|
| 1114 | { |
---|
| 1115 | $full_filename = $full_filename1; |
---|
| 1116 | } |
---|
| 1117 | } |
---|
| 1118 | else |
---|
| 1119 | { |
---|
| 1120 | $full_filename = $full_filename1; |
---|
| 1121 | } |
---|
| 1122 | |
---|
| 1123 | if ($full_filename) |
---|
| 1124 | { |
---|
| 1125 | $includes .= "$full_filename "; |
---|
| 1126 | warn "added '$full_filename'\n"; |
---|
| 1127 | if ( -e $full_filename ) |
---|
| 1128 | { |
---|
| 1129 | warn " Found input for file [$full_filename]\n"; |
---|
| 1130 | &scan_for_includes_($full_filename); |
---|
| 1131 | } |
---|
| 1132 | else |
---|
| 1133 | { |
---|
| 1134 | if ( $orig_filename =~ /^\// ) |
---|
| 1135 | { |
---|
| 1136 | warn "LatexMk: Could not find file [$orig_filename]\n"; |
---|
| 1137 | } |
---|
| 1138 | else |
---|
| 1139 | { |
---|
| 1140 | warn "LatexMk: Could not find file [$orig_filename] in path [$TEXINPUTS]\n"; |
---|
| 1141 | warn " assuming in current directory ($full_filename)\n"; |
---|
| 1142 | } |
---|
| 1143 | } |
---|
| 1144 | } |
---|
| 1145 | else |
---|
| 1146 | { |
---|
| 1147 | if ( ! $force_include_mode ) |
---|
| 1148 | { |
---|
| 1149 | if ( $orig_filename =~ /^\// ) |
---|
| 1150 | { |
---|
| 1151 | die "LatexMk: Could not find file [$orig_filename]\n"; |
---|
| 1152 | } |
---|
| 1153 | else |
---|
| 1154 | { |
---|
| 1155 | die "LatexMk: Could not find file [$orig_filename] in path [$TEXINPUTS]\n"; |
---|
| 1156 | } |
---|
| 1157 | } |
---|
| 1158 | } |
---|
| 1159 | } |
---|
| 1160 | elsif (/\\blackandwhite{([^\001\040\011}]*)}/ || /\\colorslides{([^\001}]*)}/) |
---|
| 1161 | { |
---|
| 1162 | $slide_mode = 1; |
---|
| 1163 | $full_filename = $1; |
---|
| 1164 | if ($1 =~ m/\./) |
---|
| 1165 | { |
---|
| 1166 | $full_filename = &find_file($full_filename,$TEXINPUTS); |
---|
| 1167 | } |
---|
| 1168 | else |
---|
| 1169 | { |
---|
| 1170 | $full_filename = &find_file("$full_filename.tex",$TEXINPUTS); |
---|
| 1171 | } |
---|
| 1172 | if ($full_filename) |
---|
| 1173 | { |
---|
| 1174 | $includes .= "$full_filename "; |
---|
| 1175 | if ( -e $full_filename ) |
---|
| 1176 | { |
---|
| 1177 | warn " Found slide input for file [$full_filename]\n"; |
---|
| 1178 | &scan_for_includes_($full_filename); |
---|
| 1179 | } |
---|
| 1180 | } |
---|
| 1181 | } |
---|
| 1182 | elsif (/\\psfig{file=([^,}]+)/ || /\\psfig{figure=([^,}]+)/) |
---|
| 1183 | { |
---|
| 1184 | $full_filename = &find_file($1,$psfigsearchpath); |
---|
| 1185 | if ($full_filename) |
---|
| 1186 | { |
---|
| 1187 | $includes .= "$full_filename "; |
---|
| 1188 | if ( -e $full_filename ) |
---|
| 1189 | { |
---|
| 1190 | warn " Found psfig for file [$full_filename]\n"; |
---|
| 1191 | } |
---|
| 1192 | } |
---|
| 1193 | } |
---|
| 1194 | elsif ( /\\epsfbox{([^}]+)}/ || /\\epsfbox\[[^\]]*\]{([^}]+)}/ || |
---|
| 1195 | /\\epsffile{([^}]+)}/ || /\\epsffile\[[^\]]*\]{([^}]+)}/ || |
---|
| 1196 | /\\epsfig{file=([^,}]+)/ || /\\epsfig{figure=([^,}]+)/ ) |
---|
| 1197 | { |
---|
| 1198 | $full_filename = &find_file($1,$TEXINPUTS); |
---|
| 1199 | if ($full_filename) |
---|
| 1200 | { |
---|
| 1201 | $includes .= "$full_filename "; |
---|
| 1202 | if ( -e $full_filename ) |
---|
| 1203 | { |
---|
| 1204 | warn " Found epsf for file [$full_filename]\n"; |
---|
| 1205 | } |
---|
| 1206 | } |
---|
| 1207 | } |
---|
| 1208 | elsif (/\\documentstyle[^\000]+landscape/) |
---|
| 1209 | { |
---|
| 1210 | warn " Detected landscape mode\n"; |
---|
| 1211 | $landscape_mode = 1; |
---|
| 1212 | } |
---|
| 1213 | elsif (/\\bibliography{([^}]+)}/) |
---|
| 1214 | { |
---|
| 1215 | $bib_files = $1; |
---|
| 1216 | $bib_files =~ tr/,/ /; |
---|
| 1217 | $bib_files = &find_file_list($bib_files,'.bib',$BIBINPUTS); |
---|
| 1218 | warn " Found bibliography files [$bib_files]\n"; |
---|
| 1219 | $bibtex_mode = 1; |
---|
| 1220 | } |
---|
| 1221 | elsif (/\\psfigsearchpath{([^}]+)}/) |
---|
| 1222 | { |
---|
| 1223 | $psfigsearchpath = $1; |
---|
| 1224 | } |
---|
| 1225 | elsif (/\\makeindex/) |
---|
| 1226 | { |
---|
| 1227 | $index_mode = 1; |
---|
| 1228 | warn " Detected index mode\n"; |
---|
| 1229 | } |
---|
| 1230 | } |
---|
| 1231 | } |
---|
| 1232 | |
---|
| 1233 | #************************************************************ |
---|
| 1234 | # given filename and path, return full name of file, or die if none found. |
---|
| 1235 | # when force_include_mode=1, only warn if an include file was not |
---|
| 1236 | # found, and return 0 (PvdS). |
---|
| 1237 | |
---|
| 1238 | sub find_file |
---|
| 1239 | { |
---|
| 1240 | if ( $_[0] =~ /^\// ) |
---|
| 1241 | { |
---|
| 1242 | if ($force_include_mode) |
---|
| 1243 | { |
---|
| 1244 | if ( $_[2] eq '' ) |
---|
| 1245 | { |
---|
| 1246 | warn "LatexMk: Could not find file [$_[0]]\n"; |
---|
| 1247 | } |
---|
| 1248 | return("$_[0]"); |
---|
| 1249 | } |
---|
| 1250 | else |
---|
| 1251 | { |
---|
| 1252 | if (-e $_[0]) |
---|
| 1253 | { |
---|
| 1254 | return("$_[0]"); |
---|
| 1255 | } |
---|
| 1256 | die "LatexMk: Could not find file [$_[0]]\n"; |
---|
| 1257 | } |
---|
| 1258 | } |
---|
| 1259 | foreach $dir (split(':',$_[1])) |
---|
| 1260 | { |
---|
| 1261 | if (-e "$dir/$_[0]") |
---|
| 1262 | { |
---|
| 1263 | return("$dir/$_[0]"); |
---|
| 1264 | } |
---|
| 1265 | } |
---|
| 1266 | if ($force_include_mode) |
---|
| 1267 | { |
---|
| 1268 | if ( $_[2] eq '' ) |
---|
| 1269 | { |
---|
| 1270 | warn "LatexMk: Could not find file [$_[0]] in path [$_[1]]\n"; |
---|
| 1271 | warn " assuming in current directory (./$_[0])\n"; |
---|
| 1272 | } |
---|
| 1273 | return("./$_[0]"); |
---|
| 1274 | } |
---|
| 1275 | else |
---|
| 1276 | { |
---|
| 1277 | if ( $_[2] ne '' ) |
---|
| 1278 | { |
---|
| 1279 | return(''); |
---|
| 1280 | } |
---|
| 1281 | die "LatexMk: Could not find file [$_[0]] in path [$_[1]]\n"; |
---|
| 1282 | } |
---|
| 1283 | } |
---|
| 1284 | |
---|
| 1285 | #************************************************************ |
---|
| 1286 | # given space sep list of filenames, a file suffix, and a path, return list of |
---|
| 1287 | # full names of files, or die w/ warning if not found. |
---|
| 1288 | # When $force_include_mode=1, don't die and don't append the file names (PvdS). |
---|
| 1289 | |
---|
| 1290 | sub find_file_list |
---|
| 1291 | { |
---|
| 1292 | local($tmp_file,$return_list) = ''; |
---|
| 1293 | foreach $file (split(' ',$_[0])) |
---|
| 1294 | { |
---|
| 1295 | $tmp_file = &find_file("$file$_[1]",$_[2]); |
---|
| 1296 | if ($tmp_file) |
---|
| 1297 | { |
---|
| 1298 | $return_list .= $tmp_file . " "; |
---|
| 1299 | } |
---|
| 1300 | } |
---|
| 1301 | $return_list; |
---|
| 1302 | } |
---|
| 1303 | |
---|
| 1304 | #************************************************************ |
---|
| 1305 | sub exit_msg |
---|
| 1306 | { |
---|
| 1307 | warn "\n------------\n"; |
---|
| 1308 | warn "LatexMk: $_[0].\n"; |
---|
| 1309 | warn "-- Use the -f option to force complete processing.\n"; |
---|
| 1310 | if ($_[1]) |
---|
| 1311 | { |
---|
| 1312 | warn "LatexMk: restoring last $root_filename.aux file\n"; |
---|
| 1313 | system("cp -p $root_filename.aux.bak $root_filename.aux > /dev/null 2>&1"); |
---|
| 1314 | } |
---|
| 1315 | exit; |
---|
| 1316 | } |
---|
| 1317 | |
---|
| 1318 | #************************************************************ |
---|
| 1319 | |
---|
| 1320 | sub update_depend_file |
---|
| 1321 | { |
---|
| 1322 | warn "Writing dependency file [$root_filename.dep]\n"; |
---|
| 1323 | $rcfile = ">$root_filename.dep"; |
---|
| 1324 | open(rcfile) || die "LatexMk: Unable to open dependency file [$rcfile] for updating\n"; |
---|
| 1325 | print rcfile '$includes = \'' . "$includes';\n"; |
---|
| 1326 | print rcfile '$bib_files = \'' . "$bib_files';\n"; |
---|
| 1327 | if ($slide_mode) |
---|
| 1328 | { |
---|
| 1329 | print rcfile '$slide_mode = 1;' . "\n"; |
---|
| 1330 | } |
---|
| 1331 | if ($bibtex_mode) |
---|
| 1332 | { |
---|
| 1333 | print rcfile '$bibtex_mode = 1;' . "\n"; |
---|
| 1334 | } |
---|
| 1335 | if ($index_mode) |
---|
| 1336 | { |
---|
| 1337 | print rcfile '$index_mode = 1;' . "\n"; |
---|
| 1338 | } |
---|
| 1339 | close rcfile; |
---|
| 1340 | } |
---|