diff options
author | Karl Berry <karl@freefriends.org> | 2008-10-12 17:18:38 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2008-10-12 17:18:38 +0000 |
commit | 7800349461c795f293e70e58022fcad1055fbf9e (patch) | |
tree | 8f32c357e7beac1b65072f113e95411d04f6eb55 /Master/texmf-dist | |
parent | 6c9096722a86a9bc2f9d78b7b4ec5d2245910d6b (diff) |
latexmk 4.01 (29sep08)
git-svn-id: svn://tug.org/texlive/trunk@10937 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
22 files changed, 10997 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/support/latexmk/CHANGES b/Master/texmf-dist/doc/support/latexmk/CHANGES new file mode 100644 index 00000000000..509b82fe299 --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/CHANGES @@ -0,0 +1,52 @@ +From v. 3.04 to v. 3.07 + Pdf files can be made by any of three methods: pdflatex, from dvi + or from postscript. + Extra command-line options -- see documentation + Improved configuration options -- see documentation + Bug fixes, etc + Improved detection of dependencies + If latexmk exits because of an error with latex, bibtex + or makeindex, then it gives a non-zero exit code. + Under MS-Windows allow wildcards in filenames. + +From v. 3.07 to v. 4.01 + Allow dvips, etc to put files in temporary location then move to + final location. This enables the problem to be avoided that + some viewers look for changes in a file and read a new file + before the writing of it is complete. + Ensure that an error in exectuing an rcfile results in an error + message visible to the user. + OS-specific initialization code now includes section for Mac OS-X. + Make code safe, as far as possible, for filenames containing + spaces. + Change method of detecting out-of-date-ness, etc, to examine all + files for changes. Keep a database (in a file with extension + fdb_latexmk) of the previous state of the files. The aux.bak + and idx.bak files are no longer used. The primary method of + detecting change is from the md5 checksum of a file. This deals + automatically with the vast majority of cases where there is + circular dependence of files, without needing special coding in + latexmk to know which input files to a LaTeX run are generated + from a previous run. + Hence make a much more systematic and general method for treating + dependencies. + Substituteable place holders allowed in command specifications, to + allow very general specification of commands (including multiple + commands, pipelines etc). + Extra option --dependents to list dependent files. + Support for multibib.sty, multind.sty, etc. + Support for index.sty as well as makeidx.sty. + Allow .latexmkrc as file name in project directory (as opposed to + latexmkrc). + Command-line option -e to allow execution of initialization code + from command-line invocation of latexmk. + Routines add_cus_dep, remove_cus_dep and show_cus_dep for + manipulating custom-dependency list. + Ability to specify lines to be ignored in computing md5 checksum of + a file of a particular extension. (An example would be a + comment line in an encapsulated postscript file that contains + the date and time it was created. Such lines may change without + having any consequence on the use of the file.) + Miscellaneous bug fixes, etc. + Improvements in parsing of log file + diff --git a/Master/texmf-dist/doc/support/latexmk/COPYING b/Master/texmf-dist/doc/support/latexmk/COPYING new file mode 100644 index 00000000000..5b6e7c66c27 --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + 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 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/Master/texmf-dist/doc/support/latexmk/INSTALL b/Master/texmf-dist/doc/support/latexmk/INSTALL new file mode 100644 index 00000000000..225e1c6e6b5 --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/INSTALL @@ -0,0 +1,271 @@ + INSTALLING latexmk + ================== + (Version 4.00, 12 March 2008) + + John Collins + Physics Department + Penn State University + 104 Davey Lab, Box 208 + University Park PA 16802 + U.S.A. + + http://www.phys.psu.edu/~collins/ + http://www.phys.psu.edu/~collins/software/latexmk/ + username collins at node phys.psu.edu +(E-mail address obfuscated to avoid being harvested by worms and spammers) + +Latexmk is a "make" tool for building latex documents. It runs latex +and/or pdflatex the appropriate number of times to resolve cross +references, and, if necessary, it also runs makeindex and/or bibtex when +appropriate. Then it can make postscript files, print the result or +preview it, as request. It can also be set to run continuously with a +previewer; the latex program, etc, are rerun whenever one of the source +files is modified. + +It automatically determines file dependencies from either the LaTeX .log +file or the source .tex file. Compared with previous versions, the +current version features: a fully reliable algorithm for deciding how +many times to run latex, greatly improved automatic detection of dependent +files, the ability to generate pdf files using pdflatex, and a continuous +preview mode that actually works. + +Latexmk can be installed and used on UNIX (including LINUX), and MS +Windows (tested under WinXP). It can presumably be used on other +systems with suitable customization. + +On all systems, the prequisites are + +a. A working installation of Perl. (See http://www.cpan.org/ if you + don't have one.) + +b. A working installation of TeX and LaTeX. (See http://www.ctan.org/ if + you don't have one.) + + + +Installing on UNIX/LINUX +======================== + +1. Make sure you have working installations of Perl and TeX/LaTeX. + +2. Put the file latexmk.pl in a directory for executable files. For + example, for a system-wide installation, you could put it in + /usr/local/bin. + +3. Rename this file to latexmk. + +4. Make sure latexmk is executable, e.g., by using chmod suitably. + +5. (Optional) Copy the file latexmk.1 to an appropriate directory for man + pages, e.g., /usr/local/man/man1/. + +6. Check whether the commands used by latexmk for executing latex etc are + correct. Normally the only one you have to worry about is $pscmd. + This runs the command ps and is used in preview_continuous_mode to + determine whether a previewer is already running. The format of the + output of ps is highly system dependent. Latexmk should get it right + under LINUX and Solaris. If latexmk does not get this or another + command correct, put an override in a startup file. + + a. For a system-wide installation, the correction should be in the + system startup file, which is any one of the files + /opt/local/share/latexmk/LatexMk, + /usr/local/share/latexmk/LatexMk, + /usr/local/lib/latexmk/LatexMk. + (You get to choose which.) + + b. If you are installing latexmk as an ordinary user, the startup + file is the user startup file, which is the file .latexmkrc in + your home directory. + + The startup files are written in perl, so possible overrides are like + + $latex = 'unusual_program_to_run_instead_of_normal_latex'; + + for changing the program to run latex, and + + $pscmd = 'ps -aeg'; + $pid_position = 1; + + for the ps command. Here, $pid_position = 1 indicates that the process + ID number is in the first column of the output of the command ps. + +7. If you need any modifications on the commands for running previewers, + like gv, note that prefixing a command by start, as in + + $ps_previewer = 'start gv -watch'; + + ensures that the command is run detached, as is normally appropriate + for a previewer. + + +Installing on MS-Windows +======================== + +(Power users can modify these as appropriate.) + +1. Make sure you have working installations of Perl and TeX/LaTeX, + complete with viewers for dvi and/or postscript files. + +2. If necessary, unpack the distribution. [Note: It is a good idea to + unpack the files so that they have the correct line-end characters for + MS-Windows. For example, if you use unzip on latexmk.zip, the command + unzip -a latexmk.zip should do the job. If you don't do this + conversion, it probably won't matter, since much software, including + perl, MikTeX and emacs, handles MS-Windows and UNIX line ends equally + well.] + +3. Copy the files latexmk.pl and latexmk.bat to a suitable directory + (your choice). One possibility is a directory C:\local\bin. You will + need to make sure this directory in the search path for executable + files --- see the next step. + +4. If the directory in the previous step is NOT already in the search + path for executable files, arrange for this, by adjusting the + environment variable PATH suitably. Suppose the latexmk directory + is C:\local\bin. + + a. In Windows XP, there is an item in the Control Panel to adjust + the environment: normally Control Panel -> Performance and + Maintenance -> System. The pick the tab Advanced and click on + Environment Variables. + + (i) If you are a REGULAR user, examine the User variables. If + there is already an entry for PATH, append a semicolon and + then the name of latexmk's directory (e.g., C:\local\bin). + If not, then make a new variable named PATH with the value + %PATH%;C:\local\bin + + (ii) If you are an administrator, examine the System variables, + and adjust the entry to PATH, as above. + + b. ONLY in Windows 95, 98 and ME: you will need to add a line to + the end of the C:\AUTOEXEC.BAT file. Suppose the directory for + latexmk is named C:\local\bin, then the line you add is + + PATH %PATH%;C:\local\bin + + This change will take effect the next time you reboot. + +5. (Optional) Copy documentation file(s) to a suitable directory. The + only requirement on the directory is your convenience: some convenient + place to look up documentation. The relevant files are latexmk.txt + which is a pure ASCII text file, and latexmk.ps which is a postscript + file. + +6. Check whether perl is in the search path for executables. (E.g., from + the MSDOS command-line prompt, try the command perl --version.) If + perl is not in the search path, then modify the first line of + latexmk.bat (which you installed at step 2) by replacing the command + perl by the full path name for perl, e.g., C:\perl\bin\perl.exe. + +7. You may need to reboot, or at least logoff and log back in, if you + made any changes to the path at step 3. Test out the installation + at the command-line prompt: + + a. First do + + latexmk --version + + This should show you the version number of latexmk. If this works + latexmk is accessible. If not, you will have to figure out what + did not work in the previous steps. + + b. Then change to a directory where you have a good LaTeX file. + Suppose the file is paper.tex. Delete any pre-existing dvi file, + so that latexmk is forced to remake the output files. The + following commands will check out the main features of latexmk: + + latexmk paper + latexmk -pv paper + latexmk -pv -ps paper + + The first command will create the dvi file, running latex a + suitable number of times, and additionally running bibtex and + makeindex, but only if needed. The second command will open a + viewer of the dvi file. The third command will create a postscript + file, and then open a viewer for it. + + c. If the above works, you are done. If not, you will have to figure + out what is wrong, and correct it. FIRST, READ THE DOCUMENTATION! + The normal problems are that the names for the commands used by + latexmk are incorrect for your system, or they are not present on + your system. See the next item for how to customize latexmk. + Also LOOK AT THE SECTION NAMED "TRICKY POINTS" below to see some + hints. + + +8. If the commands used by latexmk are incorrect, see the UNIX + installation instructions for what to do. The only changes needed + from the UNIX instructions are: + + a. The system initialization file is C:\latexmk\LatexMk. + + b. The user initialization file is .latexmkrc in the directory + specified by the environment variable HOME. If there is no HOME + variable, then the file is in the root directory of the current + drive. + + +Other systems +============= + +You are on your own. The instructions for UNIX/LINUX and MS-Windows +should help you to see what to do. Let me know (username collins at +node phys.psu.edu) what happens, so that I can update these +instructions and possibly latexmk as well. + + +Tricky points +============= + +1. BEWARE of filenames with funny extensions, for example, two.part.tex, + with a double extension. The behavior of TeX-related software is not + consistent in this situation. You may, for example, find a log file + named two.log or two.part.log, depending on which version of which + implementation of TeX/LaTeX you use. Naturally, there is a + possibility that latexmk will get confused, and not recognize, for + example, that a dvi file has been generated. Latexmk has some + configuration variables to deal with some of the possibilities, so you + could try playing with them --- see the code. But it general, it is + best to avoid such double extensions: they make your files + non-portable. Do something like two-part.tex or two_part.tex + instead. + +2. The same goes for filenames and directory names with spaces in them. + Much software interprets spaces as separators between different file + names or between filenames and other text. + +3. If you need to remake documentation files, e.g., latexmk.pdf or + latexmk.txt, from the man page file latexmk.1, the following + commands work (on my linux system at least): + + Postscript file from latexmk.1: + + groff -Tps -man-old -rcR=0 latexmk.1 > latexmk.ps + + Pdf file from postscript: + + ps2pdf latexmk.ps latexmk.pdf + + Text file: + + groff -Tascii -man-old -rcR=0 latexmk.1 > latexmk.txt + + + +Credits +======= + +The original version of this program was called 'go', and written by David +Musliner. That version is Copyright 1992 by David J. Musliner and The +University of Michigan. + +Version 2 was modified by Evan McLean. + +The current version is by John Collins (username collins at node +phys.psu.edu) -- other contact details at the top. It is copyright +1998-2008 by John Collins, and the previous authors; see the copyright +notice in the latexmk.pl file, which gives permission to use, copy, +modify, and distribute this software and its documentation under the +terms of the GNU Public License. diff --git a/Master/texmf-dist/doc/support/latexmk/README b/Master/texmf-dist/doc/support/latexmk/README new file mode 100644 index 00000000000..5a77ae7382c --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/README @@ -0,0 +1,172 @@ +Hi, and thanks for checking out latexmk. (Version 4.01, 24 September 2008) + +Latexmk completely automates the process of generating a LaTeX document. +Essentially, it is a highly specialized cousin of the general make +utility. Given the source files for a document, latexmk issues the +appropriate sequence of commands to generate a .dvi, .ps, .pdf or hardcopy +version of the document. It can also be set to run continuously with a +previewer; the latex program, etc, are rerun whenever one of the source +files is modified. + +Latexmk automatically determines file dependencies from either the LaTeX +.log file or the source .tex file. Compared with previous versions, the +current version features: a fully reliable algorithm for deciding how many +times to run latex, greatly improved automatic detection of dependent +files, the ability to generate pdf files using pdflatex, and a continuous +preview mode that actually works. + +Please read the man page (or the corresponding text or postscript file) +for a run down on what latexmk does and what all the features are. A copy +of the fast help that can be seen by doing "latexmk -h" is at the end of +this file. + +The latexmk perl script was modified by Evan McLean from the original +script called "go" written by David J. Musliner. Now it is supported +by + + John Collins + Physics Department + Penn State University + 104 Davey Lab, Box 208 + University Park PA 16802 + U.S.A. + + http://www.phys.psu.edu/~collins/ + username collins at node phys.psu.edu +(E-mail address obfuscated to avoid being harvested by worms and spammers) + +The start of the script file has copyright notices and disclaimers. It +also has a modification history for those who are interested. + +NOTES:- + +1) See the INSTALL file for installation instructions + +2) Portability under various UNIX-type systems (including Linux): + A special hack is used at the beginning of the latexmk script to ensure + that it correctly runs without the need to adjust a #! line. All that + is necessary is that the script has execute permission. + +3) Portability under non-UNIX systems: + Under other operating systems some other arrangement needs to be made + to run the file. For example under MS-Windows, the supplied batch file + latexmk.bat will do this. + + You may also find it necessary to convert files to the correct local + format for text files. As downloaded, the files are in UNIX format + (line-ending is '\n'). On MS-Windows systems, the conversion to MSDOS + format (with line-ending '\r\n') is normally UNnecessary, since much + current software handles the UNIX format correctly. (The known + software for which this statement applies includes MikTeX, fpTeX, + emacs.) + +4) Portability: The various commands to process LaTeX files made need to + be changed for particular installations. See the INSTALL file and the + documentation for information on customization. + +5) Portability: Users of different UNIX-like systems may have to change + the "$pscmd" variable in their RC file if the -pvc option is to work + perfectly. Refer to $pscmd in the man page. + +6) Latexmk can be downloaded from the author's site at + http://www.phys.psu.edu/~collins/software/latexmk/ + This site also includes previous versions, and possibly newer + versions under development. + +7) Latexmk is archived on the CTAN tex archive --- see + http://www.tug.org/ctan.html. By ftp it can be found in + /tex-archive/support/latexmk on the following hosts (as well as on + many other mirror sites): ftp://ftp.dante.de, ftp://ftp.tex.ac.uk, + ftp://ctan.tug.org. + +8) [If for some reason you need to find the obsolete version 2, it can + also be found on CTAN, at /tex-archive/obsolete/support/latexmk/ on + the above hosts.] + + +I hope you find this useful. + +John Collins +---------------------------- "latexmk -h" ---------------------------- +Latexmk 4.01a: Automatic LaTeX document generation routine + +Usage: latexmk [latexmk_options] [filename ...] + + Latexmk_options: + -bm <message> - Print message across the page when converting to postscript + -bi <intensity> - Set contrast or intensity of banner + -bs <scale> - Set scale for banner + -commands - list commands used by latexmk for processing files + -c - clean up (remove) all nonessential files, except + dvi, ps and pdf files. + This and the other clean-ups are instead of a regular make. + -C - clean up (remove) all nonessential files + including aux, dep, dvi, postscript and pdf files + But exclude file of database of file information + -CA - clean up (remove) absolutely ALL nonessential files + including aux, dep, dvi, postscript and pdf files, + and file of database of file information + -CF - Remove file of database of file information before doing + other actions + -cd - Change to directory of source file when processing it + -cd- - Do NOT change to directory of source file when processing it + -dependents - Show list of dependent files after processing + -dependents- - Do not show list of dependent files after processing + -dF <filter> - Filter to apply to dvi file + -dvi - generate dvi + -dvi- - turn off required dvi + -e <code> - Execute specified PERL code + -f - force continued processing past errors + -f- - turn off forced continuing processing past errors + -F - Ignore non-existent files when testing for dependencies + -F- - Turn off -F + -gg - Super go mode: clean out generated files (-CA), and then + process files regardless of file timestamps + -g - process regardless of file timestamps + -g- - Turn off -g + -h - print help + -help - print help + -jobname=STRING - set basename of output file(s) to STRING. + (Like --jobname=STRING on command line for many current + implementations of latex/pdflatex.) + -l - force landscape mode + -l- - turn off -l + -new-viewer - in -pvc mode, always start a new viewer + -new-viewer- - in -pvc mode, start a new viewer only if needed + -nodependents - Do not show list of dependent files after processing + -pdf - generate pdf by pdflatex + -pdfdvi - generate pdf by dvipdf + -pdfps - generate pdf by ps2pdf + -pdf- - turn off pdf + -ps - generate postscript + -ps- - turn off postscript + -pF <filter> - Filter to apply to postscript file + -p - print document after generating postscript. + (Can also .dvi or .pdf files -- see documentation) + -print=dvi - when file is to be printed, print the dvi file + -print=ps - when file is to be printed, print the ps file (default) + -print=pdf - when file is to be printed, print the pdf file + -pv - preview document. (Side effect turn off continuous preview) + -pv- - turn off preview mode + -pvc - preview document and continuously update. (This also turns + on force mode, so errors do not cause latexmk to stop.) + (Side effect: turn off ordinary preview mode.) + -pvc- - turn off -pvc + -r <file> - Read custom RC file + -silent - silence progress messages from called programs + -v - display program version + -verbose - display usual progress messages from called programs + -version - display program version + -view=default - viewer is default (dvi, ps, pdf) + -view=dvi - viewer is for dvi + -view=none - no viewer is used + -view=ps - viewer is for ps + -view=pdf - viewer is for pdf + filename = the root filename of LaTeX document + +-p, -pv and -pvc are mutually exclusive +-h, -c and -C overides all other options. +-pv and -pvc require one and only one filename specified +All options can be introduced by '-' or '--'. (E.g., --help or -help.) +Contents of RC file specified by -r overrides options specified + before the -r option on the command line diff --git a/Master/texmf-dist/doc/support/latexmk/example_rcfiles/README b/Master/texmf-dist/doc/support/latexmk/example_rcfiles/README new file mode 100644 index 00000000000..0fa2d6345da --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/example_rcfiles/README @@ -0,0 +1,14 @@ +The files in this directory provide suggestions for customizing an +initialization file ("rc file") for latexmk. See the latexmk +documentation for general information on its initialization files. + +NOTES: 1. These examples are developed by particular users to solve +particular problems. You may have to customize them for your own +needs. So read the comments carefully, and understand how the +examples are working. + + +2. Another source of examples is in Herb Schulz's distribution of + TexShop, at http://homepage.mac.com/herbs2, for some further + examples. (The file Latexmk321jTeXShop.zip is the one you want.) + It shows how to use glossaries, epstopdf, pdftricks and pst-pdf. diff --git a/Master/texmf-dist/doc/support/latexmk/example_rcfiles/pdflatexmkrc b/Master/texmf-dist/doc/support/latexmk/example_rcfiles/pdflatexmkrc new file mode 100644 index 00000000000..df5dfd5d81e --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/example_rcfiles/pdflatexmkrc @@ -0,0 +1,77 @@ +# Use of glossaries, extra indexes, epstopdf, and other images conversions +# Thanks to Herb Schulz + + +$pdflatex = 'pdflatex --shell-escape %O %S'; + +# Custom dependency for glossary/glossaries package +# if you make custom glossaries you may have to add items to the @cus_dep_list and corresponding sub-routines +add_cus_dep('glo', 'gls', 0, 'makeglo2gls'); + sub makeglo2gls { + system("makeindex -s $_[0].ist -t $_[0].glg -o $_[0].gls $_[0].glo"); + } +# The glossaries package, with the [acronym] option, produces a .acn file when processed with (xe/pdf)latex and +# then makeindex to process the .acn into .acr and finally runs of (xe/pdf)latex to read in the .acr file. Unfortunately +# the glossary package does just the reverse; i.e. (xe/pdf)latex processing produces a .acr files and makeindex then +# is used to convert the .acr file to a .acn file which is then ... . This dependency assumes the glossaries package. +add_cus_dep('acn', 'acr', 0, 'makeacn2acr'); + sub makeacn2acr { + system("makeindex -s $_[0].ist -t $_[0].alg -o $_[0].acr $_[0].acn"); + } +# for glossary package (Sigh...) --- they can co-exist! +add_cus_dep('acr', 'acn', 0, 'makeacr2acn'); + sub makeacr2acn { + system("makeindex -s $_[0].ist -t $_[0].alg -o $_[0].acn $_[0].acr"); + } +# example of an added custom glossary type that is used in some of the glossary/glossaries example files: +# this is for the new glossary type command \newglossary[nlg]{notation}{not}{ntn}{Notation} from the glossaries package +# NOTE: the glossary package uses a very different command: the <in-ext> and <out-ext> +# are reversed in the calling sequence :-( +add_cus_dep('ntn', 'not', 0, 'makentn2not'); + sub makentn2not { + system("makeindex -s $_[0].ist -t $_[0].nlg -o $_[0].not $_[0].ntn"); + } +# for the glossary package (Sigh...) --- they can co-exist! +add_cus_dep('not', 'ntn', 0, 'makenot2ntn'); + sub makenot2ntn { + system("makeindex -s $_[0].ist -t $_[0].nlg -o $_[0].ntn $_[0].not"); + } + +# dependencies for custom indexes using the index package +# examples for sample.tex for index package: + add_cus_dep('adx', 'and', 0, 'makeadx2and'); + sub makeadx2and { + system("makeindex -o $_[0].and $_[0].adx"); + } + add_cus_dep('ndx', 'nnd', 0, 'makendx2nnd'); + sub makendx2nnd { + system("makeindex -o $_[0].nnd $_[0].ndx"); + } + add_cus_dep('ldx', 'lnd', 0, 'makeldx2lnd'); + sub makeldx2lnd { + system("makeindex -o $_[0].lnd $_[0].ldx"); + } + +# Custom dependency and function for nomencl package +add_cus_dep('nlo', 'nls', 0, 'makenlo2nls'); + sub makenlo2nls { + system("makeindex -s nomencl.ist -o $_[0].nls $_[0].nlo"); + } + +# Custom dependency and function(s) for epstopdf package + +# FOR USERS OF epstopf v1.4 and before: should also work with v1.5 and later +# note: you may get extras runs if you use the .eps extension in the \includgraphics command +# deletes an outdated pdf-image, and triggers a pdflatex-run +add_cus_dep('eps', 'pdf', 0, 'cus_dep_delete_dest'); + +# FOR USERS OF epstopdf v1.5 and later only: +# load it as \usepackage[update,prepend]{epstopdf} +# detects an outdated pdf-image, and triggers a pdflatex-run +#add_cus_dep('eps', 'pdf', 0, 'cus_dep_require_primary_run'); + +# Custom dependecy to convert tif to png +add_cus_dep('tif', 'png', 0, 'maketif2png'); + sub maketif2png { + system("convert $_[0].tif $_[0].png"); + } diff --git a/Master/texmf-dist/doc/support/latexmk/extra-scripts/README1 b/Master/texmf-dist/doc/support/latexmk/extra-scripts/README1 new file mode 100644 index 00000000000..aeb5e615e49 --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/extra-scripts/README1 @@ -0,0 +1,140 @@ +Auxiliary scripts for latexmk +============================= + +John Collins (collins at phys.psu.edu) +20 Jan 2007 + +Latexmk can be configured to use different programs than the standard +ones to perform its tasks. If a user finds that the default behavior +is not what is desired, it is frequently possible to use a script +replacing a standard program to acheive the desired effect. It is +also possible to have a script to run some other programs as well as +latexmk to do certain tasks. A certain amount of creativity works +wonders. + +In this directory are some scripts that you may find useful. They +have been provided by other users (who I thank) or by myself. They +were written to perform certain jobs desired by these users, so they +may have some very special features that are not useful to everytone. +You may well need to modify them for your own needs, and you will +probably need to read through them in detail to understand what they +do. They can also be quite operating system specific. + +For all these scripts, the instructions assumes that the script is in +the path for executables, and that you have done whatever your OS +needs you to do to make the script executable. + +1. startacroread + + This is specific for UNIX/LINUX systems (script running under + bash). It solves a problem that when acroread is used as a pdf + viewer and latexmk is used in preview-continuous mode, acroread + does not automatically update its display when the pdf file + changes. + + Prerequisites: + UNIX-style OS + bash (command shell) + acroread + pdfopen and pdfclose from the xpdfopen package + (see http://www.tug.org/tex-archive/support/xpdfopen/) + + To use: + + Put the following lines in a startup file for latexmk + + $pdf_previewer = "start startacrobat"; + $pdf_update_method = "2"; + + This will, of course, only have an effect when latexmk will + have you view pdf files. + + Advantage: + + Use of acroread (under UNIX/LINUX) for viewing pdf files, with + automatic update when latexmk -pvc is used. + + Disadvantage: + + Acroread does not retain its page position; it returns to the + first page. (Both gv and xpdf are better for this.) + + Notes: + + The viewer window disappears and then reappears as the + foreground window. + + This solution cannot be easily adapted under MSWindows, since + the MSWindows version of acroread locks the pdf file, so that a + new version cannot be written. + + Thanks: Thorsten Bonow + + + +2. l1 + + For UNIX/LINUX, possibly cygwin, although I haven't tried. + + It is a replacement for latex that brings up a window there are + errors. It first runs latex to completion (without a stop if + there are errors). Then if there are errors, it makes their + description (from the log file) into a dvi file, which it brings + up in a separate window. + + Advantage: + + Automatic display of log file, in middle of workflow when using + latexmk in preview-continuous mode. + + Disadvantage: + + Log files are verbose. A single line error message in a latex + run is often easier to read. + + Thanks: Tom Schneider + + +3. l2 + + A version of l1 with command-line options for changing its + behavior. + + +4. kickxdvi + + A script for making xdvi update its display. Used by l1. + +5. dvipdfm_call + dvipdfmx_call + dvipdfm_call.bat + dvipdfmx_call.bat + + Scripts for using dvipdfm or dvipdfmx from latexmk. They solve + the problem that when latexmk converts dvi files to pdf, it + assumes that it is using dvipdf. If you reconfigure latexmk to + use dvipdfm or dvipdfmx, the command line arguments are wrong, and + you will get an error message. The scripts dvipdfm_call and + dvipdfmx_call do the appropriate conversion of the command-line + arguments. + + For Unix-like systems, including linux and Mac OS-X, use the + scripts dvipdfm_call and dvipdfmx_call. + For MS-Windows systems use the batch files dvipdfm_call.bat and + dvipdfmx_call.bat. + + To use these scripts: install the scripts/batch files as + appropriate, and configure one of latexmk's initialization files + to use the script you need. The correct configuration will have + one of the lines + + $dvipdf = 'dvipdfm_call'; + or + $dvipdf = 'dvipdfmx_call'; + + Then you will need to set to use the dvipdf method of making pdf + files, either on latexmk's command line, or in a configuration + file with the line + + $pdf_mode = 3; + diff --git a/Master/texmf-dist/doc/support/latexmk/extra-scripts/dvipdfm_call b/Master/texmf-dist/doc/support/latexmk/extra-scripts/dvipdfm_call new file mode 100644 index 00000000000..896dce71fc6 --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/extra-scripts/dvipdfm_call @@ -0,0 +1,14 @@ +#!/bin/sh + +# Run dvipdfm from dvipdf-style command-line +# Assume no options specified +# If this script is called from latexmk, +# we have $1=source.dvi, $2=dest.pdf +# But for safety, let's handle correctly a one argument call, +# i.e., $1=source, with no $2 + +if [ "$2" = "" ]; then + dvipdfm $1 +else + dvipdfm -o $2 $1 +fi diff --git a/Master/texmf-dist/doc/support/latexmk/extra-scripts/dvipdfm_call.bat b/Master/texmf-dist/doc/support/latexmk/extra-scripts/dvipdfm_call.bat new file mode 100755 index 00000000000..a0817015fe6 --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/extra-scripts/dvipdfm_call.bat @@ -0,0 +1,19 @@ +@echo off +REM Run dvipdfm from dvipdf-style command-line +REM Assume no options specified +REM If this script is called from latexmk, +REM we have %1=source.dvi, %2=dest.pdf +REM But for safety, let's handle correctly a one argument call, +REM i.e., %1=source, with no %2 + +if "%2" == "" goto onearg + +:twoarg +dvipdfm -o %2 %1 +goto done + +:onearg +dvipdfm %1 + + +:done
\ No newline at end of file diff --git a/Master/texmf-dist/doc/support/latexmk/extra-scripts/dvipdfmx_call b/Master/texmf-dist/doc/support/latexmk/extra-scripts/dvipdfmx_call new file mode 100644 index 00000000000..9ff04c4bdc2 --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/extra-scripts/dvipdfmx_call @@ -0,0 +1,14 @@ +#!/bin/sh + +# Run dvipdfmx from dvipdf-style command-line +# Assume no options specified +# If this script is called from latexmk, +# we have $1=source.dvi, $2=dest.pdf +# But for safety, let's handle correctly a one argument call, +# i.e., $1=source, with no $2 + +if [ "$2" = "" ]; then + dvipdfmx $1 +else + dvipdfmx -o $2 $1 +fi diff --git a/Master/texmf-dist/doc/support/latexmk/extra-scripts/dvipdfmx_call.bat b/Master/texmf-dist/doc/support/latexmk/extra-scripts/dvipdfmx_call.bat new file mode 100755 index 00000000000..0068de2196d --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/extra-scripts/dvipdfmx_call.bat @@ -0,0 +1,19 @@ +@echo off +REM Run dvipdfmx from dvipdf-style command-line +REM Assume no options specified +REM If this script is called from latexmk, +REM we have %1=source.dvi, %2=dest.pdf +REM But for safety, let's handle correctly a one argument call, +REM i.e., %1=source, with no %2 + +if "%2" == "" goto onearg + +:twoarg +dvipdfmx -o %2 %1 +goto done + +:onearg +dvipdfmx %1 + + +:done
\ No newline at end of file diff --git a/Master/texmf-dist/doc/support/latexmk/extra-scripts/kickxdvi b/Master/texmf-dist/doc/support/latexmk/extra-scripts/kickxdvi new file mode 100644 index 00000000000..f0809637aa2 --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/extra-scripts/kickxdvi @@ -0,0 +1,22 @@ +#!/bin/csh -f +#(ie run the cshell on this but don't read the .cshrc) + +echo version = 1.05 of kickxdvi 2002 Nov 12 +# 2002 Nov 12, 1.05: (John Collins) Simplify +# 2002 Nov 5, 1.04: (John Collins) Simplify +# 2002 Oct 21, 1.04: functional! +# origin 1999Feb15.17:23:04 + +echo refresh xdvi processes: + +# It picks up multiple processes just fine. + +set whoami = `whoami` + +set pid=`ps -f -u $whoami | grep xdvi.bin | grep -v grep | cut -c10-14` +if ( "$pid" != "" ) then + echo pid: $pid + /usr/bin/kill -s USR1 $pid +else + echo No xdvi.bin processes +endif diff --git a/Master/texmf-dist/doc/support/latexmk/extra-scripts/l1 b/Master/texmf-dist/doc/support/latexmk/extra-scripts/l1 new file mode 100644 index 00000000000..cf8d1c4b643 --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/extra-scripts/l1 @@ -0,0 +1,122 @@ +#!/bin/csh -f +#(ie run the cshell on this but don't read the .cshrc) + +clear +echo version = 2.17 of l 2002 Nov 5 +# 2002 Nov 5, 2.17: (John Collins) Make work with latexmk +# 2002 Oct 21, 2.16: replace popcross with kickxdvi +# 2000 Mar 6, 2.14: done is created as a directory (more useful than a file) +# 1999 Nov 18: removal of a paper triggers bibtex call now +# 1999 Aug 19: when done, `touch done` so that other +# programs can be triggered (ie latex2html!) + +set myname=l1 + +if ( "$1" == "") then + set paper=paper +else + set paper=$1 +endif + +if ( "$paper:e" == "" ) then + set base=$paper + set paper=${base}.tex +else + set base=$paper:r +endif + +if !(-f $paper) then + echo $paper does not exist\! + exit 1; +endif + +# popcross refreshes the xdvi display by briefly putting +# a window in front of the xdvi window. This is crude but effective. +# A better way is to use the kickxdvi routine. +set kickxdvi = popcross # old method. +set kickxdvi = kickxdvi + +# set overfull = Overfull +set overfull = NoOverfull +echo ALL $overfull MESSAGES WILL BE SUPPRESSED +# see Lamport page 177 for dealing with overfull boxes. +# basically, do this: +# \documentclass[12pt,draft]{article} +# draft will mark the overfull boxes and the solution +# will become obvious... + +# run latex. The cat /dev/null prevents +# latex from stopping. Errors are reported to paper.log +cat /dev/null | latex $paper | grep -v $overfull + +# determine if there was an error, by looking at paper.log: +grep "! Emergency stop." $base.log +@ EmergencyStop = ($status == 0) +# Also find if no output produced: +# Examine only the last line of the file to pick out only the +# message produced by TeX, and not something else with the same +# string. +tail -1 $base.log | grep "No pages of output." +@ NoOutput = ($status == 0) + +if ($EmergencyStop || $NoOutput)then + + # begin latexerrors %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + echo create and display latex errors + + set err = `whoami`-$base + set tmperr = /tmp/$err.tex + + echo "\documentclass[12pt]{article}" > $tmperr + echo "\textwidth 7.5in" >> $tmperr + echo "\begin{document}" >> $tmperr + if ( $EmergencyStop ) then + echo "Error(s) in tex file ($paper): " >> $tmperr + else if ( $NoOutput ) then + echo "No output from tex file ($paper): " >> $tmperr + endif + echo "\begin{verbatim}" >> $tmperr + + cat $base.log >> $tmperr + + echo "\end{verbatim}" >> $tmperr + echo "\end{document}" >> $tmperr + + pushd /tmp + latex $err.tex + if ( $EmergencyStop ) then + echo xdvi display shows the last page of the errors + set page = '+' + else + set page = '' + endif + xdvi $err.dvi $page & + popd + # end latexerrors %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + cp /tmp/$err.dvi $base.dvi + $kickxdvi + echo "****************************************" + echo "* ERROR IN PAPER - fix paper.tex file\! *" + echo "****************************************" + # beep + echo -n "" + sleep 2 + # beep + echo -n "" + cd /tmp + rm -f $err.aux $err.dvi $err.log $err.tex + + exit 1 +else + echo Successful run + $kickxdvi + if !(-f done || -d done) then + mkdir done + endif + touch done + + exit + +endif diff --git a/Master/texmf-dist/doc/support/latexmk/extra-scripts/l2 b/Master/texmf-dist/doc/support/latexmk/extra-scripts/l2 new file mode 100644 index 00000000000..f179bf36a56 --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/extra-scripts/l2 @@ -0,0 +1,143 @@ +#!/bin/csh -f +#(ie run the cshell on this but don't read the .cshrc) + +# l2: 2002 Nov 12. John Collins. +# l2: 2002 Nov 11. John Collins. +# l2: 2002 Nov 6. John Collins. +# l2: 2002 Nov 5. John Collins. Simplified from l v. 2.17 + +set myname=l2 +set displayErrors = 0 +set mainCwd = $cwd + + +#alias beep '(echo -n ""; sleep 1; echo -n "")' +alias beep '(echo -n "")' + + +nextarg: +if ( "$1" == "-d" ) then + set displayErrors=1 + shift + goto nextarg +endif +if ( "$1" == "-d-" ) then + set displayErrors=0 + shift + goto nextarg +endif + +if ( ("$1" == "") || ("$1" == "-h") || ("$1" == "--help") ) then + echo "Usage $myname [-d|-d-] paper.tex" + echo "" + echo " -d ==> display errors" + echo " -d- ==> do not display errors (default)" + echo " -h, --help ==> show this message" + exit 0 +endif + +set paper=$1 +if ( "$paper:e" == "" ) then + set base=$paper + set paper=${base}.tex +else + set base=$paper:r +endif + +if !(-f $paper) then + echo $paper does not exist\! + exit 1 +endif + +# set overfull = Overfull +set overfull = NoOverfull +echo ALL $overfull MESSAGES WILL BE SUPPRESSED +# see Lamport page 177 for dealing with overfull boxes. +# basically, do this: +# \documentclass[12pt,draft]{article} +# draft will mark the overfull boxes and the solution +# will become obvious... + +# run latex. The cat /dev/null prevents +# latex from stopping. Errors are reported to paper.log +cat /dev/null | latex $paper | grep -v $overfull + +# determine if there was an error, by looking at paper.log: +grep "Emergency stop" $base.log +@ emergencyStop = ($status == 0) + +# Also find if no output produced: +# Examine only the last line of the file to pick out only the +# message produced by TeX, and not something else with the same +# string. +tail -1 $base.log | grep "No pages of output." +@ noOutput = ($status == 0) + +if ($emergencyStop || $noOutput)then + # begin latexerrors %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + echo create and display latex errors + beep& + set err = /tmp/`whoami`-$base:t + set tmperr = $err.tex + + echo "\documentclass[12pt]{article}" > $tmperr + echo "\textwidth 7.5in" >> $tmperr + echo "\begin{document}" >> $tmperr + if ( $emergencyStop ) then + echo "Error(s) in tex file ($paper): " >> $tmperr + else if ( $noOutput ) then + echo "No output from tex file ($paper): " >> $tmperr + endif + echo "\begin{verbatim}" >> $tmperr + + cat $base.log >> $tmperr + + echo "\end{verbatim}" >> $tmperr + echo "\end{document}" >> $tmperr + + # latex puts its generated files in the current directory, rather + # than the directory of the source file. So change to the + # temporary directory, and run latex with the path removed from the + # filename argument: + pushd /tmp + latex $err:t + popd + + # Give the original latex file a valid dvi file containing the error log. + cp $err.dvi $base.dvi + + # Make a dummy aux file. And also make a .aux.bak file. This + # solves the following: + # 1. Sometimes a run with errors results from or has produced + # a bad .aux file. This gets read in on the next run and + # an infinite error loop results unless the .aux file is + # deleted or replaced by something innocuous. + # 2. Latexmk is liable to make extra runs of latex after an + # error is produced. In simple cases, this can be avoided + # if the aux file is later than the tex file and the + # aux.bak file has the same contents. + echo "\relax" > $base.aux + echo "\relax" > $base.aux.bak + + rm -f $err.aux $err.log $err.tex + + if ( $displayErrors) then + # Popup a new window containing the error log + if ( $emergencyStop ) then + echo xdvi display shows the last page of the errors + set page = '+' + else + set page = '' + endif + xdvi $err.dvi $page & + sleep 2 + endif + rm -f $err.dvi + + exit 1 + # end latexerrors %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +else + echo Successful run + exit 0 +endif diff --git a/Master/texmf-dist/doc/support/latexmk/extra-scripts/pst2pdf_for_latexmk b/Master/texmf-dist/doc/support/latexmk/extra-scripts/pst2pdf_for_latexmk new file mode 100644 index 00000000000..8e74f40c6e7 --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/extra-scripts/pst2pdf_for_latexmk @@ -0,0 +1,50 @@ +#! /bin/bash +# pst2pdf_for_latexmk +# PSTricks 2 PDF converter : +# Usage: +# pst2pdf_for_latexmk +# produces PDF files for all files of the form *-fig*.tex +# pst2pdf_for_latexmk <FILE> +# only considers FILE-fig*.tex + +# Modified from pst2pdf distributed with pdftricks.sty to use latexmk + +# IT REQUIRES VERSION 3.21 OR HIGHER OF latexmk +# See http://www.phys.psu.edu/~collins/software/latexmk/versions.html +# The version on CTAN is not yet updated + +# For each pdf file will only be made if the tex source is out-of-date +# This version of pst2pdf does not clean up generated files: they are +# needed by latexmk to determine whether or not the pdf file is +# out-of-date. +# +# To use this automatically with latexmk (linux/UNIX system assumed) +# 1. Install this script (pst2pdf_for_latexmk) somewhere in your PATH +# 2. Put a line like the following in an initialization file for latexmk: +# $pdflatex = 'pdflatex %O %S; pst2pdf_for_latexmk %B'; + +# 1 Oct 2007 John Collins: Remove path from latexmk +# 28 Sep 2007 Herb Schulz processing steprs of figure files changed for no rotation and better BoundingBox +# 27 Sep 2007 John Collins +# 26 Sep 2007 John Collins + +Myname='Pst2pdf_for_latexmk' +myname='pst2pdf_for_latexmk' + +echo "This is $myname modified to use latexmk, by John Collins" + +FILE=$1 +if test -z $FILE; then + FIGURES=`ls *-fig*.tex`; +else + FIGURES=`ls -- $FILE-fig*.tex`; +fi + + +if test -z "$FIGURES"; then + echo $Myname: No files to process +else + echo $Myname: Using latexmk to process: $FIGURES +# latexmk -pdfdvi -ps- -dvi- -e '$dvipdf = q{dvips -E -o %B.eps %S && epstopdf %B.eps --outfile=%D}' $FIGURES + latexmk -pdfdvi -ps- -dvi- -e '$dvipdf = q{dvips -o %B.ps %S ; ps2pdf13 -dAutoRotatePages=/None %B.ps ; pdfcrop %B.pdf ; /bin/mv %B-crop.pdf %D}' $FIGURES +fi diff --git a/Master/texmf-dist/doc/support/latexmk/extra-scripts/pst2pdf_for_latexmk_README.txt b/Master/texmf-dist/doc/support/latexmk/extra-scripts/pst2pdf_for_latexmk_README.txt new file mode 100644 index 00000000000..5ca55862666 --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/extra-scripts/pst2pdf_for_latexmk_README.txt @@ -0,0 +1,13 @@ +Pdftricks implementation for TeXShop. + +The files ``pdftricksmkrc'' and ``pst2pdf_for_latexmk'' (as well as latexmk, etc.) are stored in ~/Library/TeXShop/bin/ + +The file pdftrciskmk.engine is stored in ~/Library/TeXShop/Engines/. + +When instructed to Typeset a the file TeXShop cd's to the tex files directory and calls pdftricksmk.engine passing the file name (with extension). This executes latexmk using the pdftricksmkrc file for initialization. + +The call to pdflatex in the rc file DOES use shell escape (just in case eps files are also being input using epstopdf) so you MUST use the [noshell] option for pdftricks (\usepackage[noshell]{pdftricks}) to avoid a run condition. + +The processing steps I use for the -fig* files differs from that used in the standard pdftricks (and what you used). We've discovered that the original processing sometimes rotates figures and also sometimes produces a BoundingBox that cuts off descenders on letters at the edge of the figure. (I've changed my pdftricks package to use these steps too and have let the authors of that package know.) + +So far it seems to work. I'll get to work on a pst-pdf package example but, now that I'm beginning to understand what is happening with your new extensions to latexmk, I also suspect it should be fairly easy to accomodate that package. I don't see a case where anyone would use both pdftricks and pst-pdf while I do see cases where eps images, included using epstopdf, will be mixed with pstricks type images. diff --git a/Master/texmf-dist/doc/support/latexmk/extra-scripts/startacroread b/Master/texmf-dist/doc/support/latexmk/extra-scripts/startacroread new file mode 100644 index 00000000000..a1e98fce6b6 --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/extra-scripts/startacroread @@ -0,0 +1,231 @@ +#!/bin/bash + +# ------------------------------------------------------------------- +# +# Shell program to start an instance of "acroread" on localhost via +# "pdfopen" and call "pdfopen" again every time when catching the SIGUSR1 +# signal. This provides the same behaviour as "xdvi" for reloading changed +# files. Acrobat Reader doesn't come with a "watch file" option, hence +# this workaround, sigh... +# +# Copyright 2005, Thorsten Bonow +# ( thorsten.bonow at post.rwth-aachen.de ). +# +# 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. +# +# Description: +# +# +# +# Usage: +# +# startacrobat [ -h | --help ] [PDF document] +# +# Options: +# +# -h, --help Display this help message and exit. +# +# Known Bugs: +# +# No other instance of Acrobat Reader should be running: this script kills +# all of them on exit! +# +# Revision History: +# +# 01/05/2005 Initial version, adapted from "startxpdf" +# 28/08/2005 Adapted to "pdfopen" and "acrobat" +# 01/14/2006 Use HUP or USR1 signal for update to be fully +# compatible with latexmk 3.07 and 3.08 +# (modification by John Collins (collins at phys.psu.edu)) +# +# +# ------------------------------------------------------------------- + + +# ------------------------------------------------------------------- +# Constants +# ------------------------------------------------------------------- + + PROGNAME=$(basename $0) + VERSION="0.95A" + ACRO_RELOAD_EXEC="pdfopen --file" + ACROBAT_EXEC="acroread" + +# ------------------------------------------------------------------- +# Functions +# ------------------------------------------------------------------- + + +function clean_up +{ + +# ----------------------------------------------------------------------- +# Function to kill remote instance of acrobat +# No arguments +# ----------------------------------------------------------------------- + + return +} + + +function error_exit +{ + +# ----------------------------------------------------------------------- +# Function for exit due to fatal program error +# Accepts 1 argument: +# string containing descriptive error message +# ----------------------------------------------------------------------- + + + echo "${PROGNAME}: ${1:-"Unknown Error"}" >&2 + clean_up + exit 1 +} + + +function graceful_exit +{ + +# ----------------------------------------------------------------------- +# Function called for a graceful exit +# No arguments +# ----------------------------------------------------------------------- + + clean_up + exit +} + + +function usage +{ + +# ----------------------------------------------------------------------- +# Function to display usage message (does not exit) +# No arguments +# ----------------------------------------------------------------------- + + echo "Usage: ${PROGNAME} [-h | --help] [PDF document]" +} + + +function helptext +{ + +# ----------------------------------------------------------------------- +# Function to display help message for program +# No arguments +# ----------------------------------------------------------------------- + + local tab=$(echo -en "\t\t") + + cat <<- -EOF- + + ${PROGNAME} ver. ${VERSION} + Shell program to start an instance of "acroread" on localhost via + "acro-reload" and call "acro-reload" again every time when catching the + SIGUSR1 signal. This provides the same behaviour as "xdvi" for reloading + changed files. Acrobat Reader doesn't come with a "watch file" option, + hence this workaround, sigh... + + $(usage) + + Options: + + -h, --help Display this help message and exit. + + + + +-EOF- +} + + +function signal_handle +{ + +# ----------------------------------------------------------------------- +# Function to handle signals +# Accepts 1 argument: +# signal_spec +# ----------------------------------------------------------------------- + + case $1 in + INT) echo "$PROGNAME: Program aborted by user" >&2 + clean_up + exit + ;; + TERM) echo "$PROGNAME: Program terminated" >&2 + clean_up + exit + ;; + USR1) echo "$PROGNAME: Reloading..." >&2 + $ACRO_RELOAD_EXEC $PDF_FILE + ;; + *) error_exit "$PROGNAME: Terminating on unknown signal" + ;; + esac +} + + +# ------------------------------------------------------------------- +# Program starts here +# ------------------------------------------------------------------- + + +##### Command Line Processing ##### + +if [ "$1" = "--help" ]; then + helptext + graceful_exit +fi + +while getopts ":h" opt; do + case $opt in + + h ) helptext + graceful_exit ;; + * ) usage + clean_up + exit 1 + esac +done + +PDF_FILE="$1" + +##### Initialization And Setup ##### + +# Trap TERM and INT signals and properly exit + +trap "signal_handle TERM" TERM +trap "signal_handle INT" INT + +# Trap HUP and USR1 signals for reloading the PDF document +# Convert to USR1 +# (Note HUP is used by gv, and USR1 by xdvi, so both signals have precedent) + +trap "signal_handle USR1" HUP USR1 + + +##### Main Logic ##### + +$ACRO_RELOAD_EXEC $PDF_FILE + +while [ 1 ]; + do + # sleeps again after being interrupted by SIGUSR1, breaks if Acrobat Reader is + # killed + sleep 1 + eval pgrep "-f" "$ACROBAT_EXEC" ">/dev/null" || break +done + +graceful_exit + diff --git a/Master/texmf-dist/doc/support/latexmk/latexmk.1 b/Master/texmf-dist/doc/support/latexmk/latexmk.1 new file mode 100644 index 00000000000..aee2530b2c1 --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/latexmk.1 @@ -0,0 +1,1476 @@ +.TH LATEXMK 1L "28 September 2008" "" +.SH NAME +latexmk \- generate LaTeX document +.SH SYNOPSIS +.B latexmk [options] [file ...] +.SH DESCRIPTION +.I Latexmk +completely automates the process of compiling a LaTeX document. +Essentially, it is like a specialized relative of the general +\fImake\fR utility, but one which determines dependencies +automatically and has some other very useful features. In its basic +mode of operation \fIlatexmk\fR is given the name of the primary +source file for a document, and it issues the appropriate sequence of +commands to generate a .dvi, .ps, .pdf and/or hardcopy version of the +document. +.PP +\fILatexmk\fR can also be set to run continuously with a suitable +previewer. In that case the LaTeX program, etc, are rerun whenever +one of the source files is modified, and the previewer automatically +updates the on-screen view of the compiled document. +.PP +\fILatexmk\fR determines which are the source files by examining the +log file. When \fIlatexmk\fR is run, it examines properties of the +source files, and if any have been changed since the last document +generation, \fIlatexmk\fR will run the various LaTeX processing +programs as necessary. In particular, it will repeat the run of LaTeX +(or pdflatex) often enough to resolve all cross references; depending +on the macro packages used. With some macro packages and document +classes, four, or even more, runs may be needed. If necessary, +\fIlatexmk\fR will also run bibtex and/or makeindex. In addition, +\fIlatexmk\fR can be configured to generate other necessary files. +For example, from an updated figure file it can automatically generate +a file in encapsulated postscript or another suitable format for +reading by LaTeX. +.PP +\fILatexmk\fR has two different previewing options. In the simple +\fB-pv\fR option, a dvi, postscript or pdf previewer is automatically +run after generating the dvi, postscript or pdf version of the +document. The type of file to view is selected according to +configuration settings and command line options. +.PP +The second previewing option is the powerful \fB-pvc\fR option +(mnemonic: "preview continuously"). In this case, \fIlatexmk\fR runs +continuously, regularly monitoring all the source files to see if any +have changed. Every time a change is detected, \fIlatexmk\fR runs all +the programs necessary to generate a new version of the document. A +good previewer (like \fIgv\fR) will then automatically update its +display. Thus the user can simply edit a file and, when the changes +are written to disk, \fIlatexmk\fR completely automates the cycle of +updating the .dvi (and possibly the .ps and .pdf) file, and refreshing +the previewer's display. It's not quite WYSIWYG, but usefully close. +.PP +For other previewers, the user may have to manually make the previewer +update its display, which can be (some versions of xdvi and gsview) as +simple as forcing a redraw of its display. +.PP +\fILatexmk\fR has the ability to print a banner in gray diagonally +across each page when making the postscript file. It can also, if +needed, call an external program to do other postprocessing on the +generated files. +.PP +\fILatexmk\fR is highly configurable, both from the command line and +in configuration files, so that it can accommodate a wide variety of +user needs and system configurations. Default values are set +according to the operating system, so \fIlatexmk\fR often works +without special configuration on MS-Windows, cygwin, Linux, OS-X, and +other UNIX systems (notably Solaris). +.PP +A very annoying complication handled very reliably by \fILatexmk\fR, +is that LaTeX is a multiple pass system. On each run, LaTeX reads in +information generated on a previous run, for things like cross +referencing and indexing. In the simplest cases, a second run of +LaTeX suffices, and often the log file contains a message about the +need for another pass. However, there is a wide variety of add-on +macro packages to LaTeX, with a variety of behaviors. The result is +to break simple-minded determinations of how many runs are needed and +of which programs. In its new version, \fIlatexmk\fR has a highly +general and efficient solution to these issues. The solution involves +retaining between runs information on the source files, and a symptom +is that \fIlatexmk\fR generates an extra file (with extension +\fR.fdb_latexmk\fR, by default) that contains the source file +information. + +.SH LATEXMK OPTIONS AND ARGUMENTS ON COMMAND LINE +(All options can be introduced by single or double "-" characters, +e.g., "latexmk -help" or "latexmk --help".) +.TP +.B file +One or more files can be specified. If no files are specified, +\fIlatexmk\fR will, by default, run on all files in the current working directory +with a ".tex" extension. This behavior can be changed: see the +description concerning the \fI@default_files\fR variable in the +section "List of configuration variables usable in initialization +files". +.PP +If a file is specified without an extension, then the ".tex" extension +is automatically added, just as LaTeX does. Thus, if you specify: + + latexmk foo + +then \fIlatexmk\fR will operate on the file "foo.tex". +.TP +.B -bm <message> +A banner message to print diagonally across each page when converting +the dvi file to postscript. The message must be a single argument on +the command line so be careful with quoting spaces and such. + +Note that if the \fB-bm\fR option is specified, the \fB-ps\fR option is +assumed. +.TP +.B -bi <intensity> +How dark to print the banner message. A decimal number between 0 and 1. +0 is black and 1 is white. The default is 0.95, which is OK unless your +toner cartridge is getting low. +.TP +.B -bs <scale> +A decimal number that specifies how large the banner message will be +printed. Experimentation is necessary to get the right scale for your +message, as a rule of thumb the scale should be about equal to 1100 +divided by the number of characters in the message. The default is 220.0 +which is just right for 5 character messages. +.TP +.B -commands +List the commands used by \fIlatexmk\fR for processing files, and then +exit. +.TP +.B -c +Clean up (remove) all regeneratable files generated by \fIlatex\fR and +\fIbibtex\fR except dvi, postscript and pdf. These files are a +combination of log files, aux files, and those with extensions +specified in the \fI@generated_exts\fR configuration variable. In addition, +files with extensions by the \fI$clean_ext\fR configuration variable are +removed. But the file containing a database of source file +information is not removed. + +This cleanup is instead of a regular make. See the \fB-gg\fR option +if you want to do a cleanup then a make. +.TP +.B -C +Clean up (remove) all regeneratable files generated by \fIlatex\fR and +\fIbibtex\fR. This is the same as the \fB-c\fR option with the +addition of dvi, postscript and pdf files, and those with extensions +in the \fI$clean_full_ext\fR configuration variable. + +This cleanup is instead of a regular make. See the \fB-gg\fR option +if you want to do a cleanup than a make. +.TP +.B -CA +Clean up (remove) absolutely all regeneratable files. This is the +action specified by \fB-C\fR with the addition of deleting the file +containing the database of source file information. + +This cleanup is instead of a regular make. It is the same as \fB-C +-CF\fR. See the \fB-gg\fR option if you want to do a cleanup then a +make. +.TP +.B -CF +Remove the file containing the database of source file information, +before doing the other actions requested. +.TP +.B -d +Set draft mode. This prints the banner message "DRAFT" across your +page when converting the dvi file to postscript. Size and intensity +can be modified with the \fB-bs\fR and \fB-bi\fR options. The \fB-bm\fR +option will override this option as this is really just a short way of +specifying: + + latexmk -bm DRAFT + +Note that if the \fB-d\fR option is specified, the \fB-ps\fR option is +assumed. +.TP +.B -dF +Dvi file filtering. The argument to this option is a filter which will +generate a filtered dvi file with the extension ".dviF". All extra +processing (e.g. conversion to postscript, preview, printing) will then +be performed on this filtered dvi file. + +Example usage: To use dviselect to select only the even pages of the dvi file: + + latexmk -dF 'dviselect even' foo.tex +.TP +.B -diagnostics +Print detailed diagnostics during a run. This may help for debugging +problems or to understand \fI.latexmk\fR's behavior in difficult +situations. +.TP +.B -dvi +Generate dvi version of document. +.TP +.B -dvi- +Turn off generation of dvi version of document. (This may get +overridden, if some other file is made (e.g., a .ps file) that is +generated from the dvi file, or if no generated file at all is +requested.) +.TP +.B -e <code> +Execute the specified initialization code before processing. The code +is \fIPerl\fR code of the same form as is used in \fIlatexmk\fR's +initialization files -- for more details, see the information on the +\fB-r\fR option, and the section about "Configuration/initialization +(RC) files". The code is typically a sequence of assignment +statements separated by semicolons. + +The code is executed when the \fB-e\fR option is encountered during +\fIlatexmk\fR's parsing of its command line. See the \fB-r\fR option +for a way of executing initialization code from a file. An error +results in \fIlatexmk\fR stopping. Multiple instances of the \fB-r\fR +and \fB-e\fR options can be used, and they are executed in the order +they appear on the command line. + +Some care is needed to deal with proper quoting of special characters +in the code on the command line. For example, suppose it is desired +to set the latex command to use its -shell-escape option, then under +UNIX/LINUX you could use the line + + latexmk -e '$latex=q/latex %O -shell-escape %S/' file.tex + +(Note that the q/.../ construct is a \fIPerl\fR idiom equivalent to using +single quotes. This is easier than arranging to get a quote character +correctly escaped in a way that is independent of the shell and the +operating-system.) +.TP +.B -f +Force \fIlatexmk\fR to continue document processing despite errors. +Normally, when \fIlatexmk\fR detects that LaTeX or another program has +found an error which will not be resolved by further processing, no +further processing is carried out. +.TP +.B -f- +Turn off the forced processing-past-errors such as is set by the +\fB-f\fR option. This could be used to override a setting in a +configuration file. +.TP +.B -g +Force \fIlatexmk\fR to process document fully, even under situations +where \fIlatexmk\fR would normally decide that no changes in the +source files have occurred since the previous run. +This option is useful, for example, if you change some options and +wish to reprocess the files. +.TP +.B -g- +Turn off \fB-g\fR. +.TP +.B -gg +"Super go mode" or "clean make": clean out generated files as if +\fB-CA\fR had been given, and then do a regular make. +.TP +.B -h, -help +Print help information. +.TP +.B -l +Run in landscape mode, using the landscape mode for the previewers and +the dvi to postscript converters. This option is not normally needed +nowadays, since current previewers normally determine this information +automatically. +.TP +.B -l- +Turn off \fB-l\fR. +.TP +.B -new-viewer +When in continuous-preview mode, always start a new viewer to view the +generated file. By default, \fIlatexmk\fR will, in continuous-preview +mode, test for a previously running previewer for the same file and +not start a new one if a previous previewer is running. However, its +test sometimes fails (notably if there is an already-running previewer +that is viewing a file of the same name as the current file, but in a +different directory). This option turns off the default behavior. +.TP +.B -new-viewer- +The inverse of the \fB-new-viewer\fR option. It puts \fIlatexmk\fR +in its normal behavior that in preview-continuous mode it checks for +an already-running previewer. +.TP +.B -p +Print out the document. By default it is +the generated postscript file that is printed. But you can use the +\fB-print=...\fR option to print the dvi or pdf files instead, and you +can configure this in a start up file (by setting the +\fI$print_type\fR variable). + +However, printing is enabled by default only under UNIX/LINUX systems, +where the default is to use the lpr command. In general, the correct +behavior for printing very much depends on your system's software. In +particular, under MS-Windows you must have suitable program(s) +available, and you must have configured the print commands used by +\fIlatexmk\fR. This can be non-trivial. See the documentation on the +\fI$lpr\fR, \fI$lpr_dvi\fR, and \fI$lpr_pdf\fR configuration variables +to see how to set the commands for printing. + +This option is incompatible with the \fB-pv\fR and \fB-pvc\fR options, +so it turns them off. +.TP +.B -pdf +Generate pdf version of document using pdflatex. +.TP +.B -pdfdvi +Generate pdf version of document from the dvi file, by default using dvipdf. +.TP +.B -pdfps +Generate pdf version of document from the ps file, by default using +ps2pdf. +.TP +.B -pdf- +Turn off generation of pdf version of document. +(This can be used to override a setting in a configuration file. +It may get overridden if some other option requires the generation of +a pdf file.) +.TP +.B -print=dvi, -print=ps, -print=pdf +Define which kind of file is printed. This option also ensures that +the requisite file is made, and turns on printing. The default is to +print a postscript file. +.TP +.B -ps +Generate postscript version of document. +.TP +.B -ps- +Turn off generation of postscript version of document. +This can be used to override a setting in a configuration file. +(It may get overridden by some other option that requires a postscript +file, for example a request for printing.) +.TP +.B -pF +Postscript file filtering. The argument to this option is a filter +which will generate a filtered postscript file with the extension +".psF". All extra processing (e.g. preview, printing) will then be +performed on this filtered postscript file. + +Example of usage: Use psnup to print two pages on the one page: + + latexmk -ps -pF 'psnup -2' foo.tex + +or + + latexmk -ps -pF "psnup -2" foo.tex + +Whether to use single or double quotes round the "psnup -2" will +depend on your command interpreter, as used by the particular version +of perl and the operating system on your computer. +.TP +.B -pv +Run file previewer. If the \fB-view\fR option is used, this will select +the kind of file to be previewed (dvi, ps or pdf). +Otherwise the viewer views the "highest" kind of file selected, by the +\fB-dvi\fR, \fB-ps\fR, \fB-pdf\fR, \fB-pdfps\fR options, in the +order dvi, ps, pdf (low to high). +If no file type has been selected, the dvi previewer will be used. +This option is incompatible with the \fB-p\fR and \fB-pvc\fR options, +so it turns them off. +.TP +.B -pv- +Turn off \fB-pv\fR. +.TP +.B -pvc +Run a file previewer and continually update the .dvi, .ps, and/or .pdf +files whenever changes are made to source files (see the Description +above). Which of these files is generated and which is viewed is +governed by the other options, and is the same as for the \fB-pv\fR +option. +The preview-continuous option \fB-pvc\fR can only work with one file. +So in this case you will normally only specify one filename on +the command line. It is also incompatible with the +\fB-p\fR and \fB-pv\fR options, so it turns these options off + +With a good previewer the display will be automatically updated. +(Under \fIsome but not all\fR versions of UNIX/Linux "gv -watch" does +this for postscript files; this can be set by a configuration +variable. This would also work for pdf files except for an apparent +bug in gv that causes an error when the newly updated pdf file is +read.) Many other previewers will need a manual update. + +Important note: the acroread program on MS-Windows locks the pdf file, +and prevents new versions being written, so it is a bad idea to use +acroread to view pdf files in preview-continuous mode. It is better +to use a dvi or ps viewer, as set by one of the \fB-view=dvi\fR and +\fB-view=ps\fR options. + +There are some other methods for arranging an update, notably useful +for many versions of xdvi and xpdf. These are best set in +\fIlatexmk\fR's configuration; see below. + +Note that if \fIlatexmk\fR dies or is stopped by the user, the +"forked" previewer will continue to run. Successive invocations with +the \fB-pvc\fR option will not fork new previewers, but \fIlatexmk\fR +will normally use the existing previewer. (At least this will happen +when \fIlatexmk\fR is running under an operating system where it knows +how to determine whether an existing previewer is running.) +.TP +.B -pvc- +Turn off \fB-pvc\fR. +.TP +.B -quiet +Same as -silent +.TP +.B -r <rcfile> +Read the specified initialization file ("RC file") before processing. + +Be careful about the ordering: (1) Standard initialization files -- +see the section below on "Configuration/initialization (RC) files" -- +are read first. (2) Then the options on the command line are acted on +in the order they are given. Therefore if an initialization file is +specified by the \fB-r\fR option, it is read during this second step. +Thus an initialization file specified with the \fB-r\fR option can +override both the standard initialization files and \fIpreviously\fR +specified options. But all of these can be overridden by \fIlater\fR +options. + +The contents of the RC file just comprise a piece of code in the +\fIPerl\fR programming language +(typically a sequence of assignment statements); they are executed +when the \fB-r\fR option is encountered during \fIlatexmk\fR's parsing +of its command line. See the \fB-e\fR option for a way of giving +initialization code directly on \fIlatexmk\fR's command line. An +error results in \fIlatexmk\fR stopping. Multiple instances of the +\fB-r\fR and \fB-e\fR options can be used, and they are executed in +the order they appear on the command line. +.TP +.B -silent +Run commands silently, i.e., with options that reduce the amount of +diagnostics generated. For example, with the default settings for +commands under UNIX, the command "latex -interaction=batchmode" is used +for latex. + +Also reduce the number of informational messages that \fIlatexmk\fR +generates. +.TP +.B -v, -version +Print version number of \fIlatexmk\fR. +.TP +.B -verbose +Opposite of \fB-silent\fR. This is the default setting. +.TP +.B -view=default, -view=dvi, -view=ps, -view=pdf +Set the kind of file used when previewing is requested (e.g., by the +\fB-pv\fR or \fB-pvc\fR switches). The default is to view the "highest" +kind of requested file (in the order dvi, ps, pdf). +.PP +The preview-continuous option \fB-pvc\fR can only work with one file. +So in this case you will normally only specify one filename on +the command line. +.PP +Options \fB-p\fR, \fB-pv\fR and \fB-pvc\fR are mutually exclusive. So +each of these options turns the others off. + +.SH EXAMPLES +.nf +.ta 2i +% \fBlatexmk thesis\fR \fI# run latex enough times to resolve + cross-references\fR + +% \fBlatexmk -pvc -ps thesis\fR \fI# run latex enough times to resolve + cross-references, make a postscript + file, start a previewer. Then + watch for changes in the source + file thesis.tex and any files it + uses. After any changes rerun latex + the appropriate number of times and + remake the postscript file. If latex + encounters an error, latexmk will + keep running, watching for + source file changes. + +% \fBlatexmk -c\fR \fI# remove .aux, .log, .bbl, .blg, .dvi, + .pdf, .ps & .bbl files\fR + + +.SH CONFIGURATION/INITIALIZATION (RC) FILES +.PP +\fILatexmk\fR can be customized using initialization files, which are +read at startup in the following order: +.PP +1) The system RC file, if it exists. + On a UNIX system, \fIlatexmk\fR searches for following places for its +system RC file, in the following order, and reads the first it finds: + "/opt/local/share/latexmk/LatexMk", + "/usr/local/share/latexmk/LatexMk", + "/usr/local/lib/latexmk/LatexMk". + On a MS-WINDOWS system it looks for "C:\\latexmk\\LatexMk". +.PP +2) The user's RC file, "$HOME/.latexmkrc", if it exists. Here $HOME +is the value of the environment variable HOME. On UNIX and clones +(including LINUX), this variable is set by the system; on MS-Windows, +the user may choose to set it. +.PP +3) The RC file in the current working directory. This file can be +named either "latexmkrc" or ".latexmkrc", and the first of these to be +found is used, if any. +.PP +4) Any RC file(s) specified on the command line with the \fB-r\fR option. +.PP +Each RC file is a sequence of \fIPerl\fR commands. Naturally, a user can use +this in creative ways. But for most purposes, one simply uses a +sequence of assignment statements that override some of the built-in +settings of \fILatexmk\fR. Straightforward cases can be handled +without knowledge of the \fIPerl\fR language by using the examples in this +document as templates. Comment lines are introduced by the "#" +character. + +Note that command line options are obeyed in the order in which +they are written; thus any RC file specified on the command line with +the \fB-r\fR option can override previous options but can be itself +overridden by later options on the command line. There is also the +\fB-e\fR option, which allows initialization code to be specified in +\fIlatexmk\fR's command line. + +.SH HOW TO SET VARIABLES IN INITIALIZATION FILES +.PP +The important variables that can be configured are described in the +section "List of configuration variables usable in initialization +files". Syntax for setting these variables is of the following forms: +.PP + $bibtex = 'bibtex %O %B'; +.PP +for the setting of a string variable, +.PP + $preview_mode = 1; +.PP +for the setting of a numeric variable, and +.PP + @default_files = ('paper', 'paper1'); +.PP +for the setting of an array of strings. It is possible to append an +item to an array variable as follows: + + push @default_files, 'paper2'; + +Note that simple "scalar" variables have names that begin with a $ +character and array variables have names that begin with a @ +character. Each statement ends with a semicolon. + +You can do much more complicated things, but for this you will need to +consult a manual for the \fIPerl\fR programming language. + + + +.SH FORMAT OF COMMAND SPECIFICATIONS + +Some of the variables set the commands that \fIlatexmk\fR uses for +carrying out its work, for example to generate a dvi file from a tex +file or to view a postscript file. This section describes some +important features of how the commands are specified. + +\fBPlaceholders\fR: Supposed you wanted \fIlatexmk\fR to use the +command elatex in place of the regular latex command, and suppose +moreover that you wanted to give it the option "--shell-escape". You +could do this by the following setting: +.PP + $latex = 'elatex --shell-escape %O %S'; +.PP +The two items starting with the % character are placeholders. These +are substituted by appropriate values before the command is run. Thus +%S will be replaced by the source file that elatex will be applied to, +and %O will be replaced by any options that \fIlatexmk\fR has decided +to use for this command. (E.g., if you used the -silent option it +would replace %O by "-interaction=batchmode".) + +The available placeholders are: +.TP +.B %B +base of filename for current command. E.g., if a postscript file +document.ps is being made from the dvi file document.dvi, then the +basename is document. +.TP +.B %D +destination file (e.g., the name of the postscript file when +converting a dvi file to postscript). +.TP +.B %O +options +.TP +.B %R +root filename. This is the base name for the main tex file. +.TP +.B %S +source file (e.g., the name of the dvi file when converting a dvi file +to ps). +.TP +.B %T +The name of the primary tex file. +.PP +The distinction between %B and %R needs a bit of care, since they are +often the same, but not always. For example on a simple document, the +basename of a bibtex run is the same as for the texfile. But in a +document with several bibliographies, the bibliography files will have +a variety of names. Since bibtex is invoked with the basename of the +bibliography file, the setting for the bibtex command should therefore +be +.PP + $bibtex = 'bibtex %O %B'; +.PP +Generally, you should use %B rather than %R. Similarly for most +purposes, the name %T of the primary texfile is not a useful +placeholder. + +See the default values in the section "List of configuration variables +usable in initialization files" for what is normally the most +appropriate usage. + +If you omit to supply any placeholders whatever in the specification +of a command, \fIlatexmk\fR will supply what its author thinks are +appropriate defaults. This gives compatibility with configuration +files for previous versions of \fIlatexmk\fR, which didn't use +placeholders. + +\fB"Detaching" a command\fR: Normally when \fIlatexmk\fR runs a +command, it waits for the command to run to completion. This is +appropriate for commands like latex, of course. But for previewers, +the command should normally run detached, so that \fIlatexmk\fR gets +the previewer running and then returns to its next task (or exits if +there is nothing else to do). To achieve this effect of detaching a +command, you need to precede the command name with "start ", as in +.PP + $dvi_previewer = 'start xdvi %O %S'; +.PP +This will be translated to whatever is appropriate for your operating +system. + +Notes: (1) In some circumstances, \fIlatex\fR will always run a +command detached. This is the case for a previewer in preview +continuous mode, since otherwise previewing continuously makes no +sense. (2) This precludes the possibility of running a command named +start. (3) If the word start occurs more than once at the beginning +of the command string, that is equivalent to having just one. (4) +Under cygwin, some complications happen, since cygwin amounts to a +complicated merging of UNIX and MS-Windows. See the source code for +how I've handled the problem. + +\fBCommand names containing spaces\fR: Under MS-Windows it is common +that the name of a command includes spaces, since software is often +installed in a subdirectory of "C:\Program Files". Such command names +should be enclosed in double quotes, as in +.PP + $lpr_pdf = '"c:/Program Files/Ghostgum/gsview/gsview32.exe" /p %S'; +.PP +\fBUsing MS-Windows file associations\fR: A useful trick under modern +versions of MS-Windows (e.g., WinXP) is to use just the command +'start' by itself: +.PP + $dvi_previewer = 'start %S'; +.PP +Under recent versions of MS-Windows, this will cause to be run +whatever program the system has associated with dvi files. (The same +applies for a postscript viewer and a pdf viewer.) + +\fBNot using a certain command\fR: If a command is not to be run, the +command name NONE is used, as in +.PP + $lpr = 'NONE lpr'; +.PP +This typically is used when an appropriate command does not exist on +your system. The string after the "NONE" is effectively a comment. + +\fBOptions to commands\fR: +Setting the name of a command can be used not only for changing the +name of the command called, but also to add options to command. +Suppose you want \fIlatexmk\fR to use latex with source specials +enabled. Then you might use the following line in an initialization +file: +.PP + $latex = 'latex --src-specials %O %S'; +.PP + +\fBAdvanced tricks\fR: Normally one specifies a single command for the +commands invoked by \fIlatexmk\fR. Naturally, if there is some +complicated additional processing you need to do in your special +situation, you can write a script (or batch file) to do the +processing, and then configure \fIlatexmk\fR to use your script in +place of the standard program. + +It is also possible to configure \fIlatexmk\fR to run multiple +commands. For example, if when running pdflatex to generate a pdf +file from a tex file you need to run another program after pdflatex to +perform some extra processing, you could do something like: + + $pdflatex = 'pdflatex --shell-escape %O %S; pst2pdf_for_latexmk %B'; + +This definition assumes you are using a UNIX-like system, so that the +two commands to be run are separated by the semicolon in the middle of +the string. + + +.SH LIST OF CONFIGURATION VARIABLES USABLE IN INITIALIZATION FILES +.PP +Default values are indicated in brackets. +.TP +.B $banner [0] +If nonzero, the banner message is printed across each page when +converting the dvi file to postscript. Without modifying the variable +\fI$banner_message\fR, this is equivalent to specifying the \fB-d\fR +option. + +Note that if \fB$banner\fR is nonzero, the \fB$postscript_mode\fR is +assumed and the postscript file is always generated, even if it is newer +than the dvi file. +.TP +.B $banner_intensity [0.95] +Equivalent to the \fB-bi\fR option, this is a decimal number between 0 +and 1 that specifies how dark to print the banner message. 0 is black, +1 is white. The default is just right if your toner cartridge isn't +running too low. +.TP +.B $banner_message ["DRAFT"] +The banner message to print across each page when converting the dvi +file to postscript. This is equivalent to the \fB-bm\fR option. +.TP +.B $banner_scale [220.0] +A decimal number that specifies how large the banner message will be +printed. Experimentation is necessary to get the right scale for your +message, as a rule of thumb the scale should be about equal to 1100 +divided by the number of characters in the message. The Default is +just right for 5 character messages. This is equivalent to the +\fB-bs\fR option. +.TP +.B @BIBINPUTS +This is an array variable, now mostly obsolete, that specifies +directories where +\fIlatexmk\fR should look for .bib files. By default it is set from +the BIBINPUTS environment variable of the operating system. If that +environment variable is not set, a single element list consisting of +the current directory is set. The format of the directory names +depends on your operating system, of course. Examples for setting +this variable are: + + @BIBINPUTS = ( ".", "C:\\bibfiles" ); + @BIBINPUTS = ( ".", "\\\\server\\bibfiles" ); + @BIBINPUTS = ( ".", "C:/bibfiles" ); + @BIBINPUTS = ( ".", "//server/bibfiles" ); + @BIBINPUTS = ( ".", "/usr/local/texmf/bibtex/bib" ); + +Note that under MS Windows, either a forward slash "/" or a backward +slash "\(rs" can be used to separate pathname components, so the first +two and the second two examples are equivalent. Each backward slash +should be doubled to avoid running afoul of \fIPerl\fR's rules for writing +strings. +.PP +\fIImportant note:\fR This variable is now mostly obsolete in the +current version of \fIlatexmk\fR, +since it has a better method of searching for files using the +kpsewhich command. However, if your system is an unusual one without +the kpsewhich command, you may need to set the variable \fI@BIBINPUTS\fR. +.TP +.B $bibtex ["bibtex %O %S"] +The BibTeX processing program. +.TP +.B $bibtex_silent_switch ["-terse"] +\fBSwitch(es)\fR for the BibTeX processing program when silent mode is on. +.TP +.B $cleanup_mode [0] +If nonzero, specifies cleanup mode: 1 for full cleanup, 2 for cleanup +except for dvi, ps and pdf files, 3 for cleanup except for dep and aux +files. (There is also extra cleaning as specified by the +\fI$clean_ext\fR, \fI$clean_full_ext\fR and \fI@generated_exts\fR +variables.) +.PP +This variable is equivalent to specifying one of +the \fB-c\fR, \fB-c1\fR, or \fB-C\fR options. But there should be no need +to set this variable from an RC file. +.TP +.B $clean_ext [""] +Extra extensions of files for \fIlatexmk\fR to remove when any of the +clean-up options (\fB-c\fR, \fB-c1\fR, or \fB-C\fR) is selected. +The value of this variable is a string containing the extensions +separated by spaces. +.TP +.B $clean_full_ext [""] +Extra extensions of files for \fIlatexmk\fR to remove when the \fB-C\fR +option is selected, i.e., extensions of files to remove when the .dvi, +etc files are to be cleaned-up. +.TP +.B @cus_dep_list [()] +Custom dependency list -- see section on "Custom Dependencies". +.TP +.B @default_files [("*.tex")] +Default list of files to be processed. + +Normally, if no filenames are specified on the command line, +\fIlatexmk\fR processes all tex files specified in the \fI@default_files\fR +variable, which by default is set to all tex files ("*.tex") in the +current directory. This is a convenience: just run \fIlatexmk\fR and +it will process an appropriate set of files. But sometimes you want +only some of these files to be processed. In this case you set the +\fI@default_files\fR in an initialization file +(e.g., the file "latexmkrc" in the current directory). Then if no +files are specified on the command line then the files you specify by +setting \fI@default_files\fR are processed. + +Three examples: + + @default_files = ("paper_current"); + + @default_files = ("paper1", "paper2.tex"); + + @default_files = ("*.tex", "*.dtx"); + +Note that more than file may be given, and that the default extension +is ".tex". Wild cards are allowed. The parentheses are because +\fI@default_files\fR is an array variable, i.e., a sequence of +filename specifications is possible. +.TP +.B $dvi_filter [empty] +The dvi file filter to be run on the newly produced dvi file before +other processing. Equivalent to specifying the \fB-dF\fR option. +.TP +.B $dvi_mode [0] +If nonzero, generate a dvi version of the document. +Equivalent to the \fB-dvi\fR option. +.TP +.B $dvi_previewer ["start xdvi %O %S" under UNIX] +The command to invoke a dvi-previewer. +[Default is "start" under MS-WINDOWS; under more recent versions of +Windows, this will cause to be run whatever command the system has +associated with .dvi files.] +.TP +.B $dvi_previewer_landscape ["start xdvi %O %S"] +The command to invoke a dvi-previewer in landscape mode. +[Default is "start" under MS-WINDOWS; under more recent versions of +Windows, this will cause to be run whatever command the system has +associated with .dvi files.] +.TP +.B $dvipdf ["dvipdf %O %S %D"] +Command to convert dvi to pdf file. A common reconfiguration is to +use the dvipdfm command, which needs its arguments in a different order: + + $dvipdf = "dvipdfm %O -o %D %S"; + +WARNING: The default dvipdf script generates pdf files with bitmapped +fonts, which do not look good when viewed by acroread. That script +should be modified to give dvips the options "-P pdf" to ensure that +type 1 fonts are used in the pdf file. +.TP +.B $dvips ["dvips %O -o %D %S"] +The program to used as a filter to convert a .dvi file to a .ps file. +If pdf is going to be generated from pdf, then the value of the +$dvips_pdf_switch -- see below -- will be included in the options +substituted for "%O". +.TP +.B $dvips_landscape ["dvips -tlandscape %O -o %D %S"] +The program to used as a filter to convert a .dvi file to a .ps file +in landscape mode. +.TP +.B $dvips_pdf_switch ["-P pdf"] +Switch(es) for dvips program when pdf file is to be generated from +ps file. +.TP +.B $dvips_silent_switch ["-q"] +Switch(es) for dvips program when silent mode is on. +.TP +.B $dvi_update_command [""] +When the dvi previewer is set to be updated by running a command, this +is the command that is run. See the information for the variable +\fI$dvi_update_method\fR for further information, and see information +on the variable \fI$pdf_update_method\fR for an example for the +analogous case of a pdf previewer. +.TP +.B $dvi_update_method [2 under UNIX, 1 under MS-Windows] +How the dvi viewer updates its display when the dvi file has changed. +The values here apply equally to the \fI$pdf_update_method\fR and to +the \fI$ps_update_method\fR variables. + 0 => update is automatic, + 1=> manual update by user, which may only mean a mouse click on the +viewer's window or may mean a more serious action. + 2 => Send the signal, whose number is in the variable +\fI$dvi_update_signal\fR. The default value under UNIX is +suitable for xdvi. + 3 => Viewer cannot do an update, because it locks the file. (As with +acroread under MS-Windows.) + 4 => run a command to do the update. The command is specified by +the variable \fI$dvi_update_command\fR. + +See information on the variable \fI$pdf_update_method\fR for an +example of updating by command. +.TP +.B $dvi_update_signal [Under UNIX: SIGUSR1, which is a system-dependent value] +The number of the signal that is sent to the dvi viewer when it is +updated by sending a signal -- see the information on the variable +\fI$dvi_update_method\fR. The default value is the one appropriate +for xdvi on a UNIX system. +.TP +.B $fdb_ext ["fdb_latexmk"] +The extension of the file which \fIlatexmk\fR generates to contain a +database of information on source files. You will not normally need +to change this. +.TP +.B $force_mode [0] +If nonzero, continue processing past minor \fIlatex\fR errors +including unrecognized cross references. Equivalent to specifying the +\fB-f\fR option. +.TP +.B @generated_exts [( "aux", "bbl", "idx", "ind", "lof", "lot", "out", "toc", $fdb_ext )] +This contains a list of extensions for files that are generated during +a LaTeX run and that are read in by LaTeX in later runs, either +directly or indirectly. + +This list has two uses: (a) to set the kinds of file to be deleted in +a cleanup operation (with the \fB-c\fR, \fB-C\fR, \fB-CA\fR, \fB-g\fR +and \fB-gg\fR options), and (b) in the determination of whether a +rerun of (pdf)LaTeX is needed after a run that gives an error. + +(Normally, a change of a source file during a run should provoke a +rerun. This includes a file generated by LaTeX, e.g., an aux file, +that is read in on subsequent runs. But after a run that results in +an error, a new run should occur until the user has made a change in +the files. But the user may have corrected an error in a source .tex +file during the run. So \fIlatexmk\fR needs to distinguish +user-generated and automatically generated files; it determines the +automatically generated files as those with extensions in the list in +@generated_exts.) + +A convenient way to add an extra extension to the list, without losing +the already defined ones is to use a push command in the line in an +RC file. E.g., + + push @generated_exts, "end"; + +adds the extension "end" to the list of predefined generated +extensions. (This extension is used by the RevTeX package, for +example.) +.TP +.B $go_mode [0] +If nonzero, process files regardless of timestamps, and is then +equivalent to the \fB-g\fR option. +.TP +.B %hash_calc_ignore_pattern +\fB!!!This variable is for experts only!!!\fR + +The general rule \fIlatexmk\fR uses for determining when an extra run +of some program is needed is that one of the source files has changed. +But consider for example a latex package that causes an encapsulated +postscript file (an "eps" file) to be made that is to be read in on +the next run. The file contains a comment line giving its creation +date and time. On the next run the time changes, \fIlatex\fR sees +that the eps file has changed, and therefore reruns latex. This +causes an infinite loop, only exited becaues \fIlatexmk\fR has a limit +on the number of runs to guard against pathological situations. + +But the changing line has no real effect, since it is a comment. You +can instruct \fIlatex\fR to ignore the offending line as follows: + + $hash_calc_ignore_pattern{'eps'} = '^%%CreationDate: '; + +This creates a rule for files with extension \fI.eps\fR about lines to +ignore. The left-hand side is a \fIPerl\fR idiom for setting an item +in a hash. Note that the file extension is specified without a +period. The value, on the right-hand side, is a string containing a +regular expresssion. (See documentation on \fIPerl\fR for how they +are to be specified in general.) This particular regular expression +specifies that lines beginning with "%%CreationDate: " are to be +ignored in deciding whether a file of the given extension \fI.eps\fR +has changed. +.TP +.B $kpsewhich ["kpsewhich %S"] +The program called to locate a source file when the name alone is not +sufficient. Most filenames used by \fIlatexmk\fR have sufficient path +information to be found directly. But sometimes, notably when +.bib files are found from the log file of a bibtex run, the name of +the file, but not its path is known. The program specified by +$kpsewhich is used to find it. + +See also the \fI@BIBINPUTS\fR variable for another way that \fIlatexmk\fR +also uses to try to locate files; it applies only in the case of .bib +files. +.TP +.B $landscape_mode [0] +If nonzero, run in landscape mode, using the landscape mode previewers and +dvi to postscript converters. Equivalent to the \fB-l\fR option. +Normally not needed with current previewers. +.TP +.B $latex ["latex %O %S"] +The LaTeX processing program. Note that as with other programs, you +can use this variable not just to change the name of the program used, +but also specify options to the program. E.g., + + $latex = "latex --src-specials"; +.TP +.B $latex_silent_switch ["-interaction=batchmode"] +Switch(es) for the LaTeX processing program when silent mode is on. +Under MS-Windows, the default value is changed to +"-interaction=batchmode -c-style-errors", as used by MikTeX and fpTeX. +.TP +.B $lpr ["lpr %O %S" under UNIX/LINUX, \(dqNONE lpr\(dq under MS-WINDOWS] +The command to print postscript files. + +Under MS-Windows (unlike UNIX/LINUX), there is no standard program for +printing files. But there are ways you can do it. For example, if +you have gsview installed, you could use it with the option "/p": + + $lpr = '"c:/Program Files/Ghostgum/gsview/gsview32.exe" /p'; + +If gsview is installed in a different directory, you will need to make +the appropriate change. Note the combination of single and double +quotes around the name. The single quotes specify that this is a +string to be assigned to the configuration variable \fI$lpr\fR. The double +quotes are part of the string passed to the operating system to get +the command obeyed; this is necessary because one part of the command +name ("Program Files") contains a space which would otherwise be +misinterpreted. +.TP +.B $lpr_dvi ["NONE lpr_dvi"] +The printing program to print dvi files. +.TP +.B $lpr_pdf ["NONE lpr_pdf"] +The printing program to print pdf files. + +Under MS-Windows you could set this to use gsview, if it is installed, +e.g., + + $lpr = '"c:/Program Files/Ghostgum/gsview/gsview32.exe" /p'; + +If gsview is installed in a different directory, you will need to make +the appropriate change. Note the double quotes around the name: this +is necessary because one part of the command name ("Program Files") +contains a space which would otherwise be misinterpreted. + +.TP +.B $makeindex ["makeindex %O -o %D %S"] +The index processing program. +.TP +.B $max_repeat [5] +The maximum number of times \fIlatexmk\fR will run latex/pdflatex +before deciding that there may be an infinite loop and that it needs +to bail out, rather than rerunning latex/pdflatex again to resolve +cross-references, etc. The default value covers all normal cases. + +(Note that the "etc" covers a lot of cases where one run of +latex/pdflatex generates files to be read in on a later run.) +.TP +.B $new_viewer_always [0] +This variable applies to \fIlatexmk\fR \fBonly\fR in +continuous-preview mode. If \fI$new_viewer_always\fR is 0, +\fIlatexmk\fR will check for a previously running previewer on the +same file, and if one is running will not start a new one. If +\fI$new_viewer_always\fR is non-zero, this check will be skipped, and +\fIlatexmk\fR will behave as if no viewer is running. +.TP +.B $pdf_mode [0] +If zero, do NOT generate a pdf version of the document. +If equal to 1, generate a pdf version of the document using pdflatex. +If equal to 2, generate a pdf version of the document from the ps +file, by using the command specified by the \fI$ps2pdf\fR variable. +If equal to 3, generate a pdf version of the document from the dvi +file, by using the command specified by the \fI$dvipdf\fR variable. + +Equivalent to the \fB-pdf-\fR, \fB-pdf\fR, \fB-pdfdvi\fR, +\fB-pdfps\fR options. +.TP +.B $pdflatex ["pdflatex %O %S"] +The LaTeX processing program in the version that makes a pdf file instead +of a dvi file. +.TP +.B $pdflatex_silent_switch ["-interaction=batchmode"] +Switch(es) for the pdflatex program (specified in the variable +\fI$pdflatex\fR when silent mode is on. +Under MS-Windows, the default value is changed to +"-interaction=batchmode -c-style-errors", as used by MikTeX and fpTeX. +.TP +.B $pdf_previewer ["start acroread %O %S"] +The command to invoke a pdf-previewer. +[Default is changed to "start" on MS-WINDOWS; under more recent versions of +Windows, this will cause to be run whatever command the system has +associated with .pdf files.] + +\fBWARNING\fR: Potential problem under MS-Windows: +if acroread is used as the pdf previewer, and it is +actually viewing a pdf file, the pdf file cannot be updated. Thus +makes acroread a bad choice of previewer if you use \fIlatexmk\fR's +previous-continuous mode (option \fB-pvc\fR) under MS-windows. +This problem does not occur if ghostview, gv or gsview is used to +view pdf files. +.TP +.B $pdf_update_command [""] +When the pdf previewer is set to be updated by running a command, this +is the command that is run. See the information for the variable +\fI$pdf_update_method\fR. +.TP +.B $pdf_update_method [1 under UNIX, 3 under MS-Windows] +How the pdf viewer updates its display when the pdf file has +changed. See the information on the variable \fI$dvi_update_method\fR +for the codes. (Note that information needs be changed slightly so +that for the value 4, to run a command to do the update, the command +is specified by the variable \fI$pdf_update_command\fR, and for the +value 2, to specify update by signal, the signal is specified by +\fI$pdf_update_signal\fR.) + +Note that acroread under MS-Windows (but not UNIX) locks the pdf file, so +the default value is then 3. + +Arranging to use a command to get a previewer explicitly updated +requires three variables to be set. For example: + + $pdf_previewer = "start xpdf -remote %R %O %S"; + $pdf_update_method = 4; + $pdf_update_command = "xpdf -remote %R -reload"; + +The first setting arranges for the xpdf program to be used in its +"remote server mode", with the server name specified as the rootname +of the TeX file. The second setting arranges for updating to be done +in response to a command, and the third setting sets the update command. + +.TP +.B $pdf_update_signal [Under UNIX: SIGHUP, which is a system-dependent value] +The number of the signal that is sent to the pdf viewer when it is +updated by sending a signal -- see the information on the variable +\fI$pdf_update_method\fR. The default value is the one appropriate +for gv on a UNIX system. +.TP +.B $pid_position[1 under UNIX, -1 under MS-Windows] +The variable \fI$pid_position\fR is used to +specify which word in lines of the output from \fI$pscmd\fR +corresponds to the process ID. The first word in the line is numbered +0. The default value of 1 (2nd word in line) is correct for Solaris +2.6 and Linux. Setting the variable to -1 is used to indicate that +\fI$pscmd\fR is not to be used. +.TP +.B $postscript_mode [0] +If nonzero, generate a postscript version of the document. +Equivalent to the \fB-ps\fR option. +.TP +.B $preview_continuous_mode [0] +If nonzero, run a previewer to view the document, and +continue running \fIlatexmk\fR to keep .dvi up-to-date. Equivalent to +the \fB-pvc\fR option. +Which previewer is run depends on the other settings, see the command +line options \fB-view=\fR, and the variable \fI$view\fR. +.TP +.B $preview_mode [0] +If nonzero, run a previewer to preview the document. +Equivalent to the \fB-pv\fR option. +Which previewer is run depends on the other settings, see the command +line options \fB-view=\fR, and the variable \fI$view\fR. +.TP +.B $printout_mode [0] +If nonzero, print the document using \fIlpr\fR. Equivalent to the +\fB-p\fR option. This is recommended \fBnot\fR to be set from an RC +file, otherwise you could waste lots of paper. +.TP +.B $print_type = ["ps"] +Type of file to printout: possibilities are "dvi", "none", "pdf", or "ps". +.TP +.B $pscmd +Command used to get all the processes currently run by the user. The +-pvc option uses the command specified by the variable \fI$pscmd\fR to +determine if there is an already running previewer, and to find the +process ID (needed if \fIlatexmk\fR needs to signal the previewer +about file changes). + +Each line of the output of this command is assumed to correspond to +one process. See the \fI$pid_position\fR variable for how the process +number is determined. + +The default for \fIpscmd\fR is "NONE" under MS-Windows and cygwin +(i.e., the command is not used), "ps --width 200 -f -u $ENV{USER}" +under linux, "ps -ww -u $ENV{USER}" under darwin (Macintosh OS-X), and +"ps -f -u $ENV{USER}" under other operating systems (including other +flavors of UNIX). In these specifications "$ENV{USER}" is substituted +by the username. +.TP +.B $ps2pdf ["ps2pdf %O %S %D"] +Command to convert ps to pdf file. +.TP +.B $ps_filter [empty] +The postscript file filter to be run on the newly produced postscript +file before other processing. Equivalent to specifying the \fB-pF\fR +option. +.TP +.B $ps_previewer ["start gv %O %S", but \(dqstart %O %S" under MS-WINDOWS] +The command to invoke a ps-previewer. (The default under MS-WINDOWS +will cause to be run whatever command the system has associated +with .ps files.) + +Note that gv could be used with the -watch option updates its display +whenever the postscript file changes, whereas ghostview does not. +However, different versions of gv have slightly different ways of +writing this option. You can configure this variable apppropriately. + +\fBWARNING\fR: Linux systems may have installed one (or more) versions +of gv under different names, e.g., ggv, kghostview, etc, but perhaps +not one called gv. +.TP +.B $ps_previewer_landscape ["start gv -swap %O %S", but \(dqstart %O %S" under MS-WINDOWS] +The command to invoke a ps-previewer in landscape mode. +.TP +.B $ps_update_command [""] +When the postscript previewer is set to be updated by running a command, this +is the command that is run. See the information for the variable +\fI$ps_update_method\fR. +.TP +.B $ps_update_method [0 under UNIX, 1 under MS-Windows] +How the postscript viewer updates its display when the ps file has +changed. See the information on the variable \fI$dvi_update_method\fR +for the codes. (Note that information needs be changed slightly so +that for the value 4, to run a command to do the update, the command +is specified by the variable \fI$ps_update_command\fR, and for the +value 2, to specify update by signal, the signal is specified by +\fI$ps_update_signal\fR.) + +.TP +.B $ps_update_signal [Under UNIX: SIGHUP, which is a system-dependent value] +The number of the signal that is sent to the pdf viewer when it is +updated by sending a signal -- see \fI$ps_update_method\fR. The +default value is the one appropriate for gv on a UNIX system. +.TP +.B $sleep_time [2] +The time to sleep (in seconds) between checking for source file +changes when running the \fB-pvc\fR option. +.TP +.B $texfile_search [""] +This is an obsolete variable, replaced by the \fI@default_files\fR +variable. + +For backward compatibility, if you choose to set +\fI$texfile_search\fR, it is a string of space-separated filenames, and +then \fIlatexmk\fR replaces \fI@default_files\fR with the filenames in +\fI$texfile_search\fR to which is added "*.tex". +.TP +.B $tmpdir [See below for default] +Directory to store temporary files that \fIlatexmk\fR may generate while +running. + +The default under MSWindows (including cygwin), is to set +\fI$tmpdir\fR to the value of the first of whichever of the system +environment variables TMPDIR or TEMP exists, otherwise to the current +directory. Under other operating systems (expected to be UNIX/Linux, +including OS-X), the default is the value of the system environment +variable TMPDIR if it exists, otherwise "/tmp". +.TP +.B $view ["default"] +Which kind of file is to be previewed if a previewer is used. The +possible values are "default", "dvi", "ps", "pdf". The value +of "default" means that the "highest" of the kinds of file generated is +to be used (among dvi, ps and pdf). + +.SH CUSTOM DEPENDENCIES +.PP +In any RC file a set of custom dependencies can be set up to convert a +file with one extension to a file with another. An example use of this +would be to allow \fIlatexmk\fR to convert a \fI.fig\fR file to +\fI.eps\fR to be included in the \fI.tex\fR file. + +The old method of configuring \fIlatexmk\fR was to directly manipulate +the \fB@cus_dep_list\fR array that contains information defining the +custom dependencies. This method still works. But now there are +subroutines that allow convenient manipulations of the custom +dependency list. These are + + add_cus_dep( fromextension, toextension, must, subroutine ) + remove_cus_dep( fromextension, toextension ) + show_cus_dep() + +The custom dependency is a list of rules, each of which is specified +as follow: +.TP +.B from extension: +The extension of the file we are converting from (e.g. "fig"). +It is specified without a period. +.TP +.B to extension: +The extension of the file we are converting to (e.g. "eps"). +It is specified without a period. +.TP +.B must: +If non-zero, the file from which we are converting \fBmust\fR exist, if it +doesn't exist \fIlatexmk\fR will give an error message and exit unless +the \fB-f\fR option is specified. If \fImust\fR is zero and the file +we are converting from doesn't exist, then no action is taken. +.TP +.B function: +The name of the subroutine that \fIlatexmk\fR should call to perform the +file conversion. The first argument to the subroutine is the base name +of the file to be converted without any extension. The subroutines are +declared in the syntax of \fIPerl\fR. The function should return 0 if +it was successful and a nonzero number if it failed. +.PP +It is invoked whenever \fIlatexmk\fR detects that a run of +latex/pdflatex needs to read a file, like a graphics file, whose +extension is the to-extension of a custom dependency. Then +\fIlatexmk\fR examines whether a file exists with the same name, but +with the corresponding from-extension, as specified in the +custom-dependency rule. If it does, then whenever the destination +file (the one with the to-extension) is out-of-date with respect to +the corresponding source file. + +To make the new destination file, the \fIPerl\fR subroutine specified in the +rule is invoked, with an argument that is the base name of the files +in question. Simple cases just involve a subroutine invoking an +external program; this can be done by following the templates below, +even by those without knowledge of the \fIPerl\fR programming language. Of +course, experts could do something much more elaborate. + +One other item in each custom-dependency rule labelled "must" above +specifies how the rule should be applied when the source file fails to +exist. + +A simple and typical example of code in an initialization rcfile is + + add_cus_dep( 'fig', 'eps', 0, 'fig2eps' ); + sub fig2eps { + system("fig2dev -Leps $_[0].fig $_[0].eps"); + } + +The first line adds a custom dependency that converts a file with +extension "fig", as created by the xfig program, to an encapsulated +postscript file, with extension "eps". The remaining lines define a +subroutine that carries out the conversion. If a rule for converting +"fig" to "eps" files already exists (e.g., from a previously read-in +initialization file), the \fIlatexmk\fR will delete this rule before +making the new one. + +Suppose \fIlatexmk\fR is using this rule to convert a file +"figure.fig" to "figure.eps". Then it will invoke the fig2eps +subroutine defined in the above code with a single argument "figure", +which is the basename of each of the files (possibly with a path +component). This argument is referred to by \fIPerl\fR as $_[0]. In +the example above, the subroutine uses the \fIPerl\fR command system +to invoke the program fig2dev. The double quotes around the string +are a \fIPerl\fR idiom that signify that each string of the form of a +variable name, $_[0] in this case, is to be substituted by its value. + +If the return value of the subroutine is non-zero, then \fIlatexmk\fR +will assume an error occurred during the execution of the subroutine. +In the above example, no explicit return value is given, and instead +the return value is the value returned by the last (and only) +statement, i.e., the invocation of system, which returns the value 0 +on success. + +If you use filenames with spaces in them, and if your LaTeX system and +all other relevant software correctly handle such filenames, then you +could put single quotes around filenames in the command line that is +executed: + + add_cus_dep( 'fig', 'eps', 0, 'fig2eps' ); + sub fig2eps { + system("fig2dev -Lps '$_[0].fig' '$_[0].eps'"); + } + +This causes the invocation of the \fIfig2dev\fR program to have quoted +filenames; it should therefore work with filenames containing spaces. +\fBHowever, not all software deals correctly with filenames that +contain spaces. Moreover, the rules, if any, for quoting filenames +vary between operating systems, command shells and individual pieces +of software, so this code may not always work.\fR + +If you use pdflatex instead of latex, then you will probably prefer to +convert your graphics files to pdf format, in which case you would +replace the above code in an initialization file by + + add_cus_dep( 'fig', 'pdf, 0, 'fig2pdf' ); + sub fig2pdf { + system("fig2dev -Lpdf $_[0].fig $_[0].pdf"); + } + +If you have some general custom dependencies defined in the system or +user initialization file, you may find that for a particular project +they are undesirable. So you might want to delete the unneeded ones. +For example, you remove any "fig" to "eps" rule by the line + + remove_cus_dep( 'fig', 'eps' ); + +If you have complicated sets of custom dependencies, you may want to +get a listing of the custom dependencies. This is done by using the +line + + show_cus_dep(); + +in an initialization file. + +Another example of a custom dependency overcomes a limitation of +\fIlatexmk\fR concerning index files. The only index-file conversion +built-in to \fIlatexmk\fR is from an ".idx" file written on one run of +latex/pdflatex to an ".ind" file to be read in on a subsequent run. +But with the index.sty package you can create extra indexes with +extensions that you configure. \fILatexmk\fR does not know how to +deduce the extensions from the information it has. But you can easily +write a custom dependency. For example if your latex file uses the +command "\\newindex{special}{ndx}{nnd}{Special index}" you will need to +convert files with the extension \fI.ndx\fR to \fI.nnd\fR. The +following lines in an initialization RC file will cause this to +happen: + + add_cus_dep('ndx', 'nnd', 0, 'makendx2nnd'); + sub makendx2nnd { + system("makeindex -o $_[0].nnd $_[0].ndx"); + } + +(You will need to modify this code if you use filenames +with spaces in them, to provide correct quoting of the filenames.) + +Those of you with experience with Makefiles, will undoubtedly be +concerned that the \fI.ndx\fR file is written during a run of +latex/pdflatex and is always later than the \fI.nnd\fR last read in. +Thus the \fI.nnd\fR appears to be perpetually out-of-date. This +situation, of circular dependencies, is endemic to latex, and +\fIlatexmk\fR in its current version works correctly with circular +dependencies. It examines the contents of the files (by use of an md5 +checksum), and only does a remake when the file contents have actually +changed. + +Of course if you choose to write random data to the \fI.nnd\fR (or and +\fI.aux\fR file, etc) that changes on each new run, then you will have +a problem. For real experts: See the \fI%hash_cal_ignore_pattern\fR +if you have to deal with such problems. + +Glossaries can be dealt with similarly. + +.SH OLD METHOD OF DEFINING CUSTOM DEPENDENCIES +In previous versions of \fIlatexmk\fR, the only method of defining +custom dependencies was to directly manipulate the table of custom +dependencies. This is contained in the \fB@cus_dep_list\fR array. It +is an array of strings, and each string in the array has four items in +it, each separated by a space, the from-extension, the to-extension, +the "must" item, and the name of the subroutine for the custom +dependency. These were all defined above. +.PP +An example of the old method of defining custom dependencies is as +follows. It is the code in an RC file to ensure automatic conversion +of \fI.fig\fR files to \fI.eps\fR files: + + push @cus_dep_list, "fig eps 0 fig2eps"; + sub fig2eps { + system("fig2dev -Lps $_[0].fig $_[0].eps"); + } + +This method still works, and is equivalent to the earlier code using +the add_cus_dep subroutine, except that it doesn't delete any previous +custom-dependency for the same conversion. So the new method is +preferable. + +.SH SEE ALSO +latex(1), bibtex(1). +.SH BUGS +Sometimes a viewer (gv) tries to read an updated .ps or .pdf file +after its creation is started but before the file is complete. Work +around: manually refresh (or reopen) display. Or use one of the other +previewers and update methods. + +(The following isn't really a bug, but concerns features of previewers.) +Preview continuous mode only works perfectly with certain previewers: +Xdvi on UNIX/LINUX works for dvi files. +Gv on UNIX/LINUX works for both postscript and pdf. +Ghostview on UNIX/LINUX needs a manual update (reopen); it views +postscript and pdf. +Gsview under MS-Windows works for both postscript and pdf, +but only reads the updated file when its screen is refreshed. +Acroread under UNIX/LINUX views pdf, but the file needs to be closed +and reopened to view an updated version. +Under MS-Windows, acroread locks its input file and so the +pdf file cannot be updated. (Remedy: configure \fIlatexmk\fR to use gsview +instead.) +.SH THANKS TO +Authors of previous versions. Many users with their feedback, and +especially +David Coppit (username david at node coppit.org) who made many useful +suggestions that contributed to version 3, and Herbert Schulz. +(Please note that the +e-mail addresses are not written in their standard form to avoid being +harvested by worms and viruses.) +.SH AUTHOR +Current version, by John Collins (username collins at node phys.psu.edu). +(Version 4.01). + +It can be obtained from CTAN: +<http://www.tug.org/tex-archive/support/latexmk/>, and from the +author's website <http://www.phys.psu.edu/~collins/software/latexmk/>. +.br +Modifications and enhancements by Evan McLean (Version 2.0) +.br +Original script called "go" by David J. Musliner (RCS Version 3.2) + +\" LocalWords: fR fIlatexmk dvi ps fILatexmk pdflatex bibtex makeindex fB pv +\" LocalWords: pvc fIgv xdvi gsview cygwin fdb TP tex bm bs fIlatex fIbibtex +\" LocalWords: gg regeneratable dep exts dF dviF dviselect fI fR's lpr pdfps +\" LocalWords: pdfdvi dvipdf pF psF psnup fIsome gv acroread xpdf rcfile cus +\" LocalWords: batchmode latexmkrc elatex basename texfile WinXP BIBINPUTS +\" LocalWords: kpsewhich BibTeX dtx dvipdfm dvips fpTeX MikTeX fBWARNING pid +\" LocalWords: pscmd fIlpr fBnot ENV OSX SIGHUP tmpdir MSWindows tmp eps dev +\" LocalWords: fImust fIperl Lps fIfig diff --git a/Master/texmf-dist/doc/support/latexmk/latexmk.bat b/Master/texmf-dist/doc/support/latexmk/latexmk.bat new file mode 100755 index 00000000000..f119082adac --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/latexmk.bat @@ -0,0 +1,5 @@ +Rem Execute latexmk.pl, searching for it in the PATH
+Rem Assume perl is in the PATH. If not, you should replace 'perl' by
+Rem the full pathname of the perl executable, e.g., 'C:\perl\bin\perl.exe'
+
+perl -S latexmk.pl %1 %2 %3 %4 %5 %6 %7 %8 %9
diff --git a/Master/texmf-dist/doc/support/latexmk/latexmk.pdf b/Master/texmf-dist/doc/support/latexmk/latexmk.pdf Binary files differnew file mode 100644 index 00000000000..1ff86560416 --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/latexmk.pdf diff --git a/Master/texmf-dist/doc/support/latexmk/latexmk.txt b/Master/texmf-dist/doc/support/latexmk/latexmk.txt new file mode 100644 index 00000000000..7c99e946497 --- /dev/null +++ b/Master/texmf-dist/doc/support/latexmk/latexmk.txt @@ -0,0 +1,1772 @@ + +NAME + latexmk - generate LaTeX document + +SYNOPSIS + latexmk [options] [file ...] + +DESCRIPTION + Latexmk completely automates the process of compiling a LaTeX document. + Essentially, it is like a specialized relative of the general make + utility, but one which determines dependencies automatically and has + some other very useful features. In its basic mode of operation + latexmk is given the name of the primary source file for a document, + and it issues the appropriate sequence of commands to generate a .dvi, + .ps, .pdf and/or hardcopy version of the document. + + Latexmk can also be set to run continuously with a suitable previewer. + In that case the LaTeX program, etc, are rerun whenever one of the + source files is modified, and the previewer automatically updates the + on-screen view of the compiled document. + + Latexmk determines which are the source files by examining the log + file. When latexmk is run, it examines properties of the source files, + and if any have been changed since the last document generation, + latexmk will run the various LaTeX processing programs as necessary. + In particular, it will repeat the run of LaTeX (or pdflatex) often + enough to resolve all cross references; depending on the macro packages + used. With some macro packages and document classes, four, or even + more, runs may be needed. If necessary, latexmk will also run bibtex + and/or makeindex. In addition, latexmk can be configured to generate + other necessary files. For example, from an updated figure file it can + automatically generate a file in encapsulated postscript or another + suitable format for reading by LaTeX. + + Latexmk has two different previewing options. In the simple -pv + option, a dvi, postscript or pdf previewer is automatically run after + generating the dvi, postscript or pdf version of the document. The + type of file to view is selected according to configuration settings + and command line options. + + The second previewing option is the powerful -pvc option (mnemonic: + "preview continuously"). In this case, latexmk runs continuously, reg- + ularly monitoring all the source files to see if any have changed. + Every time a change is detected, latexmk runs all the programs neces- + sary to generate a new version of the document. A good previewer (like + gv) will then automatically update its display. Thus the user can sim- + ply edit a file and, when the changes are written to disk, latexmk com- + pletely automates the cycle of updating the .dvi (and possibly the .ps + and .pdf) file, and refreshing the previewer's display. It's not quite + WYSIWYG, but usefully close. + + For other previewers, the user may have to manually make the previewer + update its display, which can be (some versions of xdvi and gsview) as + simple as forcing a redraw of its display. + + Latexmk has the ability to print a banner in gray diagonally across + each page when making the postscript file. It can also, if needed, + call an external program to do other postprocessing on the generated + files. + + + + + 1 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + Latexmk is highly configurable, both from the command line and in con- + figuration files, so that it can accommodate a wide variety of user + needs and system configurations. Default values are set according to + the operating system, so latexmk often works without special configura- + tion on MS-Windows, cygwin, Linux, OS-X, and other UNIX systems + (notably Solaris). + + A very annoying complication handled very reliably by Latexmk, is that + LaTeX is a multiple pass system. On each run, LaTeX reads in informa- + tion generated on a previous run, for things like cross referencing and + indexing. In the simplest cases, a second run of LaTeX suffices, and + often the log file contains a message about the need for another pass. + However, there is a wide variety of add-on macro packages to LaTeX, + with a variety of behaviors. The result is to break simple-minded + determinations of how many runs are needed and of which programs. In + its new version, latexmk has a highly general and efficient solution to + these issues. The solution involves retaining between runs information + on the source files, and a symptom is that latexmk generates an extra + file (with extension .fdb_latexmk, by default) that contains the source + file information. + + +LATEXMK OPTIONS AND ARGUMENTS ON COMMAND LINE + (All options can be introduced by single or double "-" characters, + e.g., "latexmk -help" or "latexmk --help".) + + file One or more files can be specified. If no files are specified, + latexmk will, by default, run on all files in the current work- + ing directory with a ".tex" extension. This behavior can be + changed: see the description concerning the @default_files vari- + able in the section "List of configuration variables usable in + initialization files". + + If a file is specified without an extension, then the ".tex" extension + is automatically added, just as LaTeX does. Thus, if you specify: + + latexmk foo + + then latexmk will operate on the file "foo.tex". + + -bm <message> + A banner message to print diagonally across each page when con- + verting the dvi file to postscript. The message must be a sin- + gle argument on the command line so be careful with quoting + spaces and such. + + Note that if the -bm option is specified, the -ps option is + assumed. + + -bi <intensity> + How dark to print the banner message. A decimal number between + 0 and 1. 0 is black and 1 is white. The default is 0.95, which + is OK unless your toner cartridge is getting low. + + + + + 28 September 2008 2 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + -bs <scale> + A decimal number that specifies how large the banner message + will be printed. Experimentation is necessary to get the right + scale for your message, as a rule of thumb the scale should be + about equal to 1100 divided by the number of characters in the + message. The default is 220.0 which is just right for 5 charac- + ter messages. + + -commands + List the commands used by latexmk for processing files, and then + exit. + + -c Clean up (remove) all regeneratable files generated by latex and + bibtex except dvi, postscript and pdf. These files are a combi- + nation of log files, aux files, and those with extensions speci- + fied in the @generated_exts configuration variable. In addi- + tion, files with extensions by the $clean_ext configuration + variable are removed. But the file containing a database of + source file information is not removed. + + This cleanup is instead of a regular make. See the -gg option + if you want to do a cleanup then a make. + + -C Clean up (remove) all regeneratable files generated by latex and + bibtex. This is the same as the -c option with the addition of + dvi, postscript and pdf files, and those with extensions in the + $clean_full_ext configuration variable. + + This cleanup is instead of a regular make. See the -gg option + if you want to do a cleanup than a make. + + -CA Clean up (remove) absolutely all regeneratable files. This is + the action specified by -C with the addition of deleting the + file containing the database of source file information. + + This cleanup is instead of a regular make. It is the same as -C + -CF. See the -gg option if you want to do a cleanup then a + make. + + -CF Remove the file containing the database of source file informa- + tion, before doing the other actions requested. + + -d Set draft mode. This prints the banner message "DRAFT" across + your page when converting the dvi file to postscript. Size and + intensity can be modified with the -bs and -bi options. The -bm + option will override this option as this is really just a short + way of specifying: + + latexmk -bm DRAFT + + Note that if the -d option is specified, the -ps option is + assumed. + + -dF Dvi file filtering. The argument to this option is a filter + which will generate a filtered dvi file with the extension + + + + 28 September 2008 3 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + ".dviF". All extra processing (e.g. conversion to postscript, + preview, printing) will then be performed on this filtered dvi + file. + + Example usage: To use dviselect to select only the even pages of + the dvi file: + + latexmk -dF 'dviselect even' foo.tex + + -diagnostics + Print detailed diagnostics during a run. This may help for + debugging problems or to understand .latexmk's behavior in dif- + ficult situations. + + -dvi Generate dvi version of document. + + -dvi- Turn off generation of dvi version of document. (This may get + overridden, if some other file is made (e.g., a .ps file) that + is generated from the dvi file, or if no generated file at all + is requested.) + + -e <code> + Execute the specified initialization code before processing. + The code is Perl code of the same form as is used in latexmk's + initialization files -- for more details, see the information on + the -r option, and the section about "Configuration/initializa- + tion (RC) files". The code is typically a sequence of assign- + ment statements separated by semicolons. + + The code is executed when the -e option is encountered during + latexmk's parsing of its command line. See the -r option for a + way of executing initialization code from a file. An error + results in latexmk stopping. Multiple instances of the -r and + -e options can be used, and they are executed in the order they + appear on the command line. + + Some care is needed to deal with proper quoting of special char- + acters in the code on the command line. For example, suppose it + is desired to set the latex command to use its -shell-escape + option, then under UNIX/LINUX you could use the line + + latexmk -e '$latex=q/latex %O -shell-escape %S/' file.tex + + (Note that the q/.../ construct is a Perl idiom equivalent to + using single quotes. This is easier than arranging to get a + quote character correctly escaped in a way that is independent + of the shell and the operating-system.) + + -f Force latexmk to continue document processing despite errors. + Normally, when latexmk detects that LaTeX or another program has + found an error which will not be resolved by further processing, + no further processing is carried out. + + -f- Turn off the forced processing-past-errors such as is set by the + -f option. This could be used to override a setting in a + + + + 28 September 2008 4 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + configuration file. + + -g Force latexmk to process document fully, even under situations + where latexmk would normally decide that no changes in the + source files have occurred since the previous run. This option + is useful, for example, if you change some options and wish to + reprocess the files. + + -g- Turn off -g. + + -gg "Super go mode" or "clean make": clean out generated files as if + -CA had been given, and then do a regular make. + + -h, -help + Print help information. + + -l Run in landscape mode, using the landscape mode for the preview- + ers and the dvi to postscript converters. This option is not + normally needed nowadays, since current previewers normally + determine this information automatically. + + -l- Turn off -l. + + -new-viewer + When in continuous-preview mode, always start a new viewer to + view the generated file. By default, latexmk will, in continu- + ous-preview mode, test for a previously running previewer for + the same file and not start a new one if a previous previewer is + running. However, its test sometimes fails (notably if there is + an already-running previewer that is viewing a file of the same + name as the current file, but in a different directory). This + option turns off the default behavior. + + -new-viewer- + The inverse of the -new-viewer option. It puts latexmk in its + normal behavior that in preview-continuous mode it checks for an + already-running previewer. + + -p Print out the document. By default it is the generated + postscript file that is printed. But you can use the -print=... + option to print the dvi or pdf files instead, and you can con- + figure this in a start up file (by setting the $print_type vari- + able). + + However, printing is enabled by default only under UNIX/LINUX + systems, where the default is to use the lpr command. In gen- + eral, the correct behavior for printing very much depends on + your system's software. In particular, under MS-Windows you + must have suitable program(s) available, and you must have con- + figured the print commands used by latexmk. This can be non- + trivial. See the documentation on the $lpr, $lpr_dvi, and + $lpr_pdf configuration variables to see how to set the commands + for printing. + + This option is incompatible with the -pv and -pvc options, so it + + + + 28 September 2008 5 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + turns them off. + + -pdf Generate pdf version of document using pdflatex. + + -pdfdvi + Generate pdf version of document from the dvi file, by default + using dvipdf. + + -pdfps Generate pdf version of document from the ps file, by default + using ps2pdf. + + -pdf- Turn off generation of pdf version of document. (This can be + used to override a setting in a configuration file. It may get + overridden if some other option requires the generation of a pdf + file.) + + -print=dvi, -print=ps, -print=pdf + Define which kind of file is printed. This option also ensures + that the requisite file is made, and turns on printing. The + default is to print a postscript file. + + -ps Generate postscript version of document. + + -ps- Turn off generation of postscript version of document. This can + be used to override a setting in a configuration file. (It may + get overridden by some other option that requires a postscript + file, for example a request for printing.) + + -pF Postscript file filtering. The argument to this option is a + filter which will generate a filtered postscript file with the + extension ".psF". All extra processing (e.g. preview, printing) + will then be performed on this filtered postscript file. + + Example of usage: Use psnup to print two pages on the one page: + + latexmk -ps -pF 'psnup -2' foo.tex + + or + + latexmk -ps -pF "psnup -2" foo.tex + + Whether to use single or double quotes round the "psnup -2" will + depend on your command interpreter, as used by the particular + version of perl and the operating system on your computer. + + -pv Run file previewer. If the -view option is used, this will + select the kind of file to be previewed (dvi, ps or pdf). Oth- + erwise the viewer views the "highest" kind of file selected, by + the -dvi, -ps, -pdf, -pdfps options, in the order dvi, ps, pdf + (low to high). If no file type has been selected, the dvi pre- + viewer will be used. This option is incompatible with the -p + and -pvc options, so it turns them off. + + -pv- Turn off -pv. + + + + + 28 September 2008 6 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + -pvc Run a file previewer and continually update the .dvi, .ps, + and/or .pdf files whenever changes are made to source files (see + the Description above). Which of these files is generated and + which is viewed is governed by the other options, and is the + same as for the -pv option. The preview-continuous option -pvc + can only work with one file. So in this case you will normally + only specify one filename on the command line. It is also + incompatible with the -p and -pv options, so it turns these + options off + + With a good previewer the display will be automatically updated. + (Under some but not all versions of UNIX/Linux "gv -watch" does + this for postscript files; this can be set by a configuration + variable. This would also work for pdf files except for an + apparent bug in gv that causes an error when the newly updated + pdf file is read.) Many other previewers will need a manual + update. + + Important note: the acroread program on MS-Windows locks the pdf + file, and prevents new versions being written, so it is a bad + idea to use acroread to view pdf files in preview-continuous + mode. It is better to use a dvi or ps viewer, as set by one of + the -view=dvi and -view=ps options. + + There are some other methods for arranging an update, notably + useful for many versions of xdvi and xpdf. These are best set + in latexmk's configuration; see below. + + Note that if latexmk dies or is stopped by the user, the + "forked" previewer will continue to run. Successive invocations + with the -pvc option will not fork new previewers, but latexmk + will normally use the existing previewer. (At least this will + happen when latexmk is running under an operating system where + it knows how to determine whether an existing previewer is run- + ning.) + + -pvc- Turn off -pvc. + + -quiet Same as -silent + + -r <rcfile> + Read the specified initialization file ("RC file") before pro- + cessing. + + Be careful about the ordering: (1) Standard initialization files + -- see the section below on "Configuration/initialization (RC) + files" -- are read first. (2) Then the options on the command + line are acted on in the order they are given. Therefore if an + initialization file is specified by the -r option, it is read + during this second step. Thus an initialization file specified + with the -r option can override both the standard initialization + files and previously specified options. But all of these can be + overridden by later options. + + The contents of the RC file just comprise a piece of code in the + + + + 28 September 2008 7 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + Perl programming language (typically a sequence of assignment + statements); they are executed when the -r option is encountered + during latexmk's parsing of its command line. See the -e option + for a way of giving initialization code directly on latexmk's + command line. An error results in latexmk stopping. Multiple + instances of the -r and -e options can be used, and they are + executed in the order they appear on the command line. + + -silent + Run commands silently, i.e., with options that reduce the amount + of diagnostics generated. For example, with the default set- + tings for commands under UNIX, the command "latex -interac- + tion=batchmode" is used for latex. + + Also reduce the number of informational messages that latexmk + generates. + + -v, -version + Print version number of latexmk. + + -verbose + Opposite of -silent. This is the default setting. + + -view=default, -view=dvi, -view=ps, -view=pdf + Set the kind of file used when previewing is requested (e.g., by + the -pv or -pvc switches). The default is to view the "highest" + kind of requested file (in the order dvi, ps, pdf). + + The preview-continuous option -pvc can only work with one file. So in + this case you will normally only specify one filename on the command + line. + + Options -p, -pv and -pvc are mutually exclusive. So each of these + options turns the others off. + + +EXAMPLES + % latexmk thesis # run latex enough times to resolve + cross-references + + % latexmk -pvc -ps thesis# run latex enough times to resolve + cross-references, make a postscript + file, start a previewer. Then + watch for changes in the source + file thesis.tex and any files it + uses. After any changes rerun latex + the appropriate number of times and + remake the postscript file. If latex + encounters an error, latexmk will + keep running, watching for + source file changes. + + % latexmk -c # remove .aux, .log, .bbl, .blg, .dvi, + .pdf, .ps & .bbl files + + + + + 28 September 2008 8 + + + + + +LATEXMK(1L) LATEXMK(1L) + + +CONFIGURATION/INITIALIZATION (RC) FILES + Latexmk can be customized using initialization files, which are read at + startup in the following order: + + 1) The system RC file, if it exists. + On a UNIX system, latexmk searches for following places for its sys- + tem RC file, in the following order, and reads the first it finds: + "/opt/local/share/latexmk/LatexMk", + "/usr/local/share/latexmk/LatexMk", + "/usr/local/lib/latexmk/LatexMk". + On a MS-WINDOWS system it looks for "C:\latexmk\LatexMk". + + 2) The user's RC file, "$HOME/.latexmkrc", if it exists. Here $HOME is + the value of the environment variable HOME. On UNIX and clones + (including LINUX), this variable is set by the system; on MS-Windows, + the user may choose to set it. + + 3) The RC file in the current working directory. This file can be + named either "latexmkrc" or ".latexmkrc", and the first of these to be + found is used, if any. + + 4) Any RC file(s) specified on the command line with the -r option. + + Each RC file is a sequence of Perl commands. Naturally, a user can use + this in creative ways. But for most purposes, one simply uses a + sequence of assignment statements that override some of the built-in + settings of Latexmk. Straightforward cases can be handled without + knowledge of the Perl language by using the examples in this document + as templates. Comment lines are introduced by the "#" character. + + Note that command line options are obeyed in the order in which they + are written; thus any RC file specified on the command line with the -r + option can override previous options but can be itself overridden by + later options on the command line. There is also the -e option, which + allows initialization code to be specified in latexmk's command line. + + +HOW TO SET VARIABLES IN INITIALIZATION FILES + The important variables that can be configured are described in the + section "List of configuration variables usable in initialization + files". Syntax for setting these variables is of the following forms: + + $bibtex = 'bibtex %O %B'; + + for the setting of a string variable, + + $preview_mode = 1; + + for the setting of a numeric variable, and + + @default_files = ('paper', 'paper1'); + + for the setting of an array of strings. It is possible to append an + item to an array variable as follows: + + + + + 28 September 2008 9 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + push @default_files, 'paper2'; + + Note that simple "scalar" variables have names that begin with a $ + character and array variables have names that begin with a @ character. + Each statement ends with a semicolon. + + You can do much more complicated things, but for this you will need to + consult a manual for the Perl programming language. + + + + +FORMAT OF COMMAND SPECIFICATIONS + Some of the variables set the commands that latexmk uses for carrying + out its work, for example to generate a dvi file from a tex file or to + view a postscript file. This section describes some important features + of how the commands are specified. + + Placeholders: Supposed you wanted latexmk to use the command elatex in + place of the regular latex command, and suppose moreover that you + wanted to give it the option "--shell-escape". You could do this by + the following setting: + + $latex = 'elatex --shell-escape %O %S'; + + The two items starting with the % character are placeholders. These + are substituted by appropriate values before the command is run. Thus + %S will be replaced by the source file that elatex will be applied to, + and %O will be replaced by any options that latexmk has decided to use + for this command. (E.g., if you used the -silent option it would + replace %O by "-interaction=batchmode".) + + The available placeholders are: + + %B base of filename for current command. E.g., if a postscript + file document.ps is being made from the dvi file document.dvi, + then the basename is document. + + %D destination file (e.g., the name of the postscript file when + converting a dvi file to postscript). + + %O options + + %R root filename. This is the base name for the main tex file. + + %S source file (e.g., the name of the dvi file when converting a + dvi file to ps). + + %T The name of the primary tex file. + + The distinction between %B and %R needs a bit of care, since they are + often the same, but not always. For example on a simple document, the + basename of a bibtex run is the same as for the texfile. But in a doc- + ument with several bibliographies, the bibliography files will have a + variety of names. Since bibtex is invoked with the basename of the + + + + 28 September 2008 10 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + bibliography file, the setting for the bibtex command should therefore + be + + $bibtex = 'bibtex %O %B'; + + Generally, you should use %B rather than %R. Similarly for most pur- + poses, the name %T of the primary texfile is not a useful placeholder. + + See the default values in the section "List of configuration variables + usable in initialization files" for what is normally the most appropri- + ate usage. + + If you omit to supply any placeholders whatever in the specification of + a command, latexmk will supply what its author thinks are appropriate + defaults. This gives compatibility with configuration files for previ- + ous versions of latexmk, which didn't use placeholders. + + "Detaching" a command: Normally when latexmk runs a command, it waits + for the command to run to completion. This is appropriate for commands + like latex, of course. But for previewers, the command should normally + run detached, so that latexmk gets the previewer running and then + returns to its next task (or exits if there is nothing else to do). To + achieve this effect of detaching a command, you need to precede the + command name with "start ", as in + + $dvi_previewer = 'start xdvi %O %S'; + + This will be translated to whatever is appropriate for your operating + system. + + Notes: (1) In some circumstances, latex will always run a command + detached. This is the case for a previewer in preview continuous mode, + since otherwise previewing continuously makes no sense. (2) This pre- + cludes the possibility of running a command named start. (3) If the + word start occurs more than once at the beginning of the command + string, that is equivalent to having just one. (4) Under cygwin, some + complications happen, since cygwin amounts to a complicated merging of + UNIX and MS-Windows. See the source code for how I've handled the + problem. + + Command names containing spaces: Under MS-Windows it is common that the + name of a command includes spaces, since software is often installed in + a subdirectory of "C:Program Files". Such command names should be + enclosed in double quotes, as in + + $lpr_pdf = '"c:/Program Files/Ghostgum/gsview/gsview32.exe" /p + %S'; + + Using MS-Windows file associations: A useful trick under modern ver- + sions of MS-Windows (e.g., WinXP) is to use just the command + + $dvi_previewer = 'start %S'; + + Under recent versions of MS-Windows, this will cause to be run whatever + program the system has associated with dvi files. (The same applies + + + + 28 September 2008 11 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + for a postscript viewer and a pdf viewer.) + + Not using a certain command: If a command is not to be run, the command + name NONE is used, as in + + $lpr = 'NONE lpr'; + + This typically is used when an appropriate command does not exist on + your system. The string after the "NONE" is effectively a comment. + + Options to commands: Setting the name of a command can be used not only + for changing the name of the command called, but also to add options to + command. Suppose you want latexmk to use latex with source specials + enabled. Then you might use the following line in an initialization + file: + + $latex = 'latex --src-specials %O %S'; + + + Advanced tricks: Normally one specifies a single command for the com- + mands invoked by latexmk. Naturally, if there is some complicated + additional processing you need to do in your special situation, you can + write a script (or batch file) to do the processing, and then configure + latexmk to use your script in place of the standard program. + + It is also possible to configure latexmk to run multiple commands. For + example, if when running pdflatex to generate a pdf file from a tex + file you need to run another program after pdflatex to perform some + extra processing, you could do something like: + + $pdflatex = 'pdflatex --shell-escape %O %S; pst2pdf_for_latexmk + %B'; + + This definition assumes you are using a UNIX-like system, so that the + two commands to be run are separated by the semicolon in the middle of + the string. + + + +LIST OF CONFIGURATION VARIABLES USABLE IN INITIALIZATION FILES + Default values are indicated in brackets. + + $banner [0] + If nonzero, the banner message is printed across each page when + converting the dvi file to postscript. Without modifying the + variable $banner_message, this is equivalent to specifying the + -d option. + + Note that if $banner is nonzero, the $postscript_mode is assumed + and the postscript file is always generated, even if it is newer + than the dvi file. + + $banner_intensity [0.95] + Equivalent to the -bi option, this is a decimal number between 0 + and 1 that specifies how dark to print the banner message. 0 is + + + + 28 September 2008 12 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + black, 1 is white. The default is just right if your toner car- + tridge isn't running too low. + + $banner_message ["DRAFT"] + The banner message to print across each page when converting the + dvi file to postscript. This is equivalent to the -bm option. + + $banner_scale [220.0] + A decimal number that specifies how large the banner message + will be printed. Experimentation is necessary to get the right + scale for your message, as a rule of thumb the scale should be + about equal to 1100 divided by the number of characters in the + message. The Default is just right for 5 character messages. + This is equivalent to the -bs option. + + @BIBINPUTS + This is an array variable, now mostly obsolete, that specifies + directories where latexmk should look for .bib files. By + default it is set from the BIBINPUTS environment variable of the + operating system. If that environment variable is not set, a + single element list consisting of the current directory is set. + The format of the directory names depends on your operating sys- + tem, of course. Examples for setting this variable are: + + @BIBINPUTS = ( ".", "C:\bibfiles" ); + @BIBINPUTS = ( ".", "\\server\bibfiles" ); + @BIBINPUTS = ( ".", "C:/bibfiles" ); + @BIBINPUTS = ( ".", "//server/bibfiles" ); + @BIBINPUTS = ( ".", "/usr/local/texmf/bibtex/bib" ); + + Note that under MS Windows, either a forward slash "/" or a + backward slash "\" can be used to separate pathname components, + so the first two and the second two examples are equivalent. + Each backward slash should be doubled to avoid running afoul of + Perl's rules for writing strings. + + Important note: This variable is now mostly obsolete in the current + version of latexmk, since it has a better method of searching for files + using the kpsewhich command. However, if your system is an unusual one + without the kpsewhich command, you may need to set the variable @BIBIN- + PUTS. + + $bibtex ["bibtex %O %S"] + The BibTeX processing program. + + $bibtex_silent_switch ["-terse"] + Switch(es) for the BibTeX processing program when silent mode is + on. + + $cleanup_mode [0] + If nonzero, specifies cleanup mode: 1 for full cleanup, 2 for + cleanup except for dvi, ps and pdf files, 3 for cleanup except + for dep and aux files. (There is also extra cleaning as speci- + fied by the $clean_ext, $clean_full_ext and @generated_exts + variables.) + + + + 28 September 2008 13 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + This variable is equivalent to specifying one of the -c, -c1, or -C + options. But there should be no need to set this variable from an RC + file. + + $clean_ext [""] + Extra extensions of files for latexmk to remove when any of the + clean-up options (-c, -c1, or -C) is selected. The value of + this variable is a string containing the extensions separated by + spaces. + + $clean_full_ext [""] + Extra extensions of files for latexmk to remove when the -C + option is selected, i.e., extensions of files to remove when the + .dvi, etc files are to be cleaned-up. + + @cus_dep_list [()] + Custom dependency list -- see section on "Custom Dependencies". + + @default_files [("*.tex")] + Default list of files to be processed. + + Normally, if no filenames are specified on the command line, + latexmk processes all tex files specified in the @default_files + variable, which by default is set to all tex files ("*.tex") in + the current directory. This is a convenience: just run latexmk + and it will process an appropriate set of files. But sometimes + you want only some of these files to be processed. In this case + you set the @default_files in an initialization file (e.g., the + file "latexmkrc" in the current directory). Then if no files + are specified on the command line then the files you specify by + setting @default_files are processed. + + Three examples: + + @default_files = ("paper_current"); + + @default_files = ("paper1", "paper2.tex"); + + @default_files = ("*.tex", "*.dtx"); + + Note that more than file may be given, and that the default + extension is ".tex". Wild cards are allowed. The parentheses + are because @default_files is an array variable, i.e., a + sequence of filename specifications is possible. + + $dvi_filter [empty] + The dvi file filter to be run on the newly produced dvi file + before other processing. Equivalent to specifying the -dF + option. + + $dvi_mode [0] + If nonzero, generate a dvi version of the document. Equivalent + to the -dvi option. + + $dvi_previewer ["start xdvi %O %S" under UNIX] + The command to invoke a dvi-previewer. [Default is "start" + under MS-WINDOWS; under more recent versions of Windows, this + + + + 28 September 2008 14 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + will cause to be run whatever command the system has associated + with .dvi files.] + + $dvi_previewer_landscape ["start xdvi %O %S"] + The command to invoke a dvi-previewer in landscape mode. + [Default is "start" under MS-WINDOWS; under more recent versions + of Windows, this will cause to be run whatever command the sys- + tem has associated with .dvi files.] + + $dvipdf ["dvipdf %O %S %D"] + Command to convert dvi to pdf file. A common reconfiguration is + to use the dvipdfm command, which needs its arguments in a dif- + ferent order: + + $dvipdf = "dvipdfm %O -o %D %S"; + + WARNING: The default dvipdf script generates pdf files with + bitmapped fonts, which do not look good when viewed by acroread. + That script should be modified to give dvips the options "-P + pdf" to ensure that type 1 fonts are used in the pdf file. + + $dvips ["dvips %O -o %D %S"] + The program to used as a filter to convert a .dvi file to a .ps + file. If pdf is going to be generated from pdf, then the value + of the $dvips_pdf_switch -- see below -- will be included in the + options substituted for "%O". + + $dvips_landscape ["dvips -tlandscape %O -o %D %S"] + The program to used as a filter to convert a .dvi file to a .ps + file in landscape mode. + + $dvips_pdf_switch ["-P pdf"] + Switch(es) for dvips program when pdf file is to be generated + from ps file. + + $dvips_silent_switch ["-q"] + Switch(es) for dvips program when silent mode is on. + + $dvi_update_command [""] + When the dvi previewer is set to be updated by running a com- + mand, this is the command that is run. See the information for + the variable $dvi_update_method for further information, and see + information on the variable $pdf_update_method for an example + for the analogous case of a pdf previewer. + + $dvi_update_method [2 under UNIX, 1 under MS-Windows] + How the dvi viewer updates its display when the dvi file has + changed. The values here apply equally to the + $pdf_update_method and to the $ps_update_method variables. + 0 => update is automatic, + 1=> manual update by user, which may only mean a mouse click + on the viewer's window or may mean a more serious action. + 2 => Send the signal, whose number is in the variable + $dvi_update_signal. The default value under UNIX is suitable + for xdvi. + 3 => Viewer cannot do an update, because it locks the file. + (As with acroread under MS-Windows.) + + + + 28 September 2008 15 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + 4 => run a command to do the update. The command is speci- + fied by the variable $dvi_update_command. + + See information on the variable $pdf_update_method for an exam- + ple of updating by command. + + $dvi_update_signal [Under UNIX: SIGUSR1, which is a system-dependent + value] + The number of the signal that is sent to the dvi viewer when it + is updated by sending a signal -- see the information on the + variable $dvi_update_method. The default value is the one + appropriate for xdvi on a UNIX system. + + $fdb_ext ["fdb_latexmk"] + The extension of the file which latexmk generates to contain a + database of information on source files. You will not normally + need to change this. + + $force_mode [0] + If nonzero, continue processing past minor latex errors includ- + ing unrecognized cross references. Equivalent to specifying the + -f option. + + @generated_exts [( aux , bbl , idx , ind , lof , lot , out , toc , + $fdb_ext )] + This contains a list of extensions for files that are generated + during a LaTeX run and that are read in by LaTeX in later runs, + either directly or indirectly. + + This list has two uses: (a) to set the kinds of file to be + deleted in a cleanup operation (with the -c, -C, -CA, -g and -gg + options), and (b) in the determination of whether a rerun of + (pdf)LaTeX is needed after a run that gives an error. + + (Normally, a change of a source file during a run should provoke + a rerun. This includes a file generated by LaTeX, e.g., an aux + file, that is read in on subsequent runs. But after a run that + results in an error, a new run should occur until the user has + made a change in the files. But the user may have corrected an + error in a source .tex file during the run. So latexmk needs to + distinguish user-generated and automatically generated files; it + determines the automatically generated files as those with + extensions in the list in @generated_exts.) + + A convenient way to add an extra extension to the list, without + losing the already defined ones is to use a push command in the + line in an RC file. E.g., + + push @generated_exts, "end"; + + adds the extension "end" to the list of predefined generated + extensions. (This extension is used by the RevTeX package, for + example.) + + $go_mode [0] + If nonzero, process files regardless of timestamps, and is then + equivalent to the -g option. + + + + 28 September 2008 16 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + %hash_calc_ignore_pattern + !!!This variable is for experts only!!! + + The general rule latexmk uses for determining when an extra run + of some program is needed is that one of the source files has + changed. But consider for example a latex package that causes + an encapsulated postscript file (an "eps" file) to be made that + is to be read in on the next run. The file contains a comment + line giving its creation date and time. On the next run the + time changes, latex sees that the eps file has changed, and + therefore reruns latex. This causes an infinite loop, only + exited becaues latexmk has a limit on the number of runs to + guard against pathological situations. + + But the changing line has no real effect, since it is a comment. + You can instruct latex to ignore the offending line as follows: + + $hash_calc_ignore_pattern{'eps'} = '^%%CreationDate: '; + + This creates a rule for files with extension .eps about lines to + ignore. The left-hand side is a Perl idiom for setting an item + in a hash. Note that the file extension is specified without a + period. The value, on the right-hand side, is a string contain- + ing a regular expresssion. (See documentation on Perl for how + they are to be specified in general.) This particular regular + expression specifies that lines beginning with "%%CreationDate: + " are to be ignored in deciding whether a file of the given + extension .eps has changed. + + $kpsewhich ["kpsewhich %S"] + The program called to locate a source file when the name alone + is not sufficient. Most filenames used by latexmk have suffi- + cient path information to be found directly. But sometimes, + notably when the file, but not its path is known. The program + specified by $kpsewhich is used to find it. + + See also the @BIBINPUTS variable for another way that latexmk + also uses to try to locate files; it applies only in the case of + .bib files. + + $landscape_mode [0] + If nonzero, run in landscape mode, using the landscape mode pre- + viewers and dvi to postscript converters. Equivalent to the -l + option. Normally not needed with current previewers. + + $latex ["latex %O %S"] + The LaTeX processing program. Note that as with other programs, + you can use this variable not just to change the name of the + program used, but also specify options to the program. E.g., + + $latex = "latex --src-specials"; + + $latex_silent_switch ["-interaction=batchmode"] + Switch(es) for the LaTeX processing program when silent mode is + on. Under MS-Windows, the default value is changed to "-inter- + action=batchmode -c-style-errors", as used by MikTeX and fpTeX. + + + + + 28 September 2008 17 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + $lpr ["lpr %O %S" under UNIX/LINUX, "NONE lpr" under MS-WINDOWS] + The command to print postscript files. + + Under MS-Windows (unlike UNIX/LINUX), there is no standard pro- + gram for printing files. But there are ways you can do it. For + example, if you have gsview installed, you could use it with the + option "/p": + + $lpr = '"c:/Program Files/Ghostgum/gsview/gsview32.exe" /p'; + + If gsview is installed in a different directory, you will need + to make the appropriate change. Note the combination of single + and double quotes around the name. The single quotes specify + that this is a string to be assigned to the configuration vari- + able $lpr. The double quotes are part of the string passed to + the operating system to get the command obeyed; this is neces- + sary because one part of the command name ("Program Files") con- + tains a space which would otherwise be misinterpreted. + + $lpr_dvi ["NONE lpr_dvi"] + The printing program to print dvi files. + + $lpr_pdf ["NONE lpr_pdf"] + The printing program to print pdf files. + + Under MS-Windows you could set this to use gsview, if it is + installed, e.g., + + $lpr = '"c:/Program Files/Ghostgum/gsview/gsview32.exe" /p'; + + If gsview is installed in a different directory, you will need + to make the appropriate change. Note the double quotes around + the name: this is necessary because one part of the command name + ("Program Files") contains a space which would otherwise be mis- + interpreted. + + + $makeindex ["makeindex %O -o %D %S"] + The index processing program. + + $max_repeat [5] + The maximum number of times latexmk will run latex/pdflatex + before deciding that there may be an infinite loop and that it + needs to bail out, rather than rerunning latex/pdflatex again to + resolve cross-references, etc. The default value covers all + normal cases. + + (Note that the "etc" covers a lot of cases where one run of + latex/pdflatex generates files to be read in on a later run.) + + $new_viewer_always [0] + This variable applies to latexmk only in continuous-preview + mode. If $new_viewer_always is 0, latexmk will check for a pre- + viously running previewer on the same file, and if one is run- + ning will not start a new one. If $new_viewer_always is non- + zero, this check will be skipped, and latexmk will behave as if + no viewer is running. + + + + 28 September 2008 18 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + $pdf_mode [0] + If zero, do NOT generate a pdf version of the document. If + equal to 1, generate a pdf version of the document using pdfla- + tex. If equal to 2, generate a pdf version of the document from + the ps file, by using the command specified by the $ps2pdf vari- + able. If equal to 3, generate a pdf version of the document + from the dvi file, by using the command specified by the $dvipdf + variable. + + Equivalent to the -pdf-, -pdf, -pdfdvi, -pdfps options. + + $pdflatex ["pdflatex %O %S"] + The LaTeX processing program in the version that makes a pdf + file instead of a dvi file. + + $pdflatex_silent_switch ["-interaction=batchmode"] + Switch(es) for the pdflatex program (specified in the variable + $pdflatex when silent mode is on. Under MS-Windows, the default + value is changed to "-interaction=batchmode -c-style-errors", as + used by MikTeX and fpTeX. + + $pdf_previewer ["start acroread %O %S"] + The command to invoke a pdf-previewer. [Default is changed to + "start" on MS-WINDOWS; under more recent versions of Windows, + this will cause to be run whatever command the system has asso- + ciated with .pdf files.] + + WARNING: Potential problem under MS-Windows: if acroread is used + as the pdf previewer, and it is actually viewing a pdf file, the + pdf file cannot be updated. Thus makes acroread a bad choice of + previewer if you use latexmk's previous-continuous mode (option + -pvc) under MS-windows. This problem does not occur if + ghostview, gv or gsview is used to view pdf files. + + $pdf_update_command [""] + When the pdf previewer is set to be updated by running a com- + mand, this is the command that is run. See the information for + the variable $pdf_update_method. + + $pdf_update_method [1 under UNIX, 3 under MS-Windows] + How the pdf viewer updates its display when the pdf file has + changed. See the information on the variable $dvi_update_method + for the codes. (Note that information needs be changed slightly + so that for the value 4, to run a command to do the update, the + command is specified by the variable $pdf_update_command, and + for the value 2, to specify update by signal, the signal is + specified by $pdf_update_signal.) + + Note that acroread under MS-Windows (but not UNIX) locks the pdf + file, so the default value is then 3. + + Arranging to use a command to get a previewer explicitly updated + requires three variables to be set. For example: + + $pdf_previewer = "start xpdf -remote %R %O %S"; + $pdf_update_method = 4; + $pdf_update_command = "xpdf -remote %R -reload"; + + + + 28 September 2008 19 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + The first setting arranges for the xpdf program to be used in + its "remote server mode", with the server name specified as the + rootname of the TeX file. The second setting arranges for + updating to be done in response to a command, and the third set- + ting sets the update command. + + + $pdf_update_signal [Under UNIX: SIGHUP, which is a system-dependent + value] + The number of the signal that is sent to the pdf viewer when it + is updated by sending a signal -- see the information on the + variable $pdf_update_method. The default value is the one + appropriate for gv on a UNIX system. + + $pid_position[1 under UNIX, -1 under MS-Windows] + The variable $pid_position is used to specify which word in + lines of the output from $pscmd corresponds to the process ID. + The first word in the line is numbered 0. The default value of + 1 (2nd word in line) is correct for Solaris 2.6 and Linux. Set- + ting the variable to -1 is used to indicate that $pscmd is not + to be used. + + $postscript_mode [0] + If nonzero, generate a postscript version of the document. + Equivalent to the -ps option. + + $preview_continuous_mode [0] + If nonzero, run a previewer to view the document, and continue + running latexmk to keep .dvi up-to-date. Equivalent to the -pvc + option. Which previewer is run depends on the other settings, + see the command line options -view=, and the variable $view. + + $preview_mode [0] + If nonzero, run a previewer to preview the document. Equivalent + to the -pv option. Which previewer is run depends on the other + settings, see the command line options -view=, and the variable + $view. + + $printout_mode [0] + If nonzero, print the document using lpr. Equivalent to the -p + option. This is recommended not to be set from an RC file, oth- + erwise you could waste lots of paper. + + $print_type = ["ps"] + Type of file to printout: possibilities are "dvi", "none", + "pdf", or "ps". + + $pscmd Command used to get all the processes currently run by the user. + The -pvc option uses the command specified by the variable + $pscmd to determine if there is an already running previewer, + and to find the process ID (needed if latexmk needs to signal + the previewer about file changes). + + Each line of the output of this command is assumed to correspond + to one process. See the $pid_position variable for how the pro- + cess number is determined. + + + + + 28 September 2008 20 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + The default for pscmd is "NONE" under MS-Windows and cygwin + (i.e., the command is not used), "ps --width 200 -f -u + $ENV{USER}" under linux, "ps -ww -u $ENV{USER}" under darwin + (Macintosh OS-X), and "ps -f -u $ENV{USER}" under other operat- + ing systems (including other flavors of UNIX). In these speci- + fications "$ENV{USER}" is substituted by the username. + + $ps2pdf ["ps2pdf %O %S %D"] + Command to convert ps to pdf file. + + $ps_filter [empty] + The postscript file filter to be run on the newly produced + postscript file before other processing. Equivalent to specify- + ing the -pF option. + + $ps_previewer ["start gv %O %S", but "start %O %S" under MS-WINDOWS] + The command to invoke a ps-previewer. (The default under MS- + WINDOWS will cause to be run whatever command the system has + associated with .ps files.) + + Note that gv could be used with the -watch option updates its + display whenever the postscript file changes, whereas ghostview + does not. However, different versions of gv have slightly dif- + ferent ways of writing this option. You can configure this + variable apppropriately. + + WARNING: Linux systems may have installed one (or more) versions + of gv under different names, e.g., ggv, kghostview, etc, but + perhaps not one called gv. + + $ps_previewer_landscape ["start gv -swap %O %S", but "start %O %S" + under MS-WINDOWS] + The command to invoke a ps-previewer in landscape mode. + + $ps_update_command [""] + When the postscript previewer is set to be updated by running a + command, this is the command that is run. See the information + for the variable $ps_update_method. + + $ps_update_method [0 under UNIX, 1 under MS-Windows] + How the postscript viewer updates its display when the ps file + has changed. See the information on the variable + $dvi_update_method for the codes. (Note that information needs + be changed slightly so that for the value 4, to run a command to + do the update, the command is specified by the variable + $ps_update_command, and for the value 2, to specify update by + signal, the signal is specified by $ps_update_signal.) + + + $ps_update_signal [Under UNIX: SIGHUP, which is a system-dependent + value] + The number of the signal that is sent to the pdf viewer when it + is updated by sending a signal -- see $ps_update_method. The + default value is the one appropriate for gv on a UNIX system. + + $sleep_time [2] + The time to sleep (in seconds) between checking for source file + changes when running the -pvc option. + + + + 28 September 2008 21 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + $texfile_search [""] + This is an obsolete variable, replaced by the @default_files + variable. + + For backward compatibility, if you choose to set $tex- + file_search, it is a string of space-separated filenames, and + then latexmk replaces @default_files with the filenames in $tex- + file_search to which is added "*.tex". + + $tmpdir [See below for default] + Directory to store temporary files that latexmk may generate + while running. + + The default under MSWindows (including cygwin), is to set + $tmpdir to the value of the first of whichever of the system + environment variables TMPDIR or TEMP exists, otherwise to the + current directory. Under other operating systems (expected to + be UNIX/Linux, including OS-X), the default is the value of the + system environment variable TMPDIR if it exists, otherwise + "/tmp". + + $view ["default"] + Which kind of file is to be previewed if a previewer is used. + The possible values are "default", "dvi", "ps", "pdf". The + value of "default" means that the "highest" of the kinds of file + generated is to be used (among dvi, ps and pdf). + + +CUSTOM DEPENDENCIES + In any RC file a set of custom dependencies can be set up to convert a + file with one extension to a file with another. An example use of this + would be to allow latexmk to convert a .fig file to .eps to be included + in the .tex file. + + The old method of configuring latexmk was to directly manipulate the + @cus_dep_list array that contains information defining the custom + dependencies. This method still works. But now there are subroutines + that allow convenient manipulations of the custom dependency list. + These are + + add_cus_dep( fromextension, toextension, must, subroutine ) + remove_cus_dep( fromextension, toextension ) + show_cus_dep() + + The custom dependency is a list of rules, each of which is specified as + follow: + + from extension: + The extension of the file we are converting from (e.g. "fig"). + It is specified without a period. + + to extension: + The extension of the file we are converting to (e.g. "eps"). It + is specified without a period. + + must: If non-zero, the file from which we are converting must exist, + if it doesn't exist latexmk will give an error message and exit + unless the -f option is specified. If must is zero and the file + + + + 28 September 2008 22 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + we are converting from doesn't exist, then no action is taken. + + function: + The name of the subroutine that latexmk should call to perform + the file conversion. The first argument to the subroutine is + the base name of the file to be converted without any extension. + The subroutines are declared in the syntax of Perl. The func- + tion should return 0 if it was successful and a nonzero number + if it failed. + + It is invoked whenever latexmk detects that a run of latex/pdflatex + needs to read a file, like a graphics file, whose extension is the to- + extension of a custom dependency. Then latexmk examines whether a file + exists with the same name, but with the corresponding from-extension, + as specified in the custom-dependency rule. If it does, then whenever + the destination file (the one with the to-extension) is out-of-date + with respect to the corresponding source file. + + To make the new destination file, the Perl subroutine specified in the + rule is invoked, with an argument that is the base name of the files in + question. Simple cases just involve a subroutine invoking an external + program; this can be done by following the templates below, even by + those without knowledge of the Perl programming language. Of course, + experts could do something much more elaborate. + + One other item in each custom-dependency rule labelled "must" above + specifies how the rule should be applied when the source file fails to + exist. + + A simple and typical example of code in an initialization rcfile is + + add_cus_dep( 'fig', 'eps', 0, 'fig2eps' ); + sub fig2eps { + system("fig2dev -Leps $_[0].fig $_[0].eps"); + } + + The first line adds a custom dependency that converts a file with + extension "fig", as created by the xfig program, to an encapsulated + postscript file, with extension "eps". The remaining lines define a + subroutine that carries out the conversion. If a rule for converting + "fig" to "eps" files already exists (e.g., from a previously read-in + initialization file), the latexmk will delete this rule before making + the new one. + + Suppose latexmk is using this rule to convert a file "figure.fig" to + "figure.eps". Then it will invoke the fig2eps subroutine defined in + the above code with a single argument "figure", which is the basename + of each of the files (possibly with a path component). This argument + is referred to by Perl as $_[0]. In the example above, the subroutine + uses the Perl command system to invoke the program fig2dev. The double + quotes around the string are a Perl idiom that signify that each string + of the form of a variable name, $_[0] in this case, is to be substi- + tuted by its value. + + If the return value of the subroutine is non-zero, then latexmk will + assume an error occurred during the execution of the subroutine. In + the above example, no explicit return value is given, and instead the + return value is the value returned by the last (and only) statement, + + + + 28 September 2008 23 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + i.e., the invocation of system, which returns the value 0 on success. + + If you use filenames with spaces in them, and if your LaTeX system and + all other relevant software correctly handle such filenames, then you + could put single quotes around filenames in the command line that is + executed: + + add_cus_dep( 'fig', 'eps', 0, 'fig2eps' ); + sub fig2eps { + system("fig2dev -Lps '$_[0].fig' '$_[0].eps'"); + } + + This causes the invocation of the fig2dev program to have quoted file- + names; it should therefore work with filenames containing spaces. How- + ever, not all software deals correctly with filenames that contain + spaces. Moreover, the rules, if any, for quoting filenames vary + between operating systems, command shells and individual pieces of + software, so this code may not always work. + + If you use pdflatex instead of latex, then you will probably prefer to + convert your graphics files to pdf format, in which case you would + replace the above code in an initialization file by + + add_cus_dep( 'fig', 'pdf, 0, 'fig2pdf' ); + sub fig2pdf { + system("fig2dev -Lpdf $_[0].fig $_[0].pdf"); + } + + If you have some general custom dependencies defined in the system or + user initialization file, you may find that for a particular project + they are undesirable. So you might want to delete the unneeded ones. + For example, you remove any "fig" to "eps" rule by the line + + remove_cus_dep( 'fig', 'eps' ); + + If you have complicated sets of custom dependencies, you may want to + get a listing of the custom dependencies. This is done by using the + line + + show_cus_dep(); + + in an initialization file. + + Another example of a custom dependency overcomes a limitation of + latexmk concerning index files. The only index-file conversion built- + in to latexmk is from an ".idx" file written on one run of latex/pdfla- + tex to an ".ind" file to be read in on a subsequent run. But with the + index.sty package you can create extra indexes with extensions that you + configure. Latexmk does not know how to deduce the extensions from the + information it has. But you can easily write a custom dependency. For + example if your latex file uses the command "\newindex{spe- + cial}{ndx}{nnd}{Special index}" you will need to convert files with the + extension .ndx to .nnd. The following lines in an initialization RC + file will cause this to happen: + + add_cus_dep('ndx', 'nnd', 0, 'makendx2nnd'); + sub makendx2nnd { + system("makeindex -o $_[0].nnd $_[0].ndx"); + + + + 28 September 2008 24 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + } + + (You will need to modify this code if you use filenames with spaces in + them, to provide correct quoting of the filenames.) + + Those of you with experience with Makefiles, will undoubtedly be con- + cerned that the .ndx file is written during a run of latex/pdflatex and + is always later than the .nnd last read in. Thus the .nnd appears to + be perpetually out-of-date. This situation, of circular dependencies, + is endemic to latex, and latexmk in its current version works correctly + with circular dependencies. It examines the contents of the files (by + use of an md5 checksum), and only does a remake when the file contents + have actually changed. + + Of course if you choose to write random data to the .nnd (or and .aux + file, etc) that changes on each new run, then you will have a problem. + For real experts: See the %hash_cal_ignore_pattern if you have to deal + with such problems. + + Glossaries can be dealt with similarly. + + +OLD METHOD OF DEFINING CUSTOM DEPENDENCIES + In previous versions of latexmk, the only method of defining custom + dependencies was to directly manipulate the table of custom dependen- + cies. This is contained in the @cus_dep_list array. It is an array of + strings, and each string in the array has four items in it, each sepa- + rated by a space, the from-extension, the to-extension, the "must" + item, and the name of the subroutine for the custom dependency. These + were all defined above. + + An example of the old method of defining custom dependencies is as fol- + lows. It is the code in an RC file to ensure automatic conversion of + .fig files to .eps files: + + push @cus_dep_list, "fig eps 0 fig2eps"; + sub fig2eps { + system("fig2dev -Lps $_[0].fig $_[0].eps"); + } + + This method still works, and is equivalent to the earlier code using + the add_cus_dep subroutine, except that it doesn't delete any previous + custom-dependency for the same conversion. So the new method is + preferable. + + +SEE ALSO + latex(1), bibtex(1). + +BUGS + Sometimes a viewer (gv) tries to read an updated .ps or .pdf file after + its creation is started but before the file is complete. Work around: + manually refresh (or reopen) display. Or use one of the other preview- + ers and update methods. + + (The following isn't really a bug, but concerns features of preview- + ers.) Preview continuous mode only works perfectly with certain pre- + viewers: Xdvi on UNIX/LINUX works for dvi files. Gv on UNIX/LINUX + + + + 28 September 2008 25 + + + + + +LATEXMK(1L) LATEXMK(1L) + + + works for both postscript and pdf. Ghostview on UNIX/LINUX needs a + manual update (reopen); it views postscript and pdf. Gsview under MS- + Windows works for both postscript and pdf, but only reads the updated + file when its screen is refreshed. Acroread under UNIX/LINUX views + pdf, but the file needs to be closed and reopened to view an updated + version. Under MS-Windows, acroread locks its input file and so the + pdf file cannot be updated. (Remedy: configure latexmk to use gsview + instead.) + +THANKS TO + Authors of previous versions. Many users with their feedback, and + especially David Coppit (username david at node coppit.org) who made + many useful suggestions that contributed to version 3, and Herbert + Schulz. (Please note that the e-mail addresses are not written in + their standard form to avoid being harvested by worms and viruses.) + +AUTHOR + Current version, by John Collins (username collins at node + phys.psu.edu). (Version 4.01). + + It can be obtained from CTAN: <http://www.tug.org/tex-archive/sup- + port/latexmk/>, and from the author's website + <http://www.phys.psu.edu/~collins/software/latexmk/>. + Modifications and enhancements by Evan McLean (Version 2.0) + Original script called "go" by David J. Musliner (RCS Version 3.2) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 28 September 2008 26 + + diff --git a/Master/texmf-dist/scripts/latexmk/latexmk.pl b/Master/texmf-dist/scripts/latexmk/latexmk.pl new file mode 100755 index 00000000000..4d124a67893 --- /dev/null +++ b/Master/texmf-dist/scripts/latexmk/latexmk.pl @@ -0,0 +1,6031 @@ +eval '(exit $?0)' && eval 'exec perl -x -S "$0" ${1+"$@"}' && +eval 'exec perl -x -S "$0" $argv:q' +if 0; +#!/usr/bin/perl -w +#!/opt/local/bin/perl -w +#!/usr/local/bin/perl -w +# The above code allows this script to be run under UNIX/LINUX without +# the need to adjust the path to the perl program in a "shebang" line. +# (The location of perl changes between different installations, and +# may even be different when several computers running different +# flavors of UNIX/LINUX share a copy of latex or other scripts.) The +# script is started under the default command interpreter sh, and the +# evals in the first two lines restart the script under perl, and work +# under various flavors of sh. The -x switch tells perl to start the +# script at the first #! line containing "perl". The "if 0;" on the +# 3rd line converts the first two lines into a valid perl statement +# that does nothing. +# +# Source of the above: manpage for perlrun + +# Delete #??!! when working + +# See ?? <=============================== + +# Results of 8 Sep 2007: + +# Some improvements relative to the issues below. + +# ????????: +# Why is bibtex not always running right? Or running when it shouldn't +# I've put in rdb_make_links in a few places. +# and rdb_write +# Problem is that aux file is always out of date, until after a +# primary run. Ensure fdb and c. is updated enough etc. +# I may have it correct now: fdb_write in makeB +# See also routine rdb_update_files_for_rule, and who calls it + +# Apparently excess runs of latex after change in .tex file that entails +# change in bibliography. + +# Now I am missing diagnostics + + +## ???!!!!!!!!!!!!! Should I remove bibtex rule? NO +## ?? Need to set dependence of extra bibtex rules on .bib file +## ?? Put $pass as variable in rule. + +#======================================= + + +#?? Check all code for rdb stuff. +#?? Use of $update and $failure, etc +# Especially in pvc. Should I restore source file set up +# if there is a latex error?????????????????????? +#?? Force mode doesn't appear to do force (if error in latex file) +#??? Get banner back in. +#?? ==> Clean up of rdb. It accumulates files that aren't in use any more. +# Restrict to dependents (existent or not) discovered during +# parse of log file, and its consequences. +#?? CORRECT DIAGNOSTICS ON CHANGED FILES IF THEY DIDN'T EXIST BEFORE +#?? Further corrections to deal with disappeared source files for custom dependencies. +# Message repeatedly appears about remake when source file of cusdep doesn't exist. +#?? logfile w/o fdb file: don't set changed file, perhaps for generated exts. +# Reconsider +#?? Do proper run-stuff for bibtex, makeindex, cus-deps. OK I think +# Parse and correctly find bst and ist files +#?? Remove superfluous code when it's working. Mostly done. +#?? update_source_times in particular. I think it's done OK +#?? Add making of other files to rdb. Unify +#?? Ditto for printing and viewing? +#?? Update documentation + +# ATTEMPT TO ALLOW FILENAMES WITH SPACES: +# (as of 1 Apr 2006, and then 14 Sep. 2007) + +# Problems: +# A. Quoting filenames will not always work. +# a. Under UNIX, quotes are legal in filenames, so when PERL +# directly runs a binary, a quoted filename will be treated as +# as a filename containing a quote character. But when it calls +# a shell, the quotes are handled by the shell as quotes. +# b. Under MSWin32, quotes are illegal filename characters, and tend +# to be handled correctly. +# c. But under cygwin, results are not so clear (there are many +# combinations: native v. cygwin perl, native v cygwin programs +# NT v. unix scripts, which shell is called. +# B. TeX doesn't always handle filenames with spaces gracefully. +# a. UNIX/LINUX: The version on gluon2 Mar 31, 2006 to Sep. 2007) +# doesn't handle them at all. (TeX treats space as separator.) +# b. At least some later versions actually do (Brad Miller e-mail, +# Sep. 2007). +# c. fptex [[e-TeXk, Version 3.141592-2.1 (Web2c 7.5.2)] does, on +# my MSWin at home. In \input the filename must be in quotes. +# d. Bibtex [BibTeX (Web2c 7.5.2) 0.99c on my MSWin system at home, +# Sep. 2007] does not allow names of bibfiles to have spaces. +# C. =====> Using the shell for command lines is not safe, since special +# characters can cause lots of mayhem. +# It will therefore be a good idea to sanitize filenames. +# +# I've sanitized all calls out: +# a. system and exec use a single argument, which forces +# use of shell, under all circumstances +# Thus I can safely use quotes on filenames: They will be handled by +# the shell under UNIX, and simply passed on to the program under MSWin32. +# b. I reorganized Run, Run_Detached to use single command line +# c. All calls to Run and Run_Detached have quoted filenames. +# d. So if a space-free filename with wildcards is given on latexmk's +# command line, and it globs to space-containing filename(s), that +# works (fptex on home computer, native NT tex) +# e. ====> But globbing fails: the glob function takes space as filename +# separator. ==================== + +#================= TO DO ================ +# +# 1. See ?? ESPECIALLY $MSWin_fudge_break +# 2. Check fudged conditions in looping and make_files +# 3. Should not completely abort after a run that ends in failure from latex +# Missing input files (including via custom dependency) should be checked for +# a change in status +# If sources for missing files from custom dependency +# are available, then do a rerun +# If sources of any kind become available rerun (esp. for pvc) +# rerun +# Must parse log_file after unsuccessful run of latex: it may give +# information about missing files. +# 4. Check file of bug reports and requests +# 5. Rationalize bibtex warnings and errors. Two almost identical routines. +# Should 1. Use single routine +# 2. Convert errors to failure only in calling routine +# 3. Save first warning/error. + + +# To do: +# Rationalize again handling of include files. +# Now I use kpsewhich to do searches, if file not found +# (How do I avoid getting slowed down too much?) +# Better parsing of log file for includes. +# Document the assumptions at each stage of processing algorithm. +# Option to restart previewer automatically, if it dies under -pvc +# Test for already running previewer gets wrong answer if another +# process has the viewed file in its command line + +$my_name = 'latexmk'; +$My_name = 'Latexmk'; +$version_num = '4.01'; +$version_details = "$My_name, John Collins, 24 September 2008"; + + +use Config; +use File::Copy; +use File::Basename; +use FileHandle; +use File::Find; +use Cwd; # To be able to change cwd +use Cwd "chdir"; # Ensure $ENV{PWD} tracks cwd +use Digest; + +#use strict; + +# The following variables are assigned once and then used in symbolic +# references, so we need to avoid warnings 'name used only once': +use vars qw( $dvi_update_command $ps_update_command $pdf_update_command ); + +# Translation of signal names to numbers and vv: +%signo = (); +@signame = (); +if ( defined $Config{sig_name} ) { + $i = 0; + foreach $name (split(' ', $Config{sig_name})) { + $signo{$name} = $i; + $signame[$i] = $name; + $i++; + } +} +else { + warn "Something wrong with the perl configuration: No signals?\n"; +} + +## Copyright John Collins 1998-2008 +## (username collins at node phys.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 +## +## +## +## NEW FEATURES, since v. 2.0: +## 1. Correct algorithm for deciding how many times to run latex: +## based on whether source file(s) change between runs +## 2. Continuous preview works, and can be of ps file or dvi file +## 3. pdf creation by pdflatex possible +## 4. Defaults for commands are OS dependent. +## 5. Parsing of log file instead of source file is used to +## obtain dependencies, by default. +## +## Modification log for 28 Mar 2007 onwards in detail +## +## 24 Sep 2008, John Collins Release version 4.01. +## +## 1998-2008, John Collins. Many improvements and fixes. +## +## Modified by Evan McLean (no longer available for support) +## Original script (RCS version 2.3) called "go" written by David J. Musliner +## +## 2.0 - Final release, no enhancements. LatexMk is no longer supported +## by the author. +## 1.9 - Fixed bug that was introduced in 1.8 with path name fix. +## - Fixed buglet in man page. +## 1.8 - Add not about announcement mailling list above. +## - Added texput.dvi and texput.aux to files deleted with -c and/or +## the -C options. +## - Added landscape mode (-l option and a bunch of RC variables). +## - Added sensing of "\epsfig{file=...}" forms in dependency generation. +## - Fixed path names when specified tex file is not in the current +## directory. +## - Fixed combined use of -pvc and -s options. +## - Fixed a bunch of speling errors in the source. :-) +## - Fixed bugs in xdvi patches in contrib directory. +## 1.7 - Fixed -pvc continuous viewing to reattach to pre-existing +## process correctly. +## - Added $pscmd to allow changing process grepping for different +## systems. +## 1.6 - Fixed buglet in help message +## - Fixed bugs in detection of input and include files. +## 1.5 - Removed test message I accidentally left in version 1.4 +## - Made dvips use -o option instead of stdout redirection as some +## people had problems with dvips not going to stdout by default. +## - Fixed bug in input and include file detection +## - Fixed dependency resolution process so it detects new .toc file +## and makeindex files properly. +## - Added dvi and postscript filtering options -dF and -pF. +## - Added -v version commmand. +## 1.4 - Fixed bug in -pvc option. +## - Made "-F" option include non-existant file in the dependency list. +## (RC variable: $force_include_mode) +## - Added .lot and .lof files to clean up list of extensions. +## - Added file "texput.log" to list of files to clean for -c. +## - LatexMk now handles file names in a similar fashion to latex. +## The ".tex" extension is no longer enforced. +## - Added $texfile_search RC variable to look for default files. +## - Fixed \input and \include so they add ".tex" extension if necessary. +## - Allow intermixing of file names and options. +## - Added "-d" and banner options (-bm, -bs, and -bi). +## (RC variables: $banner, $banner_message, $banner_scale, +## $banner_intensity, $tmpdir) +## - Fixed "-r" option to detect an command line syntax errors better. +## 1.3 - Added "-F" option, patch supplied by Patrick van der Smagt. +## 1.2 - Added "-C" option. +## - Added $clean_ext and $clean_full_ext variables for RC files. +## - Added custom dependency generation capabilities. +## - Added command line and variable to specify custom RC file. +## - Added reading of rc file in current directly. +## 1.1 - Fixed bug where Dependency file generation header is printed +## rependatively. +## - Fixed bug where TEXINPUTS path is searched for file that was +## specified with absolute an pathname. +## 1.0 - Ripped from script by David J. Musliner (RCS version 2.3) called "go" +## - Fixed a couple of file naming bugs +## e.g. when calling latex, left the ".tex" extension off the end +## of the file name which could do some interesting things +## with some file names. +## - Redirected output of dvips. My version of dvips was a filter. +## - Cleaned up the rc file mumbo jumbo and created a dependency file +## instead. Include dependencies are always searched for if a +## dependency file doesn't exist. The -i option regenerates the +## dependency file. +## Getting rid of the rc file stuff also gave the advantage of +## not being restricted to one tex file per directory. +## - Can specify multiple files on the command line or no files +## on the command line. +## - Removed lpr options stuff. I would guess that generally, +## you always use the same options in which case they can +## be set up from an rc file with the $lpr variable. +## - Removed the dviselect stuff. If I ever get time (or money :-) ) +## I might put it back in if I find myself needing it or people +## express interest in it. +## - Made it possible to view dvi or postscript file automatically +## depending on if -ps option selected. +## - Made specification of dvi file viewer seperate for -pv and -pvc +## options. +##----------------------------------------------------------------------- + + +## 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. + + +#Line length in log file that indicates wrapping. +# This number EXCLUDES line-end characters, and is one-based +$log_wrap = 79; + +######################################################################### +## 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'" +@file_not_found = ( + '^No file\\s*(.*)\\.$', + '^\\! LaTeX Error: File `([^\\\']*)\\\' not found\\.', + '.*?:\\d*: LaTeX Error: File `([^\\\']*)\\\' not found\\.', + '^LaTeX Warning: File `([^\\\']*)\\\' not found', + '^Package .* file `([^\\\']*)\\\' not found', +); + +## 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). +%hash_calc_ignore_pattern =(); + +######################################################################### +## 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. + +## Commands to invoke latex, pdflatex +$latex = 'latex %O %S'; +$pdflatex = 'pdflatex %O %S'; +## Switch(es) to make them silent: +$latex_silent_switch = '-interaction=batchmode'; +$pdflatex_silent_switch = '-interaction=batchmode'; + +## Command to invoke bibtex +$bibtex = 'bibtex %O %B'; +# Switch(es) to make bibtex silent: +$bibtex_silent_switch = '-terse'; + +## Command to invoke makeindex +$makeindex = 'makeindex %O -o %D %S'; +# Switch(es) to make makeinex silent: +$makeindex_silent_switch = '-q'; + +## Command to convert dvi file to pdf file directly: +$dvipdf = 'dvipdf %O %S %D'; + +## Command to convert dvi file to ps file: +$dvips = 'dvips %O -o %D %S'; +## Command to convert dvi file to ps file in landscape format: +$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.) +$dvips_pdf_switch = '-P pdf'; +# Switch(es) to make dvips silent: +$dvips_silent_switch = '-q'; + +## Command to convert ps file to pdf file: +$ps2pdf = 'ps2pdf %O %S %D'; + +## Command to search for tex-related files +$kpsewhich = 'kpsewhich %S'; + + +##Printing: +$print_type = 'ps'; # When printing, print the postscript file. + # Possible values: 'dvi', 'ps', 'pdf', 'none' + +## Which treatment of default extensions and filenames with +## multiple extensions is used, for given filename on +## tex/latex's command line? See sub find_basename for the +## possibilities. +## Current tex's treat extensions like UNIX teTeX: +$extension_treatment = 'unix'; + +$dvi_update_signal = undef; +$ps_update_signal = undef; +$pdf_update_signal = undef; + +$dvi_update_command = undef; +$ps_update_command = undef; +$pdf_update_command = undef; + +$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. + +$quote_filenames = 1; # Quote filenames in external commands + +######################################################################### + +################################################################ +## Special variables for system-dependent fudges, etc. +$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 latemk 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! + + +################################################################ + + +# System-dependent overrides: +if ( $^O eq "MSWin32" ) { +# Pure MSWindows configuration + ## Configuration parameters: + + ## Use first existing case for $tmpdir: + $tmpdir = $ENV{TMPDIR} || $ENV{TEMP} || '.'; + + ## List of possibilities for the system-wide initialization file. + ## The first one found (if any) is used. + @rc_system_files = ( 'C:/latexmk/LatexMk' ); + + $search_path_separator = ';'; # Separator of elements in search_path + + # For both fptex and miktex, the following makes error messages explicit: + $latex_silent_switch = '-interaction=batchmode -c-style-errors'; + $pdflatex_silent_switch = '-interaction=batchmode -c-style-errors'; + + # 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"; + # 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 + $dvi_update_method = 1; + $ps_update_method = 1; + $pdf_update_method = 3; # acroread locks the pdf file + # Use NONE as flag that I am not implementing some commands: + $lpr = + 'NONE $lpr variable is not configured to allow printing of ps files'; + $lpr_dvi = + 'NONE $lpr_dvi variable is not configured to allow printing of dvi files'; + $lpr_pdf = + 'NONE $lpr_pdf variable is not configured to allow printing of pdf files'; + # The $pscmd below holds a 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. + $pscmd = + 'NONE $pscmd variable is not configured to detect running processes'; + $pid_position = -1; # offset of PID in output of pscmd. + # Negative means I cannot use ps +} +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 and TEXINPUTS environment variables may be + # UNIX-style or MSWin-style depending on whether native NT or + # cygwin executables are used. They are therefore parsed + # differently. Here is the clash: + # a. If a user is running under an NT shell, is using a + # native NT installation of tex (e.g., fptex or miktex), + # but has the cygwin executables in the path, then perl + # detects the OS as cygwin, but the user needs NT + # behavior from latexmk. + # b. If a user is running under an UNIX shell in a cygwin + # environment, and is using the cygwin installation of + # tex, then perl detects the OS as cygwin, and the user + # needs UNIX behavior from latexmk. + # Latexmk has no way of detecting the difference. The two + # situations may even arise for the same user on the same + # computer simply by changing the order of directories in the + # path environment variable + + + ## Configuration parameters: We'll assume native NT executables. + ## The user should override if they are not. + + # This may fail: perl converts MSWin temp directory name to cygwin + # format. Names containing this string cannot be handled by native + # NT executables. + $tmpdir = $ENV{TMPDIR} || $ENV{TEMP} || '.'; + + ## List of possibilities for the system-wide initialization file. + ## The first one found (if any) is used. + ## We can stay with MSWin files here, since perl understands them, + @rc_system_files = ( 'C:/latexmk/LatexMk' ); + + $search_path_separator = ';'; # Separator of elements in search_path + # This is tricky. The search_path_separator depends on the kind + # of executable: native NT v. cygwin. + # So the user will have to override this. + + # For both fptex and miktex, the following makes error messages explicit: + $latex_silent_switch = '-interaction=batchmode -c-style-errors'; + $pdflatex_silent_switch = '-interaction=batchmode -c-style-errors'; + + # We will assume that files can be viewed by native NT programs. + # Then we must fix the start command/directive, so that the + # NT-native start command of a cmd.exe is used. + # For a pdf-file, "start x.pdf" starts the pdf viewer associated with + # pdf files, so no program name is needed: + $start_NT = "cmd /c start"; + $pdf_previewer = "$start_NT %O %S"; + $ps_previewer = "$start_NT %O %S"; + $ps_previewer_landscape = $ps_previewer; + $dvi_previewer = "$start_NT %O %S"; + $dvi_previewer_landscape = $dvi_previewer; + # 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) + $dvi_update_method = 1; + $ps_update_method = 1; + $pdf_update_method = 3; # acroread locks the pdf file + # Use NONE as flag that I am not implementing some commands: + $lpr = + 'NONE $lpr variable is not configured to allow printing of ps files'; + $lpr_dvi = + 'NONE $lpr_dvi variable is not configured to allow printing of dvi files'; + $lpr_pdf = + 'NONE $lpr_pdf variable is not configured to allow printing of pdf files'; + # The $pscmd below holds a 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. + # When the OS is detected as cygwin, there are two possibilities: + # a. Latexmk was run from an NT prompt, but cygwin is in the + # path. Then the cygwin ps command will not see commands + # started from latexmk. So we cannot use it. + # b. Latexmk was started within a cygwin environment. Then + # the ps command works as we need. + # Only the user, not latemk knows which, so we default to not + # using the ps command. The user can override this in a + # configuration file. + $pscmd = + 'NONE $pscmd variable is not configured to detect running processes'; + $pid_position = -1; # offset of PID in output of pscmd. + # Negative means I cannot use ps +} +else { + # Assume anything else is UNIX or clone + + ## Configuration parameters: + + + ## Use first existing case for $tmpdir: + $tmpdir = $ENV{TMPDIR} || '/tmp'; + + ## List of possibilities for the system-wide initialization file. + ## The first one found (if any) is used. + ## Normally on a UNIX it will be in a subdirectory of /opt/local/share or + ## /usr/local/share, depending on the local conventions. + ## /usr/local/lib/latexmk/LatexMk is put in the list for + ## compatibility with older versions of latexmk. + @rc_system_files = + ( '/opt/local/share/latexmk/LatexMk', + '/usr/local/share/latexmk/LatexMk', + '/usr/local/lib/latexmk/LatexMk' ); + + $search_path_separator = ':'; # Separator of elements in search_path + + $dvi_update_signal = $signo{USR1} + if ( defined $signo{USR1} ); # Suitable for xdvi + $ps_update_signal = $signo{HUP} + if ( defined $signo{HUP} ); # Suitable for gv + $pdf_update_signal = $signo{HUP} + if ( defined $signo{HUP} ); # Suitable for gv + ## default document processing programs. + # 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 command to update. Command in $dvi_update_command, + # $ps_update_command, $pdf_update_command. + $dvi_previewer = 'start xdvi %O %S'; + $dvi_previewer_landscape = 'start xdvi -paper usr %O %S'; + if ( defined $dvi_update_signal ) { + $dvi_update_method = 2; # xdvi responds to signal to update + } else { + $dvi_update_method = 1; + } +# if ( defined $ps_update_signal ) { +# $ps_update_method = 2; # gv responds to signal to update +# $ps_previewer = 'start gv -nowatch'; +# $ps_previewer_landscape = 'start gv -swap -nowatch'; +# } else { +# $ps_update_method = 0; # gv -watch watches the ps file +# $ps_previewer = 'start gv -watch'; +# $ps_previewer_landscape = 'start gv -swap -watch'; +# } + # Turn off the fancy options for gv. Regular gv likes -watch etc + # GNU gv likes --watch etc. User must configure + $ps_update_method = 0; # gv -watch watches the ps file + $ps_previewer = 'start gv %O %S'; + $ps_previewer_landscape = 'start gv -swap %O %S'; + $pdf_previewer = 'start acroread %O %S'; + $pdf_update_method = 1; # acroread under unix needs manual update + $lpr = 'lpr %O %S'; # Assume lpr command prints postscript files correctly + $lpr_dvi = + 'NONE $lpr_dvi variable is not configured to allow printing of dvi files'; + $lpr_pdf = + 'NONE $lpr_pdf variable is not configured to allow printing of pdf files'; + # The $pscmd below holds a 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. + # Uses: + # 1. In preview_continuous mode, to save running a previewer + # when one is already running on the relevant file. + # 2. With xdvi in preview_continuous mode, xdvi must be + # signalled to make it read a new dvi file. + # + # The following works on Solaris, LINUX, HP-UX, IRIX + # Use -f to get full listing, including command line arguments. + # Use -u $ENV{CMD} to get all processes started by current user (not just + # those associated with current terminal), but none of other users' + # processes. + $pscmd = "ps -f -u $ENV{USER}"; + $pid_position = 1; # offset of PID in output of pscmd; first item is 0. + if ( $^O eq "linux" ) { + # Ps on Redhat (at least v. 7.2) appears to truncate its output + # at 80 cols, so that a long command string is truncated. + # Fix this with the --width option. This option works under + # other versions of linux even if not necessary (at least + # for SUSE 7.2). + # However the option is not available under other UNIX-type + # systems, e.g., Solaris 8. + $pscmd = "ps --width 200 -f -u $ENV{USER}"; + } + elsif ( $^O eq "darwin" ) { + # OS-X on Macintosh + $lpr_pdf = 'lpr %O %S'; + $pscmd = "ps -ww -u $ENV{USER}"; + } +} + +## default parameters +$max_repeat = 5; # Maximum times I repeat latex. Normally + # 3 would be sufficient: 1st run generates aux file, + # 2nd run picks up aux file, and maybe toc, lof which + # contain out-of-date information, e.g., wrong page + # references in toc, lof and index, and unresolved + # references in the middle of lines. But the + # formatting is more-or-less correct. On the 3rd + # run, the page refs etc in toc, lof, etc are about + # correct, but some slight formatting changes may + # occur, which mess up page numbers in the toc and lof, + # Hence a 4th run is conceivably necessary. + # At least one document class (JHEP.cls) works + # in such a way that a 4th run is needed. + # We allow an extra run for safety for a + # maximum of 5. Needing further runs is + # usually an indication of a problem; further + # runs may not resolve the problem, and + # instead could cause an infinite loop. +$clean_ext = ""; # space separated extensions of files that are + # to be deleted when doing cleanup, beyond + # standard set +$clean_full_ext = ""; # space separated extensions of files that are + # to be deleted when doing cleanup_full, beyond + # standard set and those in $clean_ext +@cus_dep_list = (); # Custom dependency list +@default_files = ( '*.tex' ); # Array of LaTeX files to process when + # no files are specified on the command line. + # Wildcards allowed + # Best used for project specific files. +@default_excluded_files = ( ); + # Array of LaTeX files to exclude when using + # @default_files, i.e., when no files are specified + # on the command line. + # Wildcards allowed + # Best used for project specific files. +$texfile_search = ""; # Specification for extra files to search for + # when no files are specified on the command line + # and the @default_files variable is empty. + # Space separated, and wildcards allowed. + # These files are IN ADDITION to *.tex in current + # directory. + # This variable is obsolete, and only in here for + # backward compatibility. + +$fdb_ext = 'fdb_latexmk'; # Extension for the file for latexmk's + # file-database + # Make it long to avoid possible collisions. +$fdb_ver = 2; # Version number for kind of fdb_file. + +$jobname = ''; # Jobname: as with current tex, etc indicates + # basename of generated files. + # Defined so that --jobname=STRING on latexmk's + # command line has same effect as with current + # tex, etc. (If $jobname is non-empty, then + # the --jobname=... option is used on tex.) + + +## default flag settings. +$silent = 0; # silence latex's messages? +$landscape_mode = 0; # default to portrait mode + +# The following two arrays contain lists of extensions (without +# period) for files that are read in during a (pdf)LaTeX run but that +# are generated automatically from the previous run, as opposed to +# being user generated files (directly or indirectly from a custom +# dependency). 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 (pdf)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. +# These arrays can be user-configured. +@generated_exts = ( 'aux', 'bbl', 'idx', 'ind', 'lof', 'lot', 'out', 'toc' ); + # N.B. 'out' is generated by hyperref package + +# Which kinds of file do I have requests to make? +# If no requests at all are made, then I will make dvi file +# If particular requests are made then other files may also have to be +# made. E.g., ps file requires a dvi file +$dvi_mode = 0; # No dvi file requested +$postscript_mode = 0; # No postscript file requested +$pdf_mode = 0; # No pdf file requested to be made by pdflatex + # Possible values: + # 0 don't create pdf file + # 1 to create pdf file by pdflatex + # 2 to create pdf file by ps2pdf + # 3 to create pdf file by dvipdf +$view = 'default'; # Default preview is of highest of dvi, ps, pdf +$sleep_time = 2; # time to sleep b/w checks for file changes in -pvc mode +$banner = 0; # Non-zero if we have a banner to insert +$banner_scale = 220; # Original default scale +$banner_intensity = 0.95; # Darkness of the banner message +$banner_message = 'DRAFT'; # Original default message +$do_cd = 0; # Do not do cd to directory of source file. + # Thus behave like latex. +$dependents_list = 0; # Whether to display list(s) of dependencies +@dir_stack = (); # Stack of pushed directories. +$cleanup_mode = 0; # No cleanup of nonessential LaTex-related files. + # $cleanup_mode = 0: no cleanup + # $cleanup_mode = 1: full cleanup + # $cleanup_mode = 2: cleanup except for dvi, + # dviF, pdf, ps, & psF +$cleanup_fdb = 0; # No removal of file for latexmk's file-database +$cleanup_only = 0; # When doing cleanup, do not go-on to making files +$diagnostics = 0; +$dvi_filter = ''; # DVI filter command +$ps_filter = ''; # Postscript filter command + +$force_mode = 0; # =1 to force processing past errors +$force_include_mode = 0;# =1 to ignore non-existent files when testing + # for dependency. (I.e., don't treat them as error) +$go_mode = 0; # =1 to force processing regardless of time-stamps + # =2 full clean-up first +$preview_mode = 0; +$preview_continuous_mode = 0; +$printout_mode = 0; # Don't print the file + +# Do we make view file in temporary then move to final destination? +# (To avoid premature updating by viewer). +$always_view_file_via_temporary = 0; # Set to 1 if viewed file is always + # made through a temporary. +$pvc_view_file_via_temporary = 1; # Set to 1 if only in -pvc mode is viewed + # file made through a temporary. + +# State variables initialized here: + +$updated = 0; # Flags when something has been remade + # Used to allow convenient user message in -pvc mode +$waiting = 0; # Flags whether we are in loop waiting for an event + # Used to avoid unnecessary repeated o/p in wait loop + +# Used for some results of parsing log file: +$reference_changed = 0; +$bad_reference = 0; +$bad_citation = 0; + + +# Set search paths for includes. +# Set them early so that they can be overridden +$BIBINPUTS = $ENV{'BIBINPUTS'}; +if (!$BIBINPUTS) { $BIBINPUTS = '.'; } +#?? OBSOLETE +$TEXINPUTS = $ENV{'TEXINPUTS'}; +if (!$TEXINPUTS) { $TEXINPUTS = '.'; } + +# Convert search paths to arrays: +# If any of the paths end in '//' then recursively search the +# directory. After these operations, @BIBINPUTS should +# have all the directories that need to be searched + +@BIBINPUTS = find_dirs1 ($BIBINPUTS); + + +###################################################################### +###################################################################### +# +# ??? UPDATE THE FOLLOWING!! +# +# We will need to determine whether source files for runs of various +# programs are out of date. In a normal situation, this is done by +# asking whether the times of the source files are later than the +# destination files. But this won't work for us, since a common +# situation is that a file is written on one run of latex, for +# example, and read back in on the next run (e.g., an .aux file). +# Some situations of this kind are standard in latex generally; others +# occur with particular macro packages or with particular +# postprocessors. +# +# The correct criterion for whether a source is out-of-date is +# therefore NOT that its modification time is later than the +# destination file, but whether the contents of the source file have +# changed since the last successful run. This also handles the case +# that the user undoes some changes to a source file by replacing the +# source file by reverting to an earlier version, which may well have +# an older time stamp. Since a direct comparison of old and new files +# would involve storage and access of a large number of backup files, +# we instead use the md5 signature of the files. (Previous versions +# of latexmk used the backup file method, but restricted to the case +# of .aux and .idx files, sufficient for most, but not all, +# situations.) +# +# We will have a database of (time, size, md5) for the relevant +# files. If the time and size of a file haven't changed, then the file +# is assumed not to have changed; this saves us from having to +# determine its md5 signature, which would involve reading the whole +# file, which is naturally time-consuming, especially if network file +# access to a server is needed, and many files are involved, when most +# of them don't change. It is of course possible to change a file +# without changing its size, but then to adjust its timestamp +# to what it was previously; this requires a certain amount of +# perversity. We can safely assume that if the user edits a file or +# changes its contents, then the file's timestamp changes. The +# interesting case is that the timestamp does change, because the file +# has actually been written to, but that the contents do not change; +# it is for this that we use the md5 signature. However, since +# computing the md5 signature involves reading the whole file, which +# may be large, we should avoid computing it more than necessary. +# +# So we get the following structure: +# +# 1. For each relevant run (latex, pdflatex, each instance of a +# custom dependency) we have a database of the state of the +# source files that were last used by the run. +# 2. On an initial startup, the database for a primary tex file +# is read that was created by a previous run of latex or +# pdflatex, if this exists. +# 3. If the file doesn't exist, then the criterion for +# out-of-dateness for an initial run is that it goes by file +# timestamps, as in previous versions of latexmk, with due +# (dis)regard to those files that are known to be generated by +# latex and re-read on the next run. +# 4. Immediately before a run, the database is updated to +# represent the current conditions of the run's source files. +# 5. After the run, it is determined whether any of the source +# files have changed. This covers both files written by the +# run, which are therefore in a dependency loop, and files that +# the user may have updated during the run. (The last often +# happens when latex takes a long time, for a big document, +# and the user makes edits before latex has finished. This is +# particularly prevalent when latexmk is used with +# preview-continuous mode.) +# 6. In the case of latex or pdflatex, the custom dependencies +# must also be checked and redone if out-of-date. +# 7. If any source files have changed, the run is redone, +# starting at step 1. +# 8. There is naturally a limit on the number of reruns, to avoid +# infinite loops from bugs and from pathological or unforeseen +# conditions. +# 9. After the run is done, the run's file database is updated. +# (By hypothesis, the sizes and md5s are correct, if the run +# is successful.) +# 10. To allow reuse of data from previous runs, the file database +# is written to a file after every complete set of passes +# through latex or pdflatex. (Note that there is separate +# information for latex and pdflatex; the necessary +# information won't coincide: Out-of-dateness for the files +# for each program concerns the properties of the files when +# the other program was run, and the set of source files could +# be different, e.g., for graphics files.) +# +# We therefore maintain the following data structures.: +# +# a. For each run (latex, pdflatex, each custom dependency) a +# database is maintained. This is a hash from filenames to a +# reference to an array: [time, size, md5]. The semantics of +# the database is that it represents the state of the source +# files used in the run. During a run it represents the state +# immediately before the run; after a run, with all reruns, it +# represents the state of the files used, modified by having +# the latest timestamps for generated files. +# b. There is a global database for all files, which represents +# the current state. This saves having to recompute the md5 +# signatures of a changed file used in more than one run +# (e.g., latex and pdflatex). +# c. Each of latex and pdflatex has a list of the relevant custom +# dependencies. +# +# In all the following a fdb-hash is a hash of the form: +# filename -> [time, size, md5] +# If a file is found to disappear, its entry is removed from the hash. +# In returns from fdb access routines, a size entry of -1 indicates a +# non-existent file. + + +# List of known rules. Rule types: primary, +# external (calls program), internal (calls routine), cusdep. + +%known_rules = ( 'latex' => 'primary', 'pdflatex' => 'primary', + ); +%primaries = (); # Hash of rules for primary part of make. Keys are + # currently 'latex', 'pdflatex' or both. Value is + # currently irrelevant. Use hash for ease of lookup + # Make remove this later, if use makeB + +# Hashes, whose keys give names of particular kinds of rule. We use +# hashes for ease of lookup. +%possible_one_time = ( 'view' => 1, 'print' => 1, 'update_view' => 1, ); +%requested_filerules = (); # Hash for rules corresponding to requested files. + # The keys are the rulenames and the value is + # currently irrelevant. +%one_time = (); # Hash for requested one-time-only rules, currently + # possible values 'print' and 'view'. + + +%rule_db = (); # Database of all rules: + # Hash: rulename -> [array of rule data] + # Rule data: + # 0: [ cmd_type, ext_cmd, int_cmd, out_of_date-crit, + # source, dest, base, out_of_date, + # out_of_date_user, time_of_last_run ] + # where + # cmd_type is 'primary', 'external' or 'cusdep', + # ext_cmd is string for associated external command + # with substitutions (%D for destination, %S + # for source, %B for base of current rule, + # %R for base of primary tex file, %T for + # texfile name, and %O for options. + # int_cmd specifies any internal command to be + # used to implement the application of the + # rule. If this is present, it overrides + # the external command, and it is the + # responsibility of the perl subroutine + # specified in intcmd to execute the + # external command if this is appropriate. + # This variable intcmd is a reference to an array, + # $$intcmd[0] = internal routine + # $$intcmd[1...] = its arguments (if any) + # out_of_date_crit specifies method of determining + # whether a file is out-of-date: + # 0 for never + # 1 for usual: whether there is a source + # file change + # 2 for dest earlier than source + # 3 for method 2 at first run, 1 thereafter + # (used when don't have file data from + # previous run). + # source = name of primary source file, if any + # dest = name of primary destination file, + # if any + # base = base name, if any, of files for + # this rule + # out_of_date = 1 if it has been detected that + # this rule needs to be run + # (typically because a source + # file has changed). + # 0 otherwise + # out_of_date_user is like out_of_date, except + # that the detection of out-of-dateness + # has been made from a change of a + # putative user file, i.e., one that is + # not a generated file (e.g., aux). This + # kind of out-of-dateness should provoke a + # rerun where or not there was an error + # during a run of (pdf)LaTeX. Normally, + # if there is an error, one should wait + # for the user to correct the error. But + # it is possible the error condition is + # already corrected during the run, e.g., + # by the user changing a source file in + # response to an error message. + # time_of_last_run = time that this rule was + # last applied. (In standard units + # from perl, to be directly compared + # with file modification times.) + # changed flags whether special changes have been made + # that require file-existence status to be ignored + # 1: {Hash sourcefile -> [source-file data] } + # Source-file data array: + # 0: time + # 1: size + # 2: md5 + # 3: name of rule to make this file + # 4: whether the file is of the kind made by epstopdf.sty + # during a primary run. It will have been read during + # the run, so that even though the file changes during + # a primary run, there is no need to trigger another + # run because of this. + +%fdb_current = (); # Fdb-hash for all files used. + + +#================================================== +## Read rc files: + +sub read_first_rc_file_in_list { + foreach my $rc_file ( @_ ) { + #print "===Testing for rc file \"$rc_file\" ...\n"; + if ( -e $rc_file ) { + #print "===Reading rc file \"$rc_file\" ...\n"; + process_rc_file( $rc_file ); + return; + } + } +} + +# Read system rc file: +read_first_rc_file_in_list( @rc_system_files ); +# Read user rc file. +read_first_rc_file_in_list( "$ENV{'HOME'}/.latexmkrc" ); +# Read rc file in current directory. +read_first_rc_file_in_list( "latexmkrc", ".latexmkrc" ); + +#================================================== + +#show_array ("BIBINPUTS", @BIBINPUTS); die; + +## Process command line args. +@command_line_file_list = (); +$bad_options = 0; + +#print "Command line arguments:\n"; for ($i = 0; $i <= $#ARGV; $i++ ) { print "$i: '$ARGV[$i]'\n"; } + +while ($_ = $ARGV[0]) +{ + # Make -- and - equivalent at beginning of option: + s/^--/-/; + shift; + if (/^-c$/) { $cleanup_mode = 2; $cleanup_only = 1; } + elsif (/^-C$/) { $cleanup_mode = 1; $cleanup_only = 1; } + elsif (/^-CA$/) { $cleanup_mode = 1; $cleanup_fdb = 1; $cleanup_only = 1;} + elsif (/^-CF$/) { $cleanup_fdb = 1; } + elsif (/^-cd$/) { $do_cd = 1; } + elsif (/^-cd-$/) { $do_cd = 0; } + elsif (/^-commands$/) { &print_commands; exit; } + elsif (/^-d$/) { $banner = 1; } + elsif (/^-dependents$/) { $dependents_list = 1; } + elsif (/^-nodependents$/ || /^-dependents-$/) { $dependents_list = 0; } + elsif (/^-dvi$/) { $dvi_mode = 1; } + elsif (/^-dvi-$/) { $dvi_mode = 0; } + elsif (/^-F$/) { $force_include_mode = 1; } + elsif (/^-F-$/) { $force_include_mode = 0; } + elsif (/^-f$/) { $force_mode = 1; } + elsif (/^-f-$/) { $force_mode = 0; } + elsif (/^-g$/) { $go_mode = 1; } + elsif (/^-g-$/) { $go_mode = 0; } + elsif (/^-gg$/) { + $go_mode = 2; $cleanup_mode = 1; $cleanup_fdb = 1; $cleanup_only = 0; + } + elsif ( /^-h$/ || /^-help$/ ) { &print_help; exit;} + elsif (/^-diagnostics/) { $diagnostics = 1; } + elsif (/^-jobname=(.*)$/) { + $jobname = $1; + } + elsif (/^-l$/) { $landscape_mode = 1; } + elsif (/^-new-viewer$/) { + $new_viewer_always = 1; + } + elsif (/^-new-viewer-$/) { + $new_viewer_always = 0; + } + elsif (/^-l-$/) { $landscape_mode = 0; } + elsif (/^-p$/) { $printout_mode = 1; + $preview_continuous_mode = 0; # to avoid conflicts + $preview_mode = 0; + } + elsif (/^-p-$/) { $printout_mode = 0; } + elsif (/^-pdfdvi$/){ $pdf_mode = 3; } + elsif (/^-pdfps$/) { $pdf_mode = 2; } + elsif (/^-pdf$/) { $pdf_mode = 1; } + elsif (/^-pdf-$/) { $pdf_mode = 0; } + elsif (/^-print=(.*)$/) { + $value = $1; + if ( $value =~ /^dvi$|^ps$|^pdf$/ ) { + $print_type = $value; + $printout_mode = 1; + } + else { + &exit_help("$My_name: unknown print type '$value' in option '$_'"); + } + } + elsif (/^-ps$/) { $postscript_mode = 1; } + elsif (/^-ps-$/) { $postscript_mode = 0; } + elsif (/^-pv$/) { $preview_mode = 1; + $preview_continuous_mode = 0; # to avoid conflicts + $printout_mode = 0; + } + elsif (/^-pv-$/) { $preview_mode = 0; } + elsif (/^-pvc$/) { $preview_continuous_mode = 1; + $force_mode = 0; # So that errors do not cause loops + $preview_mode = 0; # to avoid conflicts + $printout_mode = 0; + } + elsif (/^-pvc-$/) { $preview_continuous_mode = 0; } + elsif (/^-silent$/ || /^-quiet$/ ){ $silent = 1; } + elsif (/^-v$/ || /^-version$/) { + print "\n$version_details. Version $version_num\n"; + exit; + } + elsif (/^-verbose$/) { $silent = 0; } + elsif (/^-view=default$/) { $view = "default";} + elsif (/^-view=dvi$/) { $view = "dvi";} + elsif (/^-view=none$/) { $view = "none";} + elsif (/^-view=ps$/) { $view = "ps";} + elsif (/^-view=pdf$/) { $view = "pdf"; } + elsif (/^-e$/) { + if ( $ARGV[0] eq '' ) { + &exit_help( "No code to execute specified after -e switch"); + } + else { + execute_code_string( $ARGV[0] ); + } + shift; + } + elsif (/^-r$/) { + if ( $ARGV[0] eq '' ) { + &exit_help( "No RC file specified after -r switch"); + } + if ( -e $ARGV[0] ) { + process_rc_file( $ARGV[0] ); + } + else { + $! = 11; + die "$My_name: RC file [$ARGV[0]] does not exist\n"; + } + shift; + } + elsif (/^-bm$/) { + if ( $ARGV[0] eq '' ) { + &exit_help( "No message specified after -bm switch"); + } + $banner = 1; $banner_message = $ARGV[0]; + shift; + } + elsif (/^-bi$/) { + if ( $ARGV[0] eq '' ) { + &exit_help( "No intensity specified after -bi switch"); + } + $banner_intensity = $ARGV[0]; + shift; + } + elsif (/^-bs$/) { + if ( $ARGV[0] eq '' ) { + &exit_help( "No scale specified after -bs switch"); + } + $banner_scale = $ARGV[0]; + shift; + } + elsif (/^-dF$/) { + if ( $ARGV[0] eq '' ) { + &exit_help( "No dvi filter specified after -dF switch"); + } + $dvi_filter = $ARGV[0]; + shift; + } + elsif (/^-pF$/) { + if ( $ARGV[0] eq '' ) { + &exit_help( "No ps filter specified after -pF switch"); + } + $ps_filter = $ARGV[0]; + shift; + } + elsif (/^-/) { + warn "$My_name: $_ bad option\n"; + $bad_options++; + } + else { + push @command_line_file_list, $_ ; + } +} + +if ( $bad_options > 0 ) { + &exit_help( "Bad options specified" ); +} + +warn "$My_name: This is $version_details, version: $version_num.\n", + "**** Report bugs etc to John Collins <collins at phys.psu.edu>. ****\n" + unless $silent; + +# For backward compatibility, convert $texfile_search to @default_files +# Since $texfile_search is initialized to "", a nonzero value indicates +# that an initialization file has set it. +if ( $texfile_search ne "" ) { + @default_files = split / /, "*.tex $texfile_search"; +} + +#printA "A: Command line file list:\n"; +#for ($i = 0; $i <= $#command_line_file_list; $i++ ) { print "$i: '$command_line_file_list[$i]'\n"; } + +#Glob the filenames command line if the script was not invoked under a +# UNIX-like environment. +# Cases: (1) MS/MSwin native Glob +# (OS detected as MSWin32) +# (2) MS/MSwin cygwin Glob [because we do not know whether +# the cmd interpreter is UNIXy (and does glob) or is +# native MS-Win (and does not glob).] +# (OS detected as cygwin) +# (3) UNIX Don't glob (cmd interpreter does it) +# (Currently, I assume this is everything else) +if ( ($^O eq "MSWin32") || ($^O eq "cygwin") ) { + # Preserve ordering of files + @file_list = glob_list1(@command_line_file_list); +#print "A1:File list:\n"; +#for ($i = 0; $i <= $#file_list; $i++ ) { print "$i: '$file_list[$i]'\n"; } +} +else { + @file_list = @command_line_file_list; +#print "A2:File list:\n"; +#for ($i = 0; $i <= $#file_list; $i++ ) { print "$i: '$file_list[$i]'\n"; } +} +@file_list = uniq1( @file_list ); + + +# Check we haven't selected mutually exclusive modes. +# Note that -c overides all other options, but doesn't cause +# an error if they are selected. +if (($printout_mode && ( $preview_mode || $preview_continuous_mode )) + || ( $preview_mode && $preview_continuous_mode )) +{ + # Each of the options -p, -pv, -pvc turns the other off. + # So the only reason to arrive here is an incorrect inititalization + # file, or a bug. + &exit_help( "Conflicting options (print, preview, preview_continuous) selected"); +} + +if ( @command_line_file_list ) { + # At least one file specified on command line (before possible globbing). + if ( !@file_list ) { + &exit_help( "Wildcards in file names didn't match any files"); + } +} +else { + # No files specified on command line, try and find some + # Evaluate in order specified. The user may have some special + # for wanting processing in a particular order, especially + # if there are no wild cards. + # Preserve ordering of files + my @file_list1 = uniq1( glob_list1(@default_files) ); + my @excluded_file_list = uniq1( glob_list1(@default_excluded_files) ); + # Make hash of excluded files, for easy checking: + my %excl = (); + foreach my $file (@excluded_file_list) { + $excl{$file} = ''; + } + foreach my $file (@file_list1) { + push( @file_list, $file) unless ( exists $excl{$file} ); + } + if ( !@file_list ) { + &exit_help( "No file name specified, and I couldn't find any"); + } +} + +$num_files = $#file_list + 1; +$num_specified = $#command_line_file_list + 1; + +#print "Command line file list:\n"; +#for ($i = 0; $i <= $#command_line_file_list; $i++ ) { print "$i: '$command_line_file_list[$i]'\n"; } +#print "File list:\n"; +#for ($i = 0; $i <= $#file_list; $i++ ) { print "$i: '$file_list[$i]'\n"; } + + +# If selected a preview-continuous mode, make sure exactly one filename was specified +if ($preview_continuous_mode && ($num_files != 1) ) { + if ($num_specified > 1) { + &exit_help( + "Need to specify exactly one filename for ". + "preview-continuous mode\n". + " but $num_specified were specified" + ); + } + elsif ($num_specified == 1) { + &exit_help( + "Need to specify exactly one filename for ". + "preview-continuous mode\n". + " but wildcarding produced $num_files files" + ); + } + else { + &exit_help( + "Need to specify exactly one filename for ". + "preview-continuous mode.\n". + " Since none were specified on the command line, I looked for \n". + " files in '@default_files'.\n". + " But I found $num_files files, not 1." + ); + } +} + +# If selected jobname, can only apply that to one file: +if ( ($jobname ne '') && ($num_files > 1) ) { + &exit_help( + "Need to specify at most one filename if ". + "jobname specified, \n". + " but $num_files were found (after defaults and wildcarding)." + ); +} + + +# Normalize the commands, to have place-holders for source, dest etc: +&fix_cmds; + +# If landscape mode, change dvips processor, and the previewers: +if ( $landscape_mode ) +{ + $dvips = $dvips_landscape; + $dvi_previewer = $dvi_previewer_landscape; + $ps_previewer = $ps_previewer_landscape; +} + +if ( $silent ) { + add_option( \$latex, " $latex_silent_switch" ); + add_option( \$pdflatex, " $pdflatex_silent_switch" ); + add_option( \$bibtex, " $bibtex_silent_switch" ); + add_option( \$makeindex, " $makeindex_silent_switch" ); + add_option( \$dvips, " $dvips_silent_switch" ); +} + +if ( $jobname ne '' ) { + $jobstring = "--jobname=$jobname"; + add_option( \$latex, " $jobstring" ); + add_option( \$pdflatex, " $jobstring" ); +} + +# Which kind of file do we preview? +if ( $view eq "default" ) { + # If default viewer requested, use "highest" of dvi, ps and pdf + # that was requested by user. + # No explicit request means view dvi. + $view = "dvi"; + if ( $postscript_mode ) { $view = "ps"; } + if ( $pdf_mode ) { $view = "pdf"; } +} + +if ( ! ( $dvi_mode || $pdf_mode || $postscript_mode || $printout_mode) ) { + print "No specific requests made, so default to dvi by latex\n"; + $dvi_mode = 1; +} + +# Set new-style requested rules: +if ( $dvi_mode ) { $requested_filerules{'latex'} = 1; } +if ( $pdf_mode == 1 ) { $requested_filerules{'pdflatex'} = 1; } +elsif ( $pdf_mode == 2 ) { $requested_filerules{'ps2pdf'} = 1; } +elsif ( $pdf_mode == 3 ) { $requested_filerules{'dvipdf'} = 1; } +if ( $postscript_mode ) { $requested_filerules{'dvips'} = 1; } +if ( $printout_mode ) { $one_time{'print'} = 1; } +if ( $preview_continuous_mode || $preview_mode ) { $one_time{'view'} = 1; } +if ( length($dvi_filter) != 0 ) { $requested_filerules{'dvi_filter'} = 1; } +if ( length($ps_filter) != 0 ) { $requested_filerules{'ps_filter'} = 1; } +if ( $banner ) { $requested_filerules{'dvips'} = 1; } + + +%possible_primaries = (); +foreach (&rdb_possible_primaries) { + $possible_primaries{$_} = 1; +} + +#print "POSSIBLE PRIMARIES: "; +#foreach (keys %possible_primaries ) {print "$_, ";} +#print "\n"; + + +if ( $pdf_mode == 2 ) { + # We generate pdf from ps. Make sure we have the correct kind of ps. + add_option( \$dvips, " $dvips_pdf_switch" ); +} + + +# Make convenient forms for lookup. +# Extensions always have period. + +# Convert @generated_exts to a hash for ease of look up, with exts +# preceeded by a '.' +# %generated_exts_all is used in analyzing file changes, to +# distinguish changes in user files from changes in generated files. +%generated_exts_all = (); +foreach (@generated_exts ) { + $generated_exts_all{".$_"} = 1; +} + +$quell_uptodate_msgs = $silent; + # Whether to quell informational messages when files are uptodate + # Will turn off in -pvc mode + +# Process for each file. +# The value of $bibtex_mode set in an initialization file may get +# overridden, during file processing, so save it: +#?? Unneeded now: $save_bibtex_mode = $bibtex_mode; + +$failure_count = 0; +$last_failed = 0; # Flag whether failed on making last file + # This is used for showing suitable error diagnostics +FILE: +foreach $filename ( @file_list ) +{ + # Global variables for making of current file: + $updated = 0; + $failure = 0; # Set nonzero to indicate failure at some point of + # a make. Use value as exit code if I exit. + $failure_msg = ''; # Indicate reason for failure +#?? Unneeded now: $bibtex_mode = $save_bibtex_mode; + + if ( $do_cd ) { + ($filename, $path) = fileparse( $filename ); + warn "$My_name: Changing directory to '$path'\n"; + pushd( $path ); + } + else { + $path = ''; + } + + + ## remove extension from filename if was given. + if ( &find_basename($filename, $root_filename, $texfile_name) ) + { + if ( $force_mode ) { + warn "$My_name: Could not find file [$texfile_name]\n"; + } + else { + &ifcd_popd; + &exit_msg1( "Could not find file [$texfile_name]", + 11); + } + } + if ($jobname ne '' ) { + $root_filename = $jobname; + } + + # Initialize basic dependency information: + + # For use under error conditions: + @default_includes = ($texfile_name, "$root_filename.aux"); + + $fdb_file = "$root_filename.$fdb_ext"; + + if ($cleanup_fdb) { unlink $fdb_file; } + if ( $cleanup_mode > 0 ) { + my @extra_generated = (); + my @aux_files = (); + rdb_read_generatedB( $fdb_file, \@extra_generated, \@aux_files ); + if ( ($go_mode == 2) && !$silent ) { + warn "$My_name: Removing all generated files\n" unless $silent; + } + if ($diagnostics) { + show_array( "For deletion:\n Extra_generated:", @extra_generated ); + show_array( " Aux files:", @aux_files ); + } + # Add to the generated files, some log file and some backup + # files used in previous versions of latexmk + &cleanup1( 'blg', 'ilg', 'log', 'aux.bak', 'idx.bak', + split(' ',$clean_ext), + @generated_exts + ); + unlink( 'texput.log', @extra_generated, "texput.aux", @aux_files ); + if ( $cleanup_mode == 1 ) { + &cleanup1( 'dvi', 'dviF', 'ps', 'psF', 'pdf', + split(' ', $clean_full_ext) + ); + } + } + if ($cleanup_only) { next FILE; } + + # Initialize file and rule databases. + %rule_list = (); + &rdb_make_rule_list; + &rdb_set_rules(\%rule_list); + + +#??? The following are not needed if use makeB. +# ?? They may be set too early? +# Arrays and hashes for picking out accessible rules. +# Distinguish rules for making files and others + @accessible_all = sort ( &rdb_accessible( keys %requested_filerules, keys %one_time )); + %accessible_filerules = (); + foreach (@accessible_all) { + unless ( /view/ || /print/ ) { $accessible_filerules{$_} = 1; } + } + @accessible_filerules = sort keys %accessible_filerules; + +# show_array ( "=======All rules used", @accessible_all ); +# show_array ( "=======Requested file rules", sort keys %requested_filerules ); +# show_array ( "=======Rules for files", @accessible_filerules ); + + if ( $diagnostics ) { + print "$My_name: Rules after start up for '$texfile_name'\n"; + rdb_show(); + } + + %primaries = (); + foreach (@accessible_all) { + if ( ($_ eq 'latex') || ($_ eq 'pdflatex') ) { $primaries{$_} = 1; } + } + + $have_fdb = 0; + if ( (! -e $fdb_file) && (! -e "$root_filename.aux") ) { + # No aux and no fdb file => set up trivial aux file + # and corresponding fdb_file. Arrange them to provoke one run + # as minimum, but no more if actual aux file is trivial. + # (Useful on big files without cross references.) + &set_trivial_aux_fdb; + } + + if ( -e $fdb_file ) { + $rdb_errors = rdb_read( $fdb_file ); + $have_fdb = ($rdb_errors == 0); + } + if (!$have_fdb) { + # We didn't get a valid set of data on files used in + # previous run. So use filetime criterion for make + # instead of change from previous run, until we have + # done our own make. + rdb_recurseA( [keys %possible_primaries], + sub{ if ( $$Ptest_kind == 1 ) { $$Ptest_kind = 3;} } + ); + if ( -e "$root_filename.log" ) { + rdb_for_some( [keys %possible_primaries], \&rdb_set_from_logB ); + } + } + if ($go_mode) { + # Force everything to be remade. + rdb_recurseA( [keys %requested_filerules], sub{$$Pout_of_date=1;} ); + } + + + if ( $diagnostics ) { + print "$My_name: Rules after initialization\n"; + rdb_show(); + } + + #************************************************************ + + if ( $preview_continuous_mode ) { + &make_preview_continuousB; + # Will probably exit by ctrl/C and never arrive here. + next FILE; + } + + +## Handling of failures: +## Variable $failure is set to indicate a failure, with information +## put in $failure_msg. +## These variables should be set to 0 and '' at any point at which it +## should be assumed that no failures have occurred. +## When after a routine is called it is found that $failure is set, then +## processing should normally be aborted, e.g., by return. +## Then there is a cascade of returns back to the outermost level whose +## responsibility is to handle the error. +## Exception: An outer level routine may reset $failure and $failure_msg +## after initial processing, when the error condition may get +## ameliorated later. + #Initialize failure flags now. + $failure = 0; + $failure_msg = ''; + $failure = rdb_makeB( keys %requested_filerules ); + if ($failure > 0) { next FILE;} + rdb_for_some( [keys %one_time], \&rdb_run1 ); +} # end FILE +continue { + if ($dependents_list) { rdb_list(); } + # Handle any errors + if ( $failure > 0 ) { + if ( $failure_msg ) { + #Remove trailing space + $failure_msg =~ s/\s*$//; + warn "$My_name: Did not finish processing file: $failure_msg\n"; + $failure = 1; + } + $failure_count ++; + $last_failed = 1; + } + else { + $last_failed = 0; + } + &ifcd_popd; +} +# If we get here without going through the continue section: +if ( $do_cd && ($#dir_stack > -1) ) { + # Just in case we did an abnormal exit from the loop + warn "$My_name: Potential bug: dir_stack not yet unwound, undoing all directory changes now\n"; + &finish_dir_stack; +} + +if ($failure_count > 0) { + if ( $last_failed <= 0 ) { + # Error occured, but not on last file, so + # user may not have seen error messages + warn "\n------------\n"; + warn "$My_name: Some operations failed.\n"; + } + if ( !$force_mode ) { + warn "$My_name: Use the -f option to force complete processing.\n"; + } + exit 12; +} + + + +# end MAIN PROGRAM +############################################################# + +sub fix_cmds { + # If commands do not have placeholders for %S etc, put them in + foreach ($latex, $pdflatex, $lpr, $lpr_dvi, $lpr_pdf, + $pdf_previewer, $ps_previewer, $ps_previewer_landscape, + $dvi_previewer, $dvi_previewer_landscape, + $kpsewhich + ) { + # Source only + if ( $_ && ! /%/ ) { $_ .= " %O %S"; } + } + foreach ($bibtex) { + # Base only + if ( $_ && ! /%/ ) { $_ .= " %O %B"; } + } + foreach ($dvipdf, $ps2pdf) { + # Source and dest without flag for destination + if ( $_ && ! /%/ ) { $_ .= " %O %S %D"; } + } + foreach ($dvips, $makeindex) { + # Source and dest with -o dest before source + if ( $_ && ! /%/ ) { $_ .= " %O -o %D %S"; } + } + foreach ($dvi_filter, $ps_filter) { + # Source and dest, but as filters + if ( $_ && ! /%/ ) { $_ .= " %O <%S >%D"; } + } +} #END fix_cmds + +############################################################# + +sub add_option { + # Call add_option( \$cmd, $opt ) + # Add option to command + if ( ${$_[0]} !~ /%/ ) { &fix_cmds; } + ${$_[0]} =~ s/%O/$_[1] %O/; +} #END add_option + +############################################################# + +sub rdb_make_rule_list { +# Substitutions: %S = source, %D = dest, %B = this rule's base +# %T = texfile, %R = root = base for latex. + + # Defaults for dvi, ps, and pdf files + # Use local, not my, so these variables can be referenced + local $dvi_final = "%R.dvi"; + local $ps_final = "%R.ps"; + local $pdf_final = "%R.pdf"; + if ( length($dvi_filter) > 0) { + $dvi_final = "%R.dviF"; + } + if ( length($ps_filter) > 0) { + $ps_final = "%R.psF"; + } + + my $print_file = ''; + my $print_cmd = ''; + if ( $print_type eq 'dvi' ) { + $print_file = $dvi_final; + $print_cmd = $lpr_dvi; + } + elsif ( $print_type eq 'pdf' ) { + $print_file = $pdf_final; + $print_cmd = $lpr_pdf; + } + elsif ( $print_type eq 'ps' ) { + $print_file = $ps_final; + $print_cmd = $lpr; + } + + my $view_file = ''; + my $viewer = ''; + my $viewer_update_method = 0; + my $viewer_update_signal = undef; + my $viewer_update_command = undef; + + if ( ($view eq 'dvi') || ($view eq 'pdf') || ($view eq 'ps') ) { + $view_file = ${$view.'_final'}; + $viewer = ${$view.'_previewer'}; + $viewer_update_method = ${$view.'_update_method'}; + $viewer_update_signal = ${$view.'_update_signal'}; + if (defined ${$view.'_update_command'}) { + $viewer_update_command = ${$view.'_update_command'}; + } + } + # Specification of internal command for viewer update: + my $PA_update = ['do_update_view', $viewer_update_method, $viewer_update_signal, 0, 1]; + +# For test_kind: Use file contents for latex and friends, but file time for the others. +# This is because, especially for dvi file, the contents of the file may contain +# a pointer to a file to be included, not the contents of the file! + %rule_list = ( + 'latex' => [ 'primary', "$latex", '', "%T", "%B.dvi", "%R", 1 ], + 'pdflatex' => [ 'primary', "$pdflatex", '', "%T", "%B.pdf", "%R", 1 ], + 'dvipdf' => [ 'external', "$dvipdf", 'do_viewfile', $dvi_final, "%B.pdf", "%R", 2 ], + 'dvips' => [ 'external', "$dvips", 'do_viewfile', $dvi_final, "%B.ps", "%R", 2 ], + 'dvifilter'=> [ 'external', $dvi_filter, 'do_viewfile', "%B.dvi", "%B.dviF", "%R", 2 ], + 'ps2pdf' => [ 'external', "$ps2pdf", 'do_viewfile', $ps_final, "%B.pdf", "%R", 2 ], + 'psfilter' => [ 'external', $ps_filter, 'do_viewfile', "%B.ps", "%B.psF", "%R", 2 ], + 'print' => [ 'external', "$print_cmd", 'if_source', $print_file, "", "", 2 ], + 'update_view' => [ 'external', $viewer_update_command, $PA_update, + $view_file, "", "", 2 ], + 'view' => [ 'external', "$viewer", 'if_source', $view_file, "", "", 2 ], + ); + %source_list = (); + foreach my $rule (keys %rule_list) { + $source_list{$rule} = []; + my $PAsources = $source_list{$rule}; + my ( $cmd_type, $cmd, $source, $dest, $root ) = @{$rule_list{$rule}}; + if ($source) { + push @$PAsources, [ $rule, $source, '' ]; + } + } + +# Ensure we only have one way to make pdf file, and that it is appropriate: + if ($pdf_mode == 1) { delete $rule_list{'dvipdf'}; delete $rule_list{'ps2pdf'}; } + elsif ($pdf_mode == 2) { delete $rule_list{'dvipdf'}; delete $rule_list{'pdflatex'}; } + else { delete $rule_list{'pdflatex'}; delete $rule_list{'ps2pdf'}; } + +} # END rdb_make_rule_list + +#************************************************************ + +sub rdb_set_rules { + # Call rdb_set_rules( \%rule_list, ...) + # Set up rule database from definitions + + # Map of files to rules that MAKE them: + local %from_rules = (); + %rule_db = (); + + foreach my $Prule_list (@_) { + foreach my $rule ( sort keys %$Prule_list) { + my ( $cmd_type, $ext_cmd, $int_cmd, $source, $dest, $base, $test_kind ) = @{$$Prule_list{$rule}}; + my $needs_making = 0; + # Substitute in the filename variables, since we will use + # those for determining filenames. But delay expanding $cmd + # until run time, in case of changes. + foreach ($base, $source, $dest ) { + s/%R/$root_filename/; + } + foreach ($source, $dest ) { + s/%B/$base/; + s/%T/$texfile_name/; + } + # print "$rule: $cmd_type, EC='$ext_cmd', IC='$int_cmd', $test_kind,\n", + # " S='$source', D='$dest', B='$base' $needs_making\n"; + rdb_create_rule( $rule, $cmd_type, $ext_cmd, $int_cmd, $test_kind, + $source, $dest, $base, + $needs_making ); + if ($dest) { $from_rules{$dest} = $rule ; } + } + rdb_for_all( + 0, + sub{ + # my ($base, $path, $ext) = fileparse( $file, '\.[^\.]*' ); + # if ( exists $from_rules{$file} && ! exists $generated_exts_all{$ext} ) { + # # Show how to make this file. But don't worry about generated + # # files. + if ( exists $from_rules{$file} ) { + $$Pfrom_rule = $from_rules{$file}; + } + #?? print "$rule: $file, $$Pfrom_rule\n"; + } + ); + } # End arguments of subroutine + &rdb_make_links; +} # END rdb_set_rules + +#************************************************************ + +sub rdb_make_links { +# ?? Problem if there are multiple rules for getting a file. Notably pdf. +# Which one to choose? + # Create $from_rule if there's a suitable rule. + # Map files to rules: + local %from_rules = (); + rdb_for_all( sub{ if($$Pdest){$from_rules{$$Pdest} = $rule;} } ); +#?? foreach (sort keys %from_rules) {print "D='$_' F='$from_rules{$_}\n";} + rdb_for_all( + 0, + sub{ + if ( exists $from_rules{$file} ) { $$Pfrom_rule = $from_rules{$file}; } +#?? print "$rule: $file, $$Pfrom_rule\n"; + } + ); + rdb_for_all( + 0, + sub{ + if ( exists $from_rules{$file} ) { + $$Pfrom_rule = $from_rules{$file}; + } + if ( $$Pfrom_rule && (! rdb_rule_exists( $$Pfrom_rule ) ) ) { + $$Pfrom_rule = ''; + } +#?? print "$rule: $file, $$Pfrom_rule\n"; + } + ); +} # END rdb_make_links + +#************************************************************ + +sub set_trivial_aux_fdb { + # 1. Write aux file EXACTLY as would be written if the tex file + # had no cross references, etc. I.e., a minimal .aux file. + # 2. Write a corresponding fdb file + # 3. Provoke a run of (pdf)latex (actually of all primaries). + + local $aux_file = "$root_filename.aux"; + open( aux_file, '>', $aux_file ) + or die "Cannot write file '$aux_file'\n"; + print aux_file "\\relax \n"; + close(aux_file); + + foreach my $rule (keys %primaries ) { + rdb_ensure_file( $rule, $texfile_name ); + rdb_ensure_file( $rule, $aux_file ); + rdb_one_rule( $rule, + sub{ $$Pout_of_date = 1; } + ); + } + &rdb_write( $fdb_file ); +} #END set_trivial_aux_fdb + +#************************************************************ +#### Particular actions +#************************************************************ +#************************************************************ + +sub do_cusdep { + # Unconditional application of custom-dependency + # except that rule is not applied if the source file source + # does not exist, and an error is returned if the dest is not made. + # + # Assumes rule context for the custom-dependency, and that my first + # argument is the name of the subroutine to apply + my $func_name = $_[0]; + my $return = 0; + if ( !-e $$Psource ) { + # Source does not exist. Users of this rule will need to turn + # it off when custom dependencies are reset + if ( !$silent ) { +## ??? Was commented out. 1 Sep. 2008 restored, for cusdep no-file-exists issue + warn "$My_name: In trying to apply custom-dependency rule\n", + " to make '$$Pdest' from '$$Psource'\n", + " the source file has disappeared since the last run\n"; + } + # Treat as successful + } + elsif ( !$func_name ) { + warn "$My_name: Possible misconfiguration or bug:\n", + " In trying to apply custom-dependency rule\n", + " to make '$$Pdest' from '$$Psource'\n", + " the function name is blank.\n"; + } + elsif ( ! defined &$func_name ) { + warn "$My_name: Misconfiguration or bug,", + " in trying to apply custom-dependency rule\n", + " to make '$$Pdest' from '$$Psource'\n", + " function name '$func_name' does not exists.\n"; + } + else { + my $cusdep_ret = &$func_name( $$Pbase ); + if ( defined $cusdep_ret && ($cusdep_ret != 0) ) { + $return = $cusdep_ret; + if ($return) { + warn "Rule '$rule', function '$func_name'\n", + " failed with return code = $return\n"; + } + } + elsif ( !-e $$Pdest ) { + # Destination non-existent, but routine failed to give an error + warn "$My_name: In running custom-dependency rule\n", + " to make '$$Pdest' from '$$Psource'\n", + " function '$func_name' did not make the destination.\n"; + $return = -1; + } + } + return $return; +} # END do_cusdep + +#************************************************************ + +sub do_viewfile { + # Unconditionally make file for viewing, going through temporary file if + # Assumes rule context + + my $return = 0; + my ($base, $path, $ext) = fileparseA( $$Pdest ); + if ( &view_file_via_temporary ) { + my $tmpfile = tempfile1( "${root_filename}_tmp", $ext ); + $return = &rdb_ext_cmd1( '', '', $tmpfile ); + move( $tmpfile, $$Pdest ); + } + else { + $return = &rdb_ext_cmd; + } + return $return; +} #END do_viewfile + +#************************************************************ + +sub do_update_view { + # Update viewer + # Assumes rule context + # Arguments: (method, signal, viewer_process) + + my $return = 0; + + # Although the process is passed as an argument, we'll need to update it. + # So (FUDGE??) bypass the standard interface for the process. + # We might as well do this for all the arguments. + my $viewer_update_method = ${$PAint_cmd}[1]; + my $viewer_update_signal = ${$PAint_cmd}[2]; + my $Pviewer_process = \${$PAint_cmd}[3]; + my $Pneed_to_get_viewer_process = \${$PAint_cmd}[4]; + + if ($viewer_update_method == 2) { + if ($$Pneed_to_get_viewer_process) { + $$Pviewer_process = &find_process_id( $$Psource ); + if ($$Pviewer_process != 0) { + $$Pneed_to_get_viewer_process = 0; + } + } + if ($$Pviewer_process == 0) { + print "$My_name: need to signal viewer for file '$$Psource', but didn't get \n", + " process ID for some reason, e.g., no viewer, bad configuration, bug\n" + if $diagnostics ; + } + elsif ( defined $viewer_update_signal) { + print "$My_name: signalling viewer, process ID $$Pviewer_process\n" + if $diagnostics ; + kill $viewer_update_signal, $$Pviewer_process; + } + else { + warn "$My_name: viewer is supposed to be sent a signal\n", + " but no signal is defined. Misconfiguration or bug?\n"; + $return = 1; + } + } + elsif ($viewer_update_method == 4) { + if (defined $$Pext_cmd) { + $return = &rdb_ext_cmd; + } + else { + warn "$My_name: viewer is supposed to be updated by running a command,\n", + " but no command is defined. Misconfiguration or bug?\n"; + } + } + return $return; +} #END do_update_view + +#************************************************************ + +sub if_source { + # Unconditionally apply rule if source file exists. + # Assumes rule context + if ( -e $$Psource ) { + return &rdb_ext_cmd; + } + else { + return -1; + } +} #END if_source + +#************************************************************ +#### Subroutines +#************************************************************ +#************************************************************ + +# Finds the basename of the root file +# Arguments: +# 1 - Filename to breakdown +# 2 - Where to place base file +# 3 - Where to place tex file +# Returns non-zero if tex file does not exist +# +# The rules for determining this depend on the implementation of TeX. +# The variable $extension_treatment determines which rules are used. + +sub find_basename +#?? Need to use kpsewhich, if possible +{ + local($given_name, $base_name, $ext, $path, $tex_name); + $given_name = $_[0]; + if ( "$extension_treatment" eq "miktex_old" ) { + # Miktex v. 1.20d: + # 1. If the filename has an extension, then use it. + # 2. Else append ".tex". + # 3. The basename is obtained from the filename by + # removing the path component, and the extension, if it + # exists. If a filename has a multiple extension, then + # all parts of the extension are removed. + # 4. The names of generated files (log, aux) are obtained by + # appending .log, .aux, etc to the basename. Note that + # these are all in the CURRENT directory, and the drive/path + # part of the originally given filename is ignored. + # + # Thus when the given filename is "\tmp\a.b.c", the tex + # filename is the same, and the basename is "a". + + ($base_name, $path, $ext) = fileparse( $given_name, '\..*' ); + if ( "$ext" eq "") { $tex_name = "$given_name.tex"; } + else { $tex_name = $given_name; } + $_[1] = $base_name; + $_[2] = $tex_name; + } + elsif ( "$extension_treatment" eq "unix" ) { + # unix (at least web2c 7.3.1) => + # 1. If filename.tex exists, use it, + # 2. else if filename exists, use it. + # 3. The base filename is obtained by deleting the path + # component and, if an extension exists, the last + # component of the extension, even if the extension is + # null. (A name ending in "." has a null extension.) + # 4. The names of generated files (log, aux) are obtained by + # appending .log, .aux, etc to the basename. Note that + # these are all in the CURRENT directory, and the drive/path + # part of the originally given filename is ignored. + # + # Thus when the given filename is "/tmp/a.b.c", there are two + # cases: + # a. /tmp/a.b.c.tex exists. Then this is the tex file, + # and the basename is "a.b.c". + # b. /tmp/a.b.c.tex does not exist. Then the tex file is + # "/tmp/a.b.c", and the basename is "a.b". + + if ( -e "$given_name.tex" ) { + $tex_name = "$given_name.tex"; + } + else { + $tex_name = "$given_name"; + } + ($base_name, $path, $ext) = fileparse( $tex_name, '\.[^\.]*' ); + $_[1] = $base_name; + $_[2] = $tex_name; + } + else { + die "$My_name: Incorrect configuration gives \$extension_treatment=", + "'$extension_treatment'\n"; + } + if ($diagnostics) { + print "Given='$given_name', tex='$tex_name', base='$base_name'\n"; + } + return ! -e $tex_name; +} #END find_basename + +#************************************************************ + +sub make_preview_continuousB { + # Version for use with makeB + local @changed = (); + local @disappeared = (); + local @no_dest = (); # Non-existent destination files + local @rules_to_apply = (); + local $failure = 0; + local $runs = 0; + local %rules_applied = (); + local $updated = 0; + + # What to make? + my @targets = keys %requested_filerules; + + $quell_uptodate_msgs = 1; + + local $view_file = ''; + rdb_one_rule( 'view', sub{ $view_file = $$Psource; } ); + + if ( ($view eq 'dvi') || ($view eq 'pdf') || ($view eq 'ps') ) { + warn "Viewing $view\n"; + } + elsif ( $view eq 'none' ) { + warn "Not using a previewer\n"; + $view_file = ''; + } + else { + warn "$My_name: BUG: Invalid preview method '$view'\n"; + exit 20; + } + + my $viewer_running = 0; # No viewer known to be running yet + # Get information from update_view rule + local $viewer_update_method = 0; + # Pointers so we can update the following: + local $Pviewer_process = undef; + local $Pneed_to_get_viewer_process = undef; + rdb_one_rule( 'update_view', + sub{ $viewer_update_method = $$PAint_cmd[1]; + $Pviewer_process = \$$PAint_cmd[3]; + $Pneed_to_get_viewer_process = \$$PAint_cmd[4]; + } + ); + # Note that we don't get the previewer process number from the program + # that starts it; that might only be a script to get things set up and the + # actual previewer could be (and sometimes IS) another process. + + if ( ($view_file ne '') && (-e $view_file) && !$new_viewer_always ) { + # Is a viewer already running? + # (We'll save starting up another viewer.) + $$Pviewer_process = &find_process_id( $view_file ); + if ( $$Pviewer_process ) { + warn "$My_name: Previewer is already running\n" + if !$silent; + $viewer_running = 1; + $$Pneed_to_get_viewer_process = 0; + } + } + + # Loop forever, rebuilding .dvi and .ps as necessary. + # Set $first_time to flag first run (to save unnecessary diagnostics) +CHANGE: + for (my $first_time = 1; 1; $first_time = 0 ) { + $updated = 0; + $failure = 0; + $failure_msg = ''; + if ( $MSWin_fudge_break && ($^O eq "MSWin32") ) { + # Fudge under MSWin32 ONLY, to stop perl/latexmk from + # catching ctrl/C and ctrl/break, and let it only reach + # downstream programs. See comments at first definition of + # $MSWin_fudge_break. + $SIG{BREAK} = $SIG{INT} = 'IGNORE'; + } + $failure = rdb_makeB( @targets ); + +## warn "=========Viewer PID = $$Pviewer_process; updated=$updated\n"; + + if ( $MSWin_fudge_break && ($^O eq "MSWin32") ) { + $SIG{BREAK} = $SIG{INT} = 'DEFAULT'; + } + if ( $failure > 0 ) { + if ( !$failure_msg ) { + $failure_msg = 'Failure to make the files correctly'; + } + # There will be files changed during the run that are irrelevant. + # We need to wait for the user to change the files. + # So set the GENERATED files as up-to-date + rdb_for_some( [keys %current_primaries], \&rdb_update_gen_files ); + + $failure_msg =~ s/\s*$//; #Remove trailing space + warn "$My_name: $failure_msg\n", + " ==> You will need to change a source file before I do another run <==\n"; + } + elsif ( ($view_file ne '') && (-e $view_file) && $updated && $viewer_running ) { + # A viewer is running. Explicitly get it to update screen if we have to do it: + rdb_one_rule( 'update_view', \&rdb_run1 ); + } + elsif ( ($view_file ne '') && (-e $view_file) && !$viewer_running ) { + # Start the viewer + if ( !$silent ) { + if ($new_viewer_always) { + warn "$My_name: starting previewer for '$view_file'\n", + "------------\n"; + } + else { + warn "$My_name: I have not found a previewer that ", + "is already running. \n", + " So I will start it for '$view_file'\n", + "------------\n"; + } + } + local $retcode = rdb_makeB ( 'view' ); + if ( $retcode != 0 ) { + if ($force_mode) { + warn "$My_name: I could not run previewer\n"; + } + else { + &exit_msg1( "I could not run previewer", $retcode); + } + } + else { + $viewer_running = 1; + $$Pneed_to_get_viewer_process = 1; + } # end analyze result of trying to run viewer + } # end start viewer + if ( $first_time || $updated || $failure ) { + print "\n=== Watching for updated files. Use ctrl/C to stop ...\n"; + } + $waiting = 1; if ($diagnostics) { warn "WAITING\n"; } + WAIT: while (1) { + sleep($sleep_time); + &rdb_clear_change_record; + rdb_recurseA( [@targets], \&rdb_flag_changes_here ); + if ( &rdb_count_changes > 0) { + &rdb_diagnose_changes + unless $silent; +#??? + warn "$My_name: File(s) changed or not used in previous run(s). Remake files.\n"; + last WAIT; + } + # Does this do this job???? + local $new_files = 0; + rdb_for_some( [keys %current_primaries], sub{ $new_files += &rdb_find_new_filesB } ); + if ($new_files > 0) { + warn "$My_name: New file(s) found.\n"; + last WAIT; + } + } # end WAIT: + $waiting = 0; if ($diagnostics) { warn "NOT WAITING\n"; } + } #end infinite_loop CHANGE: +} #END sub make_preview_continuousB + +#************************************************************ + +sub process_rc_file { + # Usage process_rc_file( filename ) + # Run rc_file whose name is given in first argument + # Exit with code 11 if file could not be read. + # (In general this is not QUITE the right error) + # Exit with code 13 if there is a syntax error or other problem. + # ???Should I leave the exiting to the caller (perhaps as an option)? + # But I can always catch it with an eval if necessary. + # That confuses ctrl/C and ctrl/break handling. + my $rc_file = $_[0]; + warn "$My_name: Executing PERL code in file '$rc_file'...\n" + if $diagnostics; + do( $rc_file ); + # The return value from the do is not useful, since it is the value of + # the last expression evaluated, which could be anything. + # The correct test of errors is on the values of $! and $@. + +# This is not entirely correct. On gluon2: +# rc_file does open of file, and $! has error, apparently innocuous +# See ~/proposal/06/latexmkrc-effect + + my $OK = 1; + if ( $! ) { + # Get both numeric error and its string, by forcing numeric and + # string contexts: + my $err_no = $!+0; + my $err_string = "$!"; + warn "$My_name: Initialization file '$rc_file' could not be read,\n", + " or it gave some other problem. Error code \$! = $err_no.\n", + " Error string = '$err_string'\n"; + $! = 256; + $OK = 0; + } + if ( $@ ) { + $! = 256; + # Indent the error message to make it easier to locate + my $indented = prefix( $@, " " ); + $@ = ""; + warn "$My_name: Initialization file '$rc_file' gave an error:\n", + "$indented"; + $OK = 0; + } + if ( ! $OK ) { + die "$My_name: Stopping because of problem with rc file\n"; + } +} #END process_rc_file + +#************************************************************ + +sub execute_code_string { + # Usage execute_code_string( string_of_code ) + # Run the PERL code contained in first argument + # Exit with code 13 if there is a syntax error or other problem. + # ???Should I leave the exiting to the caller (perhaps as an option)? + # But I can always catch it with an eval if necessary. + # That confuses ctrl/C and ctrl/break handling. + my $code = $_[0]; + warn "$My_name: Executing initialization code specified by -e:\n", + " '$code'...\n" + if $diagnostics; + eval $code; + # The return value from the eval is not useful, since it is the value of + # the last expression evaluated, which could be anything. + # The correct test of errors is on the values of $! and $@. + + if ( $@ ) { + $! = 256; + my $message = $@; + $@ = ""; + $message =~ s/\s*$//; + die "$My_name: ", + "Stopping because executing following code from command line\n", + " $code\n", + "gave an error:\n", + " $message\n"; + } +} #END execute_code_string + +#************************************************************ + +sub cleanup1 { + # Usage: cleanup1( exts_without_period, ... ) + foreach (@_) { unlink("$root_filename.$_"); } +} #END cleanup1 + +#************************************************************ +#************************************************************ +#************************************************************ + +# Error handling routines, warning routines, help + +#************************************************************ + +sub die_trace { + # Call: die_trace( message ); + &traceback; # argument(s) passed unchanged + die "\n"; +} #END die_trace + +#************************************************************ + +sub traceback { + # Call: &traceback + # or traceback( message, ) + my $msg = shift; + if ($msg) { warn "$msg\n"; } + warn "Traceback:\n"; + my $i=0; # Start with immediate caller + while ( my ($pack, $file, $line, $func) = caller($i++) ) { + if ($func eq 'die_trace') { next; } + warn " $func called from line $line\n"; + } +} #END traceback + +#************************************************************ + +sub exit_msg1 +{ + # exit_msg1( error_message, retcode [, action]) + # 1. display error message + # 2. if action set, then restore aux file + # 3. exit with retcode + warn "\n------------\n"; + warn "$My_name: $_[0].\n"; + warn "-- Use the -f option to force complete processing.\n"; + + my $retcode = $_[1]; + if ($retcode >= 256) { + # Retcode is the kind returned by system from an external command + # which is 256 * command's_retcode + $retcode /= 256; + } + exit $retcode; +} #END exit_msg1 + +#************************************************************ + +sub warn_running { + # Message about running program: + if ( $silent ) { + warn "$My_name: @_\n"; + } + else { + warn "------------\n@_\n------------\n"; + } +} #END warn_running + +#************************************************************ + +sub exit_help +# Exit giving diagnostic from arguments and how to get help. +{ + warn "\n$My_name: @_\n", + "Use\n", + " $my_name -help\nto get usage information\n"; + exit 10; +} #END exit_help + + +#************************************************************ + +sub print_help +{ + print + "$My_name $version_num: Automatic LaTeX document generation routine\n\n", + "Usage: $my_name [latexmk_options] [filename ...]\n\n", + " Latexmk_options:\n", + " -bm <message> - Print message across the page when converting to postscript\n", + " -bi <intensity> - Set contrast or intensity of banner\n", + " -bs <scale> - Set scale for banner\n", + " -commands - list commands used by $my_name for processing files\n", + " -c - clean up (remove) all nonessential files, except\n", + " dvi, ps and pdf files.\n", + " This and the other clean-ups are instead of a regular make.\n", + " -C - clean up (remove) all nonessential files\n", + " including aux, dep, dvi, postscript and pdf files\n", + " But exclude file of database of file information\n", + " -CA - clean up (remove) absolutely ALL nonessential files\n", + " including aux, dep, dvi, postscript and pdf files,\n", + " and file of database of file information\n", + " -CF - Remove file of database of file information before doing \n", + " other actions\n", + " -cd - Change to directory of source file when processing it\n", + " -cd- - Do NOT change to directory of source file when processing it\n", + " -dependents - Show list of dependent files after processing\n", + " -dependents- - Do not show list of dependent files after processing\n", + " -dF <filter> - Filter to apply to dvi file\n", + " -dvi - generate dvi\n", + " -dvi- - turn off required dvi\n", + " -e <code> - Execute specified PERL code\n", + " -f - force continued processing past errors\n", + " -f- - turn off forced continuing processing past errors\n", + " -F - Ignore non-existent files when testing for dependencies\n", + " -F- - Turn off -F\n", + " -gg - Super go mode: clean out generated files (-CA), and then\n", + " process files regardless of file timestamps\n", + " -g - process regardless of file timestamps\n", + " -g- - Turn off -g\n", + " -h - print help\n", + " -help - print help\n", + " -jobname=STRING - set basename of output file(s) to STRING.\n", + " (Like --jobname=STRING on command line for many current\n", + " implementations of latex/pdflatex.)\n", + " -l - force landscape mode\n", + " -l- - turn off -l\n", + " -new-viewer - in -pvc mode, always start a new viewer\n", + " -new-viewer- - in -pvc mode, start a new viewer only if needed\n", + " -nodependents - Do not show list of dependent files after processing\n", + " -pdf - generate pdf by pdflatex\n", + " -pdfdvi - generate pdf by dvipdf\n", + " -pdfps - generate pdf by ps2pdf\n", + " -pdf- - turn off pdf\n", + " -ps - generate postscript\n", + " -ps- - turn off postscript\n", + " -pF <filter> - Filter to apply to postscript file\n", + " -p - print document after generating postscript.\n", + " (Can also .dvi or .pdf files -- see documentation)\n", + " -print=dvi - when file is to be printed, print the dvi file\n", + " -print=ps - when file is to be printed, print the ps file (default)\n", + " -print=pdf - when file is to be printed, print the pdf file\n", + " -pv - preview document. (Side effect turn off continuous preview)\n", + " -pv- - turn off preview mode\n", + " -pvc - preview document and continuously update. (This also turns\n", + " on force mode, so errors do not cause $my_name to stop.)\n", + " (Side effect: turn off ordinary preview mode.)\n", + " -pvc- - turn off -pvc\n", + " -r <file> - Read custom RC file\n", + " -silent - silence progress messages from called programs\n", + " -v - display program version\n", + " -verbose - display usual progress messages from called programs\n", + " -version - display program version\n", + " -view=default - viewer is default (dvi, ps, pdf)\n", + " -view=dvi - viewer is for dvi\n", + " -view=none - no viewer is used\n", + " -view=ps - viewer is for ps\n", + " -view=pdf - viewer is for pdf\n", + " filename = the root filename of LaTeX document\n", + "\n", + "-p, -pv and -pvc are mutually exclusive\n", + "-h, -c and -C overides all other options.\n", + "-pv and -pvc require one and only one filename specified\n", + "All options can be introduced by '-' or '--'. (E.g., --help or -help.)\n", + "Contents of RC file specified by -r overrides options specified\n", + " before the -r option on the command line\n"; + +} #END print_help + +#************************************************************ +sub print_commands +{ + warn "Commands used by $my_name:\n", + " To run latex, I use \"$latex\"\n", + " To run pdflatex, I use \"$pdflatex\"\n", + " To run bibtex, I use \"$bibtex\"\n", + " To run makeindex, I use \"$makeindex\"\n", + " To make a ps file from a dvi file, I use \"$dvips\"\n", + " To make a ps file from a dvi file with landscape format, ", + "I use \"$dvips_landscape\"\n", + " To make a pdf file from a dvi file, I use \"$dvipdf\"\n", + " To make a pdf file from a ps file, I use \"$ps2pdf\"\n", + " To view a pdf file, I use \"$pdf_previewer\"\n", + " To view a ps file, I use \"$ps_previewer\"\n", + " To view a ps file in landscape format, ", + "I use \"$ps_previewer_landscape\"\n", + " To view a dvi file, I use \"$dvi_previewer\"\n", + " To view a dvi file in landscape format, ", + "I use \"$dvi_previewer_landscape\"\n", + " To print a ps file, I use \"$lpr\"\n", + " To print a dvi file, I use \"$lpr_dvi\"\n", + " To print a pdf file, I use \"$lpr_pdf\"\n", + " To find running processes, I use \"$pscmd\", \n", + " and the process number is at position $pid_position\n"; + warn "Notes:\n", + " Command starting with \"start\" is run detached\n", + " Command that is just \"start\" without any other command, is\n", + " used under MS-Windows to run the command the operating system\n", + " has associated with the relevant file.\n", + " Command starting with \"NONE\" is not used at all\n"; +} #END print_commands + +#************************************************************ + +sub view_file_via_temporary { + return $always_view_file_via_temporary + || ($pvc_view_file_via_temporary && $preview_continuous_mode); +} #END view_file_via_temporary + +#************************************************************ +#### Tex-related utilities + + +sub check_bibtex_log { + # Check for bibtex warnings: + # Usage: check_bibtex_log( base_of_bibtex_run ) + # return 0: OK, 1: bibtex warnings, 2: bibtex errors, + # 3: could not open .blg file. + + my $base = $_[0]; + my $log_name = "$base.blg"; + my $log_file = new FileHandle; + open( $log_file, "<$log_name" ) + or return 3; + my $have_warning = 0; + my $have_error = 0; + while (<$log_file>) { + if (/Warning--/) { + #print "Bibtex warning: $_"; + $have_warning = 1; + } + if (/error message/) { + #print "Bibtex error: $_"; + $have_error = 1; + } + } + close $log_file; + if ($have_error) {return 2;} + if ($have_warning) {return 1;} + return 0; +} #END check_bibtex_log + +#************************************************** + +sub clean_file_name{ + # Convert filename found in log file to true filename. + # Used normally only by parse_logB, below + # 1. For names of form + # `"string".ext', which arises e.g., from \jobname.bbl: + # when the base filename contains spaces, \jobname has quotes. + # and from \includegraphics with basename specified. + # 2. Or "string.ext" from \includegraphcs with basename and ext specified. + my $filename = $_[0]; + $filename =~ s/^\"([^\"]*)\"(.*)$/$1$2/; + return $filename; +} +# ------------------------------ + +sub parse_logB { +# Scan log file for: dependent files +# reference_changed, bad_reference, bad_citation +# Return value: 1 if success, 0 if no log file. +# Set global variables: +# %dependents: maps definite dependents to code: +# 0 = from missing-file line +# May have no extension +# May be missing path +# 1 = from 'File: ... Graphic file (type ...)' line +# no path. Should exist, but may need a search, by kpsewhich. +# 2 = from regular '(...' coding for input file, +# Has NO path, which it would do if LaTeX file +# Highly likely to be mis-parsed line +# 3 = ditto, but has a path character ('/'). +# Should be LaTeX file that exists. +# If it doesn't exist, we have probably a mis-parsed line. +# There's no need to do a search. +# 4 = definitive, which in this subroutine is only +# done for default dependents +# Treat the following specially, since they have special rules +# @bbl_files to list of .bbl files. +# %idx_files to map from .idx files to .ind files. +# Also set +# $reference_changed, $bad_reference, $bad_citation +# Trivial or default values if log file does not exist/cannot be opened + +# Give a quick way of looking up custom-dependency extensions + my %cusdep_from = (); + my %cusdep_to = (); + foreach ( @cus_dep_list ) { + my ($fromext, $toext) = split; + $cusdep_from{$fromext} = $cusdep_from{".$fromext"} = $_; + $cusdep_to{$toext} = $cusdep_to{".$toext"} = $_; + } +# print "==== Cusdep from-exts:"; foreach (keys %cusdep_from) {print " '$_'";} print "\n"; +# print "==== Cusdep to-exts:"; foreach (keys %cusdep_to) {print " '$_'";} print "\n"; + + # Returned info: + %dependents = (); + foreach (@default_includes) { $dependents{$_} = 4; } + @bbl_files = (); + %idx_files = (); # Maps idx_file to (ind_file, base) + + $reference_changed = 0; + $bad_reference = 0; + $bad_citation = 0; + + my $log_name = "$root_filename.log"; + my $log_file = new FileHandle; + if ( ! open( $log_file, "<$log_name" ) ) { + return 0; + } + +LINE: + while(<$log_file>) { + # Could use chomp here, but that fails if there is a mismatch + # between the end-of-line sequence used by latex and that + # used by perl. (Notably a problem with MSWin latex and + # cygwin perl!) + s/[\n\r]*$//; + if ( $. == 1 ){ + if ( /^This is / ) { + # First line OK + next LINE; + } else { + warn "$My_name: Error on first line of '$log_name'. ". + "This is apparently not a TeX log file.\n"; + close $log_file; + $failure = 1; + $failure_msg = "Log file '$log_name' appears to have wrong format."; + return 0; + } + } + # Handle wrapped lines: + # They are lines brutally broken at exactly $log_wrap chars + # excluding line-end. + my $len = length($_); + while ($len == $log_wrap) { + my $extra = <$log_file>; + $extra =~ s/[\n\r]*$//; + $len = length($extra); + $_ .= $extra; + } + # Check for changed references, bad references and bad citations: + if (/Rerun to get/) { + warn "$My_name: References changed.\n"; + $reference_changed = 1; + } + if (/LaTeX Warning: (Reference[^\001]*undefined)./) { + warn "$My_name: $1 \n"; + $bad_reference = 1; + } + if (/LaTeX Warning: (Citation[^\001]*undefined)./) { + warn "$My_name: $1 \n"; + $bad_citation = 1; + } + if ( /^Document Class: / ) { + # Class sign-on line + next LINE; + } + if ( /^\(Font\)/ ) { + # Font info line + next LINE; + } + if ( /^Output written on / ) { + # Latex message + next LINE; + } + if ( /^Overfull / + || /^Underfull / + || /^or enter new name\. \(Default extension: .*\)/ + || /^\*\*\* \(cannot \\read from terminal in nonstop modes\)/ + ) { + # Latex error/warning, etc. + next LINE; + } +# Test for writing of index file. The precise format of the message +# depends on which package (makeidx.sty , multind.sty or index.sty) and +# which version writes the message. + if ( /Writing index file (.*)$/ ) { + my $idx_file = ''; + if ( /^Writing index file (.*)$/ ) { + # From makeidx.sty or multind.sty + $idx_file = $1; + } + elsif ( /^index\.sty> Writing index file (.*)$/ ) { + # From old versions of index.sty + $idx_file = $1; + } + elsif ( /^Package \S* Info: Writing index file (.*) on input line/ ) { + # From new versions of index.sty + $idx_file = $1; + } + else { + warn "$My_name: Message indicates index file was written\n", + " ==> but I do not know how to understand it: <==\n", + " '$_'\n"; + next LINE; + } + # Typically, there is trailing space, not part of filename: + $idx_file =~ s/\s*$//; + $idx_file = clean_file_name($idx_file); + my ($idx_base, $idx_path, $idx_ext) = fileparseA( $idx_file ); + $idx_base = $idx_path.$idx_base; + $idx_file = $idx_base.$idx_ext; + if ( $idx_ext eq '.idx' ) { + warn "$My_name: Index file '$idx_file' was written\n" + unless $silent; + $idx_files{$idx_file} = [ "$idx_base.ind", $idx_base ]; + } + elsif ( exists $cusdep_from{$idx_ext} ) { + if ( !$silent ) { + warn "$My_name: Index file '$idx_file' was written\n"; + warn " Cusdep '$cusdep_from{$idx_ext}' should be used\n"; + } + # No action needed here + } + else { + warn "$My_name: Index file '$idx_file' written\n", + " ==> but it has an extension I do not know how to handle <==\n"; + } + + next LINE; + } + if ( /^No file (.*?\.bbl)./ ) { + # Notice that the + my $bbl_file = clean_file_name($1); + warn "$My_name: Non-existent bbl file '$bbl_file'\n $_\n"; + $dependents{$bbl_file} = 0; + push @bbl_files, $bbl_file; + next LINE; + } + foreach my $pattern (@file_not_found) { + if ( /$pattern/ ) { + my $file = clean_file_name($1); + warn "$My_name: Missing input file: '$file' from line\n '$_'\n" + unless $silent; + $dependents{$file} = 0; + next LINE; + } + } + if ( /^File: ([^\s\[]*) Graphic file \(type / ) { + # First line of message from includegraphics/x + $dependents{$1} = 1; + next LINE; + } + # Now test for generic lines to ignore, only after special cases! + if ( /^File: / ) { + # Package sign-on line. Includegraphics/x also produces a line + # with this signature, but I've already handled it. + next LINE; + } + if ( /^Package: / ) { + # Package sign-on line + next LINE; + } + if (/^\! LaTeX Error: / ) { + next LINE; + } + if (/^No pages of output\./) { + warn "$My_name: Log file says no output from latex\n" + unless $silent; + next LINE; + } + INCLUDE_CANDIDATE: + while ( /\((.*$)/ ) { + # Filename found by + # '(', then filename, then terminator. + # Terminators: obvious candidates: ')': end of reading file + # '(': beginning of next file + # ' ': space is an obvious separator + # ' [': start of page: latex + # and pdflatex put a + # space before the '[' + # '[': start of config file + # in pdflatex, after + # basefilename. + # '{': some kind of grouping + # Problem: + # All or almost all special characters are allowed in + # filenames under some OS, notably UNIX. Luckily most cases + # are rare, if only because the special characters need + # escaping. BUT 2 important cases are characters that are + # natural punctuation + # Under MSWin, spaces are common (e.g., "C:\Program Files") + # Under VAX/VMS, '[' delimits directory names. This is + # tricky to handle. But I think few users use this OS + # anymore. + # + # Solution: use ' [', but not '[' as first try at delimiter. + # Then if candidate filename is of form 'name1[name2]', then + # try splitting it. If 'name1' and/or 'name2' exists, put + # it/them in list, else just put 'name1[name2]' in list. + # So form of filename is now: + # '(', + # then any number of characters that are NOT ')', '(', or '{' + # (these form the filename); + # then ' [', or ' (', or ')', or end-of-string. + # That fails for pdflatex + # In log file: + # '(' => start of reading of file, followed by filename + # ')' => end of reading of file + # '[' => start of page (normally preceeded by space) + # Remember: + # filename (on VAX/VMS) may include '[' and ']' (directory + # separators) + # filenames (on MS-Win) commonly include space. + + # First step: replace $_ by whole of line after the '(' + # Thus $_ is putative filename followed by other stuff. + $_ = $1; + if ( /^([^\(^\)^\{]*?)\s\[/ ) { + # Terminator: space then '[' + # Use *? in condition: to pick up first ' [' as terminator + # 'file [' should give good filename. + } + elsif ( /^([^\(^\)^\{]*)\s(?=\()/ ) { + # Terminator is ' (', but '(' isn't in matched string, + # so we keep the '(' ready for the next match + } + elsif ( /^([^\(^\)^\{]*)(\))/ ) { + # Terminator is ')' + } + elsif ( /^([^\(^\)^\{]*?)\s*\{/ ) { + # Terminator: arbitrary space then '{' + # Use *? in condition: to pick up first ' [' as terminator + # 'file [' should give good filename. + } + else { + #Terminator is end-of-string + } + $_ = $'; # Put $_ equal to the unmatched tail of string ' + my $include_candidate = $1; + $include_candidate =~ s/\s*$//; # Remove trailing space. + if ( $include_candidate eq "[]" ) { + # Part of overfull hbox message + next INCLUDE_CANDIDATE; + } + if ( $include_candidate =~ /^\\/ ) { + # Part of font message + next INCLUDE_CANDIDATE; + } + # Make list of new include files; sometimes more than one. + my @new_includes = ($include_candidate); + if ( $include_candidate =~ /^(.+)\[([^\]]+)\]$/ ) { + # Construct of form 'file1[file2]', as produced by pdflatex + if ( -e $1 ) { + # If the first component exists, we probably have the + # pdflatex form + @new_includes = ($1, $2); + } + else { + # We have something else. + # So leave the original candidate in the list + } + } + INCLUDE_NAME: + foreach my $include_name (@new_includes) { + my ($base, $path, $ext) = fileparseB( $include_name ); + if ( ($path eq './') || ($path eq '.\\') ) { + $include_name = $base.$ext; + } + if ( $include_name !~ m'[/|\\]' ) { + # Filename does not include a path character + # High potential for misparsed line + $dependents{$include_name} = 2; + } else { + $dependents{$include_name} = 3; + } + if ( $ext eq '.bbl' ) { + warn "$My_name: Found input bbl file '$include_name'\n" + unless $silent; + push @bbl_files, $include_name; + } + } # INCLUDE_NAME + } # INCLUDE_CANDIDATE + } # LINE + close($log_file); + + # Default includes are always definitive: + foreach (@default_includes) { $dependents{$_} = 4; } + + ###print "New parse: \n"; + ###foreach (sort keys %dependents) { print " '$_': $dependents{$_}\n"; } + + my @misparsed = (); + my @missing = (); + my @not_found = (); +CANDIDATE: + foreach my $candidate (keys %dependents) { + my $code = $dependents{$candidate}; + if ( -e $candidate ) { + $dependents{$candidate} = 4; + } + elsif ($code == 1) { + # Graphics file that is supposed to have been read. + # Candidate name is as given in source file, not as path + # to actual file. + # We have already tested that file doesn't exist, as given. + # so use kpsewhich. + # If the file still is not found, assume non-existent; + my @kpse_result = kpsewhich( $candidate ); + if ($#kpse_result > -1) { + $dependents{$kpse_result[0]} = 4; + delete $dependents{$candidate}; + next CANDIDATE; + } + else { + push @not_found, $candidate; + } + } + elsif ($code == 2) { + # Candidate is from '(...' construct in log file, for input file + # which should include pathname if valid input file. + # Name does not have pathname-characteristic character (hence + # $code==2. + # Candidate file does not exist with given name + # Almost surely result of a misparsed line in log file. + delete $dependents{$candidate}; + push @misparse, $candidate; + } + elsif ($code == 0) { + my ($base, $path, $ext) = fileparseA($candidate); + $ext =~ s/^\.//; + if ( ($ext eq '') && (-e "$path$base.tex") ) { + $dependents{"$path$base.tex"} = 4; + delete $dependents{$candidate}; + } + push @missing, $candidate; + } + } + + + if ( $diagnostics ) { + @misparse = uniqs( @misparse ); + @missing = uniqs( @missing ); + @not_found = uniqs( @not_found ); + my @dependents = sort( keys %dependents ); + + my $dependents = $#dependents + 1; + my $misparse = $#misparse + 1; + my $missing = $#missing + 1; + my $not_found = $#not_found + 1; + my $exist = $dependents - $not_found - $missing; + my $bbl = $#bbl_files + 1; + + print "$dependents dependent files detected, of which ", + "$exist exist, $not_found were not found,\n", + " and $missing appear not to exist.\n"; + print "Dependents:\n"; + foreach (@dependents) { print " $_\n"; } + if ($not_found > 0) { + print "Not found:\n"; + foreach (@not_found) { print " $_\n"; } + } + if ($missing > 0) { + print "Not existent:\n"; + foreach (@missing) { print " $_\n"; } + } + if ( $bbl > 0 ) { + print "Input bbl files:\n"; + foreach (@bbl_files) { print " $_\n"; } + } + + if ( $misparse > 0 ) { + print "$misparse\n"; + print "Apparent input files appearently from misunderstood lines in .log file:\n"; + foreach ( @misparse ) { print " $_\n"; } + } + } + + return 1; +} #END parse_logB + +#************************************************************ + +sub parse_aux { + #Usage: parse_aux( $aux_file, \@new_bib_files, \@new_aux_files ) + # Parse aux_file (recursively) for bib files. + # If can't open aux file, then + # Return 0 and leave @new_bib_files empty + # Else set @new_bib_files from information in the aux files + # And: + # Return 1 if no problems + # Return 2 with @new_bib_files empty if there are no \bibdata + # lines. + # Return 3 if I couldn't locate all the bib_files + # Set @new_aux_files to aux files parsed + + my $aux_file = $_[0]; + local $Pbib_files = $_[1]; + local $Paux_files = $_[2]; + + @$Pbib_files = (); + @$Paux_files = (); + + parse_aux1( $aux_file ); + if ($#{$Paux_files} < 0) { + return 0; + } + @$Pbib_files = uniqs( @$Pbib_files ); + + if ( $#{$Pbib_files} == -1 ) { + warn "$My_name: No .bib files listed in .aux file '$aux_file' \n", + return 2; + } + my $bibret = &find_file_list1( $Pbib_files, $Pbib_files, + '.bib', \@BIBINPUTS ); + @$Pbib_files = uniqs( @$Pbib_files ); + if ($bibret == 0) { + warn "$My_name: Found bibliography file(s) [@$Pbib_files]\n" + unless $silent; + } + else { + warn "$My_name: Failed to find one or more bibliography files ", + "in [@$Pbib_files]\n"; + if ($force_mode) { + warn "==== Force_mode is on, so I will continue. ", + "But there may be problems ===\n"; + } + else { + #$failure = -1; + #$failure_msg = 'Failed to find one or more bib files'; + #warn "$My_name: Failed to find one or more bib files\n"; + } + return 3; + } + return 1; +} #END parse_aux + +#************************************************************ + +sub parse_aux1 +# Parse single aux file for bib files. +# Usage: &parse_aux1( aux_file_name ) +# Append newly found bib_filenames in @$Pbib_files, already +# initialized/in use. +# Append aux_file_name to @$Paux_files if aux file opened +# Recursively check \@input aux files +# Return 1 if success in opening $aux_file_name and parsing it +# Return 0 if fail to open it +{ + my $aux_file = $_[0]; + my $aux_fh = new FileHandle; + if (! open($aux_fh, $aux_file) ) { + warn "$My_name: Couldn't find aux file '$aux_file'\n"; + return 0; + } + push @$Paux_files, $aux_file; +AUX_LINE: + while (<$aux_fh>) { + if ( /^\\bibdata\{(.*)\}/ ) { + # \\bibdata{comma_separated_list_of_bib_file_names} + # (Without the '.bib' extension) + push( @$Pbib_files, split /,/, $1 ); + } + elsif ( /^\\\@input\{(.*)\}/ ) { + # \\@input{next_aux_file_name} + &parse_aux1( $1 ); + } + } + close($aux_fh); + return 1; +} #END parse_aux1 + +#************************************************************ + +#************************************************************ +#************************************************************ +#************************************************************ + +# Manipulations of main file database: + +#************************************************************ + +sub fdb_get { + # Call: fdb_get(filename) + # Returns an array (time, size, md5) for the current state of the + # named file. + # For non-existent file, deletes entry in fdb_current, and returns (0,-1,0) + my $file = shift; + my ($new_time, $new_size) = get_time_size($file); + my @nofile = (0,-1,0); # What we use for initializing + # a new entry in fdb or flagging + # non-existent file + if ( $new_size < 0 ) { + delete $fdb_current{$file}; + return @nofile; + } + my $recalculate_md5 = 0; + if ( ! exists $fdb_current{$file} ) { + # Ensure we have a record. + $fdb_current{$file} = [@nofile]; + $recalculate_md5 = 1; + } + my $file_data = $fdb_current{$file}; + my ( $time, $size, $md5 ) = @$file_data; + if ( ($new_time != $time) || ($new_size != $size) ) { + # Only force recalculation of md5 if time or size changed + # Else we assume file is really unchanged. + $recalculate_md5 = 1; + } + if ($recalculate_md5) { + @$file_data = ( $new_time, $new_size, get_checksum_md5( $file ) ); + } + return @$file_data;; +} #END fdb_get + +#************************************************************ + +sub fdb_show { + # Displays contents of fdb + foreach my $file ( sort keys %fdb_current ) { + print "'$file': @{$fdb_current{$file}}\n"; + } +} #END fdb_show + +#************************************************************ +#************************************************************ +#************************************************************ + +# Routines for manipulating rule database + +#************************************************************ + +sub rdb_read { + # Call: rdb_read( $in_name ) + # Sets rule database from saved file, in format written by rdb_write. + # Returns -1 if file could not be read else number of errors. + # Thus return value on success is 0 + my $in_name = $_[0]; + + my $in_handle = new FileHandle; + $in_handle->open( $in_name, '<' ) + or return (); + my $errors = 0; + my $state = 0; # Outside a section + my $rule = ''; + my $run_time = 0; + my $source = ''; + my $dest = ''; + my $base = ''; + local %new_sources = (); # Hash: rule => { file=>[ time, size, md5, fromrule ] } + my $new_source = undef; # Reference to hash of sources for current rule +LINE: + while ( <$in_handle> ) { + # Remove leading and trailing white space. + s/^\s*//; + s/\s*$//; + # Ignore blank lines and comments + if ( /^$/ || /^#/ || /^%/ ) { next LINE;} + if ( /^\[\"([^\"]+)\"\]/ ) { + # Start of section + $rule = $1; +#?? print "--- Starting rule '$rule'\n"; + my $tail = $'; #' Single quote in comment tricks the parser in + # emacs from misparsing an isolated single quote + $run_time = 0; + $source = $dest = $base = ''; + if ( $tail =~ /^\s*(\S+)\s*$/ ) { + $run_time = $1; + } + elsif ( $tail =~ /^\s*(\S+)\s+\"([^\"]*)\"\s+\"([^\"]*)\"\s+\"([^\"]*)\"\s*$/ ) { + $run_time = $1; + $source = $2; + $dest = $3; + $base = $4; + } + if ( rdb_rule_exists( $rule ) ) { + rdb_one_rule( $rule, + sub{ $$Ptest_kind = 1; + $$Prun_time = $run_time; + #??if ($source) { $$Psource = $source; } + #??if ($dest) { $$Pdest = $dest; } + #??if ($base) { $$Pbase = $base; } + } + ); + } + elsif ($rule =~ /^cusdep\s+(\S+)\s+(\S+)\s+(.+)$/ ) { + # Create custom dependency + my $fromext = $1; + my $toext = $2; + my $base = $3; + $source = "$base.$fromext"; + $dest = "$base.$toext"; + my $PAnew_cmd = ['do_cusdep', '']; + foreach my $dep ( @cus_dep_list ) { + my ($tryfromext,$trytoext,$must,$func_name) = split(' ',$dep); + if ( ($tryfromext eq $fromext) && ($trytoext eq $toext) ) { + $$PAnew_cmd[1] = $func_name; + } + } + rdb_create_rule( $rule, 'cusdep', '', $PAnew_cmd, 1, + $source, $dest, $base, 0, $run_time ); + } + elsif ( $rule =~ /^(makeindex|bibtex)\s*(.*)$/ ) { + my $rule_generic = $1; + if ( ! $source ) { + # If fdb_file was old-style (v. 1) + $source = $2; + my $path = ''; + my $ext = ''; + ($base, $path, $ext) = fileparseA( $source ); + $base = $path.$base; + if ($rule_generic eq 'makeindex') { + $dest = "$base.ind"; + } + elsif ($rule_generic eq 'bibtex') { + $dest = "$base.bbl"; + $source = "$base.aux"; + } + } + warn "$My_name: File-database '$in_name': setting rule '$rule'\n" + if $diagnostics; + my $cmd_type = 'external'; + my $ext_cmd = ${$rule_generic}; + warn " Rule kind = '$rule_generic'; ext_cmd = '$ext_cmd';\n", + " source = '$source'; dest = '$dest'; base = '$base';\n" + if $diagnostics; + rdb_create_rule( $rule, $cmd_type, $ext_cmd, '', 1, + $source, $dest, $base, 0, $run_time); + } + else { + warn "$My_name: In file-database '$in_name' rule '$rule'\n", + " is not in use in this session\n" + if $diagnostics; + $new_source = undef; + $state = 3; + next LINE; + } + $new_source = $new_sources{$rule} = {}; + $state = 1; #Reading a section + } + elsif ( /^\"([^\"]*)\"\s+(\S+)\s+(\S+)\s+(\S+)\s+\"([^\"]*)\"/ ) { + # Source file line + if ($state == 3) { + # The rule is not being currently used. + next LINE; + } + my $file = $1; + my $time = $2; + my $size = $3; + my $md5 = $4; + my $from_rule = $5; +#?? print " --- File '$file'\n"; + if ($state != 1) { + warn "$My_name: In file-database '$in_name' ", + "line $. is outside a section:\n '$_'\n"; + $errors++; + next LINE; + } + rdb_ensure_file( $rule, $file ); + rdb_set_file1( $rule, $file, $time, $size, $md5 ); + # Save the rest of the data, especially the from_fule until we know all + # the rules, otherwise the from_rule may not exist. + # Also we'll have a better chance of looping through files. + ${$new_source}{$file} = [ $time, $size, $md5, $from_rule ]; + } + elsif ($state == 0) { + # Outside a section. Nothing to do. + } + else { + warn "$My_name: In file-database '$in_name' ", + "line $. is of wrong format:\n '$_'\n"; + $errors++; + next LINE; + } + } + undef $in_handle; + # Set cus dependencies. + &rdb_set_dependentsA( keys %rule_db ); + +#?? Check from_rules exist. + + return $errors; +} # END rdb_read + +#************************************************************ + +sub rdb_read_generatedB { + # Call: rdb_read_generatedB( $in_name, \@extra_generated, \@aux_files ) + # From rule database in saved file, in format written by rdb_write, + # finds the non-basic generated files that are to be deleted by a cleanup. + # Returns an array of these files, or an empty array if the file + # does not exist or cannot be opened. + my ($in_name, $Pgenerated, $Paux_files) = @_; + @$Pgenerated = (); + @$Paux_files = (); + + my $in_handle = new FileHandle; + $in_handle->open( $in_name, '<' ) + or return (); + my $rule = ''; + my $run_time = 0; + my $source = ''; + my $dest = ''; + my $base = ''; + my $ext = ''; + my $path = ''; + my $state = 0; # Outside a section +LINE: + while ( <$in_handle> ) { + # Remove leading and trailing white space. + s/^\s*//; + s/\s*$//; + # Ignore blank lines and comments + if ( /^$/ || /^#/ || /^%/ ) { next LINE;} + if ( /^\[\"([^\"]+)\"\]/ ) { + # Start of section + $rule = $1; + my $tail = $'; #' Single quote in comment tricks the parser in + # emacs from misparsing an isolated single quote + $run_time = 0; + $source = $dest = $base = ''; + if ( $tail =~ /^\s*(\S+)\s+\"([^\"]*)\"\s+\"([^\"]*)\"\s+\"([^\"]*)\"\s*$/ ) { + $source = $2; + $dest = $3; + $base = $4; + } + else { next LINE; } + if ( $rule =~ /^makeindex/ ) { + push @$Pgenerated, $source, $dest, "$base.ilg"; + } + elsif ( $rule =~ /^bibtex/ ) { + push @$Pgenerated, $dest, "$base.blg"; + push @$Paux_files, $source; + } + $state = 1; #Reading a section + } + elsif ( /^\"([^\"]*)\"\s+(\S+)\s+(\S+)\s+(\S+)\s+\"([^\"]*)\"/ ) { + # Source file line + if ($state == 3) { + # The rule is not being currently used. + next LINE; + } + my $file = $1; + ($base, $path, $ext) = fileparseA( $file ); + if ( $ext eq '.aux' ) { push @$Paux_files, $file; } + } + elsif ($state == 0) { + # Outside a section. Nothing to do. + } + else { + warn "$My_name: In file-database '$in_name' ", + "line $. is of wrong format:\n '$_'\n"; + next LINE; + } + } # LINE + undef $in_handle; + +} # END rdb_read_generatedB + +#************************************************************ + +sub rdb_write { + # Call: rdb_write( $out_name ) + # Writes to the given file name the database of file and rule data + # accessible from the primary rules. + # Returns 1 on success, 0 if file couldn't be opened. + local $out_name = $_[0]; + local $out_handle = new FileHandle; + if ( ($out_name eq "") || ($out_name eq "-") ) { + # Open STDOUT + $out_handle->open( '>-' ); + } + else { + $out_handle->open( $out_name, '>' ); + } + if (!$out_handle) { return 0; } + + local %current_primaries = (); # Hash whose keys are primary rules + # needed, i.e., known latex-like rules which trigger + # circular dependencies + local @pre_primary = (); # Array of rules + local @post_primary = (); # Array of rules + local @one_time = (); # Array of rules + &rdb_classify_rules( \%possible_primaries, keys %requested_filerules ); + + print $out_handle "# Fdb version $fdb_ver\n"; + my @rules = sort( + rdb_accessible( + uniq1( keys %known_rules, keys %current_primaries ))); + rdb_for_some( + \@rules, + sub { print $out_handle "[\"$rule\"] $$Prun_time \"$$Psource\" \"$$Pdest\" \"$$Pbase\" \n"; }, + sub { print $out_handle " \"$file\" $$Ptime $$Psize $$Pmd5 \"$$Pfrom_rule\"\n"; }, + ); + undef $out_handle; + return 1; +} #END rdb_write + +#************************************************************ + +sub rdb_set_from_logB { + # Assume rule context. + # This is intended to be applied only for a primary (LaTeX-like) rule + # Starting from the log_file, set current details for the current rule. + + # Rules should only be primary + if ( $$Pcmd_type ne 'primary' ) { + warn "\n$My_name: ==========$My_name: Probable BUG======= \n ", + " rdb_set_from_logB called to set files ", + "for non-primary rule '$rule'\n\n"; + return; + } + + +#?? # We'll prune this by all files determined to be needed for source files. +#?? my %unneeded_source = %$PHsource; + + # Parse log file to find relevant filenames + # Result in the following variables: + local %dependents = (); # Maps files to status + local @bbl_files = (); + local %idx_files = (); # Maps idx_file to (ind_file, base) + + # The following are also returned, but are global, to be used by caller + # $reference_changed, $bad_reference $bad_citation + + &parse_logB; + + IDX_FILE: + foreach my $idx_file ( keys %idx_files ) { + my ($ind_file, $ind_base) = @{$idx_files{$idx_file}}; + my $from_rule = "makeindex $idx_file"; + if ( ! rdb_rule_exists( $from_rule ) ){ + print "!!!===Creating rule '$from_rule': '$ind_file' from '$idx_file'\n" + if ($diagnostics); + rdb_create_rule( $from_rule, 'external', $makeindex, '', 1, + $idx_file, $ind_file, $ind_base, 1, 0); + foreach my $primary ( keys %primaries ) { + print " ===Source file '$ind_file' for '$primary'\n" + if ($diagnostics > -1); + rdb_ensure_file( $primary, $ind_file, $from_rule ); + } + } + if ( ! -e $ind_file ) { + # Failure was non-existence of makable file + # Leave failure issue to other rules. + $failure = 0; + } + } + + BBL_FILE: + foreach my $bbl_file ( uniqs( @bbl_files ) ) { + my ($bbl_base, $bbl_path, $bbl_ext) = fileparseA( $bbl_file ); + $bbl_base = $bbl_path.$bbl_base; + my @new_bib_files; + my @new_aux_files; + &parse_aux( "$bbl_base.aux", \@new_bib_files, \@new_aux_files ); + my $from_rule = "bibtex $bbl_base"; + if ( ! rdb_rule_exists( $from_rule ) ){ + print "!!!===Creating rule '$from_rule'\n" + if ($diagnostics); + rdb_create_rule( $from_rule, 'external', $bibtex, '', 1, + "$bbl_base.aux", $bbl_file, $bbl_base, 1, 0); + foreach my $source ( @new_bib_files, @new_aux_files ) { + print " ===Source file '$source'\n" + if ($diagnostics); + rdb_ensure_file( $from_rule, $source ); + } + foreach my $primary ( keys %primaries ) { + print " ===Source file '$bbl_file' for '$primary'\n" + if ($diagnostics); + rdb_ensure_file( $primary, $bbl_file, $from_rule ); + if ( ! -e $bbl_file ) { + # Failure was non-existence of makable file + # Leave failure issue to other rules. + $failure = 0; + } + } + } + } + +NEW_SOURCE: + foreach my $new_source (keys %dependents) { + foreach my $primary ( keys %primaries ) { + rdb_ensure_file( $primary, $new_source ); + } + } + + my @more_sources = &rdb_set_dependentsA( $rule ); + my $num_new = $#more_sources + 1; + foreach (@more_sources) { + $dependents{$_} = 4; + if ( ! -e $_ ) { + # Failure was non-existence of makable file + # Leave failure issue to other rules. + $failure = 0; + $$Pchanged = 1; # New files can be made. Ignore error. + } + } + if ($diagnostics) { + if ($num_new > 0 ) { + print "$num_new new source files for rule '$rule':\n"; + foreach (@more_sources) { print " '$_'\n"; } + } + else { + print "No new source files for rule '$rule':\n"; + } + } + + my @files_not_needed = (); + foreach (keys %$PHsource) { + if ( ! exists $dependents{$_} ) { + print "Removing no-longer-needed dependent '$_' from rule '$rule'\n" + if $diagnostics>-1; + push @files_not_needed, $_; + } + } + rdb_remove_files( $rule, @files_not_needed ); + +} # END rdb_set_from_logB + +#************************************************************ + +sub rdb_find_new_filesB { + # Call: rdb_find_new_filesB + # Assumes rule context for primary rule. + # Deal with files which were missing and for which a method + # of finding them has become available: + # (a) A newly available source file for a custom dependency. + # (b) When there was no extension, a file with appropriate + # extension + # (c) When there was no extension, and a newly available source + # file for a custom dependency can make it. + + my %new_includes = (); + +MISSING_FILE: + foreach my $missing ( keys %$PHsource ) { + next if ( $$PHsource{$missing} != 0 ); + my ($base, $path, $ext) = fileparseA( $missing ); + $ext =~ s/^\.//; + if ( -e "$missing.tex" ) { + $new_includes{"$missing.tex"} = 1; + } + if ( -e $missing ) { + $new_includes{$missing} = 1; + } + if ( $ext ne "" ) { + foreach my $dep (@cus_dep_list){ + my ($fromext,$toext) = split(' ',$dep); + if ( ( "$ext" eq "$toext" ) + && ( -e "$path$base.$fromext" ) + ) { + # Source file for the missing file exists + # So we have a real include file, and it will be made + # next time by rdb_set_dependents + $new_includes{$missing} = 1; + } + else { + # no point testing the $toext if the file doesn't exist. + } + next MISSING_FILE; + } + } + else { + # $_ doesn't exist, $_.tex doesn't exist, + # and $_ doesn't have an extension + foreach my $dep (@cus_dep_list){ + my ($fromext,$toext) = split(' ',$dep); + if ( -e "$path$base.$fromext" ) { + # Source file for the missing file exists + # So we have a real include file, and it will be made + # next time by &rdb__dependents + $new_includes{"$path$base.$toext"} = 1; +# next MISSING_FILE; + } + if ( -e "$path$base.$toext" ) { + # We've found the extension for the missing file, + # and the file exists + $new_includes{"$path$base.$toext"} = 1; +# next MISSING_FILE; + } + } + } + } # end MISSING_FILES + + # Sometimes bad line-breaks in log file (etc) create the + # impression of a missing file e.g., ./file, but with an incorrect + # extension. The above tests find the file with an extension, + # e.g., ./file.tex, but it is already in the list. So now I will + # remove files in the new_include list that are already in the + # include list. Also handle aliasing of file.tex and ./file.tex. + # For example, I once found: +# (./qcdbook.aux (./to-do.aux) (./ideas.aux) (./intro.aux) (./why.aux) (./basics +#.aux) (./classics.aux) + + my $found = 0; + foreach my $file (keys %new_includes) { + my $stripped = $file; + $stripped =~ s{^\./}{}; + if ( exists $PHsource{$file} ) { + delete $new_includes{$file}; + } + else { + $found ++; + rdb_ensure_file( $rule, $file ); + } + } + +## ?? Is this correct? I used to use @includes +# rdb_update_files_for_rule( keys %PHsources ); + if ( $diagnostics && ( $found > 0 ) ) { + warn "$My_name: Detected previously missing files:\n"; + foreach ( sort keys %new_includes ) { + warn " '$_'\n"; + } + } + return $found; +} # END rdb_find_new_filesB + +#************************************************************ + +sub rdb_update_files_for_rule { +#=========== APPEARS NOT TO BE USED! ========================= +# Usage: rdb_update_files_for_rule( source_files ...) +# Assume rule context. +# Update list of source files for current rule, treating properly cases +# where file didn't exist before run, etc + foreach my $file ( @_ ) { + if ( ! rdb_file_exists( $rule, $file ) ) { + # File that didn't appear in the source files for the run + # before. Two cases: (a) it was created during the run; + # (b) it existed before the run. + # If case (a), then the file was non-existent before the + # run, so we must now label it as non-existent, and + # we trigger a new run +#?? print "?? Adding '$file' to '$rule'\n"; + rdb_ensure_file( $rule, $file ); + my $file_time = get_mtime0( $file ); + if ( ($$Ptest_kind == 2) || ($$Ptest_kind == 3) ) { + # Test wrt destination time, but exclude files + # which appear to be generated (according to extension) + # Assume generated files up-to-date after last run. + # I.e., last run was valid. + my $ext = ext( $file ); + + if ( (! exists $generated_exts_all{$ext} ) + && ($file_time >= $dest_mtime) + ) { + # Only changes since the mtime of the destination matter, + # and only non-generated files count. + # Non-existent destination etc gives $dest_mtime=0 + # so this will automatically give out-of-date condition + # Flag out-of-date for a file by treating it as non-existent + rdb_set_file1( $rule, $file, 0, -1, 0); + } + } + elsif ($file_time >= $$Prun_time ) { + # File generated during run. So treat as non-existent at beginning + rdb_set_file1( $rule, $file, 0, -1, 0); + $$Pout_of_date = 1; + } + # Else default of current state of file is correct. + } # END not previously existent file + } # END file +} # END rdb_update_files_for_rule + +#************************************************************ + +sub rdb_set_dependentsA { + # Call rdb_set_dependentsA( rules ...) + # Returns array (sorted), of new source files. + local @new_sources = (); + rdb_recurseA( [@_], 0, \&rdb_one_depA ); + &rdb_make_links; + return uniqs( @new_sources ); +} #END rdb_set_dependentsA + +#************************************************************ + +sub rdb_one_depA { + # Helper for finding dependencies. One case, $rule and $file given + # Assume file (and rule) context for DESTINATION file. + local $new_dest = $file; + my ($base_name, $path, $toext) = fileparseA( $new_dest ); + $base_name = $path.$base_name; + $toext =~ s/^\.//; +DEP: + foreach my $dep ( @cus_dep_list ) { + my ($fromext,$proptoext,$must,$func_name) = split(' ',$dep); + if ( $toext eq $proptoext ) { + my $source = "$base_name.$fromext"; + # Found match of rule + if ($diagnostics) { + print "Found cusdep: $source to make $rule:$new_dest ====\n"; + } + if ( -e $source ) { + $$Pfrom_rule = "cusdep $fromext $toext $base_name"; +#?? print "?? Ensuring rule for '$$Pfrom_rule'\n"; + local @PAnew_cmd = ( 'do_cusdep', $func_name ); + if ( !-e $new_dest ) { + push @new_sources, $new_dest; + } + if (! rdb_rule_exists( $$Pfrom_rule ) ) { + rdb_create_rule( $$Pfrom_rule, 'cusdep', '', \@PAnew_cmd, 3, + $source, $new_dest, $base_name, 0 ); + } + else { + rdb_one_rule( + $$Pfrom_rule, + sub{ @$PAint_cmd = @PAnew_cmd; $$Pdest = $new_dest;} + ); + } + return; + } + else { + # Source file does not exist + if ( !$force_mode && ( $must != 0 ) ) { + # But it is required that the source exist ($must !=0) + $failure = 1; + $failure_msg = "File '$base_name.$fromext' does not exist ". + "to build '$base_name.$toext'"; + return; + } + elsif ( $$Pfrom_rule =~ /^cusdep $fromext $toext / ) { + # Source file does not exist, destination has the rule set. + # So turn the from_rule off + $$Pfrom_rule = ''; + } + else { + } + } + } + elsif ( ($toext eq '') && (! -e $file ) ) { + # Empty extension and non-existent destination + # This normally results from \includegraphics{A} + # without graphics extension for file, when file does + # not exist. So we will try to find something to make it. + my $source = "$base_name.$fromext"; + if ( -e $source ) { + $new_dest = "$base_name.$proptoext"; + my $from_rule = "cusdep $fromext $toext $base_name"; + push @new_sources, $new_dest; + print "Ensuring rule for '$from_rule', to make '$new_dest'\n" + if $diagnostics > -1; + local @PAnew_cmd = ( 'do_cusdep', $func_name ); + if (! rdb_rule_exists( $from_rule ) ) { + rdb_create_rule( $from_rule, 'cusdep', '', \@PAnew_cmd, 3, + $source, $new_dest, $base_name, 0); + } + else { + rdb_one_rule( + $$Pfrom_rule, + sub{ @$PAint_cmd = @PAnew_cmd; $$Pdest = $new_dest;} + ); + } + rdb_ensure_file( $rule, $new_dest, $from_rule ); + return; + } + } # End of Rule found + } # End DEP +} #END rdb_one_depA + +#************************************************************ + +sub rdb_list { + # Call: rdb_list() + # List rules and their source files + print "===Rules:\n"; + local $count_rules = 0; + my @accessible_all = rdb_accessible( keys %requested_filerules ); + rdb_for_some( + \@accessible_all, + sub{ $count_rules++; + print "Rule '$rule' depends on:\n"; + }, + sub{ print " '$file'\n"; } + ); + if ($count_rules <= 0) { + print " ---No rules defined\n"; + } +} #END rdb_list + +#************************************************************ + +sub rdb_show { + # Call: rdb_show() + # Displays contents of rule data base. + # Side effect: Exercises access routines! + print "===Rules:\n"; + local $count_rules = 0; + rdb_for_all( + sub{ $count_rules++; + my @int_cmd = @$PAint_cmd; + foreach (@int_cmd) { + if ( !defined($_) ) { $_='undef';} + } + print " [$rule]: '$$Pcmd_type' '$$Pext_cmd' '@int_cmd' $$Ptest_kind ", + "'$$Psource' '$$Pdest' '$$Pbase' $$Pout_of_date $$Pout_of_date_user\n"; }, + sub{ print " '$file': $$Ptime $$Psize $$Pmd5 '$$Pfrom_rule'\n"; } + ); + if ($count_rules <= 0) { + print " ---No rules defined\n"; + } +} #END rdb_show + +#************************************************************ + +sub rdb_accessible { + # Call: rdb_accessible( rule, ...) + # Returns array of rules accessible from the given rules + local @accessible = (); + rdb_recurseA( [@_], sub{ push @accessible, $rule; } ); + return @accessible; +} #END rdb_accessible + +#************************************************************ + +sub rdb_possible_primaries { + # Returns array of possible primaries + my @rules = (); + foreach my $rule ( keys %known_rules ) { + if ( $known_rules{$rule} eq 'primary') { + push @rules, $rule; + } + } + return @rules; +} #END rdb_possible_primaries + +#************************************************************ +#************************************************************ +#************************************************************ + +# Routines for makes. NEW VERSIONS ?? + +#????????Debugging routines: +sub R1 {print "===START $rule\n"} +sub R2 {print "===END $rule\n"} +sub F1 {print " ---START $file\n"} +sub F2 {print " ---END $file\n"} +#************************************************************ + +sub rdb_makeB { + # Call: rdb_makeB( target, ... ) + # Makes the targets and prerequisites. + # Leaves one-time rules to last. + # Does appropriate repeated makes to resolve dependency loops + + # Returns 0 on success, nonzero on failure. + + # General method: Find all accessible rules, then repeatedly make + # them until all accessible rules are up-to-date and the source + # files are unchanged between runs. On termination, all + # accessible rules have stable source files. + # + # One-time rules are view and print rules that should not be + # repeated in an algorithm that repeats rules until the source + # files are stable. It is the calling routine's responsibility to + # arrange to call them, or to use them here with caution. + # + # Note that an update-viewer rule need not be considered + # one-time. It can be legitimately applied everytime the viewed + # file changes. + # + # Note also that the criterion of stability is to be applied to + # source files, not to output files. Repeated application of a + # rule to IDENTICALLY CONSTANT source files may produce different + # output files. This may be for a trivial reason (e.g., the + # output file contains a time stamp, as in the header comments for + # a typical postscript file), or for a non-trivial reason (e.g., a + # stochastic algorithm, as in abcm2ps). + # + # This caused me some actual trouble. In general, circular + # dependencies produce non-termination, and the the following + # situation is an example of a generic situation where certain + # rules must be obeyed in order to obtain proper results: + # 1. A/the latex source file contains specifications for + # certain postprocessing operations. Standard (pdf)latex + # already has this, for indexing and bibliography. + # 2. In the case in point that caused me trouble, the + # specification was for musical tunes that were contained + # in external source files not directly input to + # (pdf)latex. But in the original version, there was a + # style file (abc.sty) that caused latex itself to call + # abcm2ps to make .eps files for each tune that were to be + # read in on the next run of latex. + # 3. Thus the specification can cause a non-terminating loop + # for latexmk, because the output files of abcm2ps changed + # even with identical input. + # 4. The solution was to + # a. Use a style file abc_get.sty that simply wrote the + # specification on the tunes to the .aux file in a + # completely deterministic fashion. + # b. Instead of latex, use a script abclatex.pl that runs + # latex and then extracts the abc contents for each tune + # from the source abc file. This is also + # deterministic. + # c. Use a cusdep rule in latexmk to convert the tune abc + # files to eps. This is non-deterministic, but only + # gets called when the (deterministic) source file + # changes. + # This solves the problem. Latexmk works. Also, it is no + # longer necessary to enable write18 in latex, and multiple + # unnecessary runs of abcm2ps are no longer used. + # + # The order of testing and applying rules is chosen by the + # following heuristics: + # 1. Both latex and pdflatex may be used, but the resulting + # aux files etc may not be completely identical. Define + # latex and pdflatex as primary rules. Apply the general + # method of repeated circulating through all rules until + # the source files are stable for each primary rule + # separately. Naturally the rules are all accessible + # rules, but excluding primary rules except for the current + # primary. + # 2. Assume that the primary rules are relatively + # time-consuming, so that unnecessary passes through them + # to check stability of the source files should be avoided. + # 3. Assume that although circular dependencies exist, the + # rules can nevertheless be thought of as basically + # non-circular, and that many rules are strictly or + # normally non-circular. In particular cusdep rules are + # typically non-circular (e.g., fig2eps), as are normal + # output processing rules like dvi2ps. + # 4. The order for the non-circular approximation is + # determined by applying the assumption that an output file + # from one rule that is read in for an earlier stage is + # unchanged. + # HOWEVER, at a first attempt, the ordering is not needed. It + # only gives an optimization + # 5. (Note that these assumptions could be violated, e.g., if + # $dvips is arranged not only to do the basic dvips + # command, but also to extract information from the ps file + # and feed it back to an input file for (pdf)latex.) + # 6. Nevertheless, the overall algorithm should allow + # circularities. Then the general criterion of stability + # of source files covers the general case, and also + # robustly handles the case that the USER changes source + # files during a run. This is particularly important in + # -pvc mode, given that a full make on a large document can + # be quite lengthy in time, and moreover that a user + # naturally wishes to make corrections in response to + # errors, particularly latex errors, and have them apply + # right away. + # This leads to the following approach: + # 1. Classify accessible rules as: primary, pre-primary + # (typically cusdep, bibtex, makeindex, etc), post-primary + # (typically dvips, etc), and one-time + # 2. Then stratify the rules into an order of application that + # corresponds to the basic feedforward structure, with the + # exclusion of one-time rules. + # 3. Always require that one-time rules are among the + # explicitly requested rules, i.e., the last to be applied, + # were we to apply them. Anything else would not match the + # idea of a one-time rule. + # 4. Then work as follows: + # a. Loop over primaries + # b. For each primary, examine each pre-primary rule and + # apply if needed, then the primary rule and then each + # post-primary rule. The ordering of the pre-primary + # and post-primary rules was found in step 2. + # BUT applying the ordering is not essential + # c. Any time that a pre-primary or primary rule is + # applied, loop back to the beginning of step b. This + # ensures that bibtex etc are applied before rerunning + # (pdf)latex, and also covers changing source files, and + # gives priority to quick pre-primary rules for changing + # source files against slow reruns of latex. + # d. Then apply post-primary rules in order, but not + # looping back after each rule. This non-looping back + # is because the rules are normally feed-forward only. + # BUT applying the ordering is not essential + # e. But after completing post-primary rules do loop back + # to b if any rules were applied. This covers exotic + # circular dependence (and as a byproduct, changing + # source files). + # f. On each case of looping back to b, re-evaluate the + # dependence setup to allow for the effect of changing + # source files. + # + + local @requested_targets = @_; + local %current_primaries = (); # Hash whose keys are primary rules + # needed, i.e., known latex-like rules which trigger + # circular dependencies + local @pre_primary = (); # Array of rules + local @post_primary = (); # Array of rules + local @one_time = (); # Array of rules + + + # For diagnostics on changed files, etc: + local @changed = (); + local @disappeared = (); + local @no_dest = (); # Non-existent destination files + local @rules_to_apply = (); + + &rdb_classify_rules( \%possible_primaries, @requested_targets ); + + local %pass = (); + local $failure = 0; # General accumulated error flag + local $runs = 0; + local $too_many_runs = 0; + local %rules_applied = (); + my $retry_msg = 0; # Did I earlier say I was going to attempt + # another pass after a failure? + PRIMARY: + foreach my $primary (keys %current_primaries ) { + foreach my $rule (keys %rule_db) { + $pass{$rule} = 0; + } + PASS: + while (1==1) { + $runs = 0; + my $previous_failure = $failure; + $failure = 0; + local $newrule_nofile = 0; # Flags whether rule created for + # making currently non-existent file, which + # could become a needed source file for a run + # and therefore undo an error condition + if ($diagnostics) { + print "MakeB: doing pre_primary and primary...\n"; + } + rdb_for_some( [@pre_primary, $primary], \&rdb_makeB1 ); + if ( ($runs > 0) && ! $too_many_runs ) { + $retry_msg = 0; + if ( $failure && $newrule_nofile ) { + $retry_msg = 1; + print "$My_name: Error on run, but found possibility to ", + "make new source files\n"; + next PASS; + } + elsif ( ! $failure ) { + next PASS; + } + } + elsif ($runs == 0) { + # $failure not set on this pass, so use value from previous pass: + $failure = $previous_failure; + if ($retry_msg) { + print "But in fact no new files made\n"; + } + } + if ($failure && !$force_mode ) { last PASS; } + if ($diagnostics) { + print "MakeB: doing post_primary...\n"; + } + rdb_for_some( [@post_primary], \&rdb_makeB1 ); + if ($failure) { last PASS; } + if ($runs > 0) { next PASS; } + # Get here if nothing was run. + last PASS; + } + continue { + # Re-evaluate rule classification and accessibility, + # but do not change primaries. + &rdb_classify_rules( \%current_primaries, @requested_targets ); + &rdb_make_links; + } + } + rdb_for_some( [@one_time], \&rdb_makeB1 ); + rdb_write( $fdb_file ); + + if (! $silent) { + # Diagnose of the runs + if ( $#{keys %rules_applied } > -1 ) { + print "$My_name: $runs runs. Rules applied:\n"; + foreach (sort keys %rules_applied) { + print " '$_'\n"; + } + } + elsif ($failure && $force_mode) { + print "$My_name: Errors, in force_mode: so I tried finishing targets\n"; + } + elsif ($failure) { + print "$My_name: Errors, so I did not complete making targets\n"; + } + else { + local @dests = (); + rdb_for_some( [@_], sub{ push @dests, $$Pdest if ($$Pdest); } ); + print "$My_name: All targets (@dests) are up-to-date\n"; + } + } + return $failure; +} #END rdb_makeB + +#------------------- + +sub rdb_makeB1 { + # Call: rdb_makeB1 + # Helper routine for rdb_makeB. + # Carries out make at level of given rule (all data available). + # Assumes contexts for recursion, make, and rule, and + # assumes that source files for the rule are to be considered + # up-to-date. + if ($diagnostics) { print " MakeB1 $rule\n"; } + if ($failure & ! $force_mode) {return;} + &rdb_clear_change_record; + &rdb_flag_changes_here; +# if ($diagnostics>-1) { print " MakeB1.1 $rule $$Pout_of_date\n"; } + + my $return = 0; # Return code from called routine +#?? print "makeB1: Trying '$rule' for '$$Pdest': "; + if (!$$Pout_of_date) { +#?? if ( ($$Pcmd_type eq 'primary') && (! $silent) ) { +# print "Rule '$rule' up to date\n"; +# } + return; + } + if ($diagnostics) { print " remake\n"; } + if (!$silent) { + print "$My_name: applying rule '$rule'...\n"; + &rdb_diagnose_changes( "Rule $rule: "); + } +##????????????????????????????????????: variable rules_applied not used + $rules_applied{$rule} = 1; + $runs++; +#?? print "$rule: $$Pcmd_type\n"; + + # We are applying the rule, so its source file state for when it + # was last made is as of now: + # ??IS IT CORRECT TO DO NOTHING IN CURRENT VERSION? + + # The actual run + $return = 0; + # Rule may have been created since last run: + if ( ! defined $pass{$rule} ) {$pass{$rule} = 0; } + if ( $pass{$rule} ge $max_repeat ) { + # Avoid infinite loop by having a maximum repeat count + # Getting here represents some kind of weird error. + warn "$My_name: Maximum runs of $rule reached ", + "without getting stable files\n"; + $too_many_runs = 1; + $failure = 1; + $failure_msg = "'$rule' needed too many passes"; + return; + } + $pass{$rule}++; + warn_running( "Run number $pass{$rule} of rule '$rule'" ); + if ($$Pcmd_type eq 'primary' ) { + $return = &rdb_primary_run; + } + else { $return = &rdb_run1; } + if ($$Pchanged) { + $newrule_nofile = 1; + $return = 0; + } + elsif ( $$Pdest && ( !-e $$Pdest ) && (! $failure) ){ + # If there is a destination to make, but for some reason + # it did not get made, then make sure a failure gets reported. + # But if the failure has already been reported, there's no need + # to report here, since that would give a generic error + # message instead of a specific one. + +## ??? 1 Sep. 2008, for cusdep no-file-exists issue + if ( ( $$Pcmd_type eq 'cusdep') && $$Psource && (! -e $$Psource) ) { + # However, if the rule is a custom dependency, this is not by + # itself an error, if also the source file does not exist. In + # that case, we may have the situation that (1) the dest file is no + # longer needed by the tex file, and (2) therefore the user + # has deleted the source and dest files. After the next + # latex run and the consequent analysis of the log file, the + # cusdep rule will no longer be needed, and will be removed. + + # So in this case, do NOT report an error + $$Pout_of_date = 0; + } + else { + $failure = 1; + $failure_msg = "'$rule' did not make '$$Pdest'"; + } + } + if ($return != 0) {$failure = 1;} +} #END rdb_makeB1 + +#************************************************************ + +sub rdb_submakeB { + # Call: rdb_submakeB + # Makes all the source files for a given rule. + # Assumes contexts for recursion, for make, and rule. + %visited = %visited_at_rule_start; + local $failure = 0; # Error flag + my @v = keys %visited; +#?? print "---submakeB $rule. @v \n"; + rdb_do_files( sub{ rdb_recurse_rule( $$Pfrom_rule, 0,0,0, \&rdb_makeB1 ) } ); + return $failure; +} #END rdb_submakeB + +#************************************************************ + + +sub rdb_classify_rules { + # Usage: rdb_classify_rules( \%allowed_primaries, requested targets ) + # Assume the following variables are available (global or local): + # Input: + # @requested_targets # Set to target rules + + # Output: + # %current_primaries # Keys are actual primaries + # @pre_primary # Array of rules + # @post_primary # Array of rules + # @one_time # Array of rules + # @pre_primary and @post_primary are in natural order of application. + + local $P_allowed_primaries = shift; + local @requested_targets = @_; + local $state = 0; # Post-primary + local @classify_stack = (); + + %current_primaries = (); + @pre_primary = (); + @post_primary = (); + @one_time = (); + + rdb_recurseA( \@requested_targets, \&rdb_classify1, 0,0, \&rdb_classify2 ); + + # Reverse, as tendency is to find last rules first. + @pre_primary = reverse @pre_primary; + @post_primary = reverse @post_primary; + + if ($diagnostics) { + print "Rule classification: \n"; + if ($#requested_targets < 0) { + print " No requested rules\n"; + } + else { + print " Requested rules:\n"; + foreach ( @requested_targets ) { print " $_\n"; } + } + if ($#pre_primary < 0) { + print " No pre-primaries\n"; + } + else { + print " Pre-primaries:\n"; + foreach (@pre_primary) { print " $_\n"; } + } + print " Primaries:\n"; + foreach (keys %current_primaries) { print " $_\n"; } + if ($#post_primary < 0) { + print " No post-primaries\n"; + } + else { + print " Post-primaries:\n"; + foreach (@post_primary) { print " $_\n"; } + } + if ($#one_time < 0) { + print " No one_time rules\n"; + } + else { + print " One_time rules:\n"; + foreach ( @one_time ) { print " $_\n"; } + } + } #end diagnostics +} #END rdb_classify_rules + +#------------------- + +sub rdb_classify1 { + # Helper routine for rdb_classify_rules + # Applied as rule_act1 in recursion over rules + # Assumes rule context, and local variables from rdb_classify_rules +# print "=========== '$rule' $depth ========== \n"; + push @classify_stack, [$state]; + if ( exists $possible_one_time{$rule} ) { + # Normally, we will have already extracted the one_time rules, + # and they will never be accessed here. But just in case of + # problems or generalizations, we will cover all possibilities: + if ($depth > 1) { + warn "ONE TIME rule not at outer level '$rule'\n"; + } + push @one_time, $rule; + } + elsif ($state == 0) { + if ( exists ${$P_allowed_primaries}{$rule} ) { + $state = 1; # In primary rule + $current_primaries{ $rule } = 1; + } + else { + push @post_primary, $rule; + } + } + else { + $state = 2; # in post-primary rule + push @pre_primary, $rule; + } +} #END rdb_classify1 + +#------------------- + +sub rdb_classify2 { + # Helper routine for rdb_classify_rules + # Applied as rule_act2 in recursion over rules + # Assumes rule context + ($state) = @{ pop @classify_stack }; +} #END rdb_classify2 + +#************************************************************ + + +sub rdb_run1 { + # Assumes contexts for: rule. + # Unconditionally apply the rule + # Returns return code from applying the rule. + # Otherwise: 0 on other kind of success, -1 on error. + + # Source file data, by definition, correspond to the file state just before + # the latest run, and the run_time to the time just before the run: + &rdb_update_filesA; + $$Prun_time = time; + $$Pchanged = 0; # No special changes in files + + # Return values for external command: + my $return = 0; + + # Find any internal command + my @int_args = @$PAint_cmd; + my $int_cmd = shift @int_args; + my @int_args_for_printing = @int_args; + foreach (@int_args_for_printing) { + if ( ! defined $_ ) { $_ = 'undef'; } + } + if ($int_cmd) { + print "For rule '$rule', running '\&$int_cmd( @int_args_for_printing )' ...\n"; + $return = &$int_cmd( @int_args ); + } + elsif ($$Pext_cmd) { + $return = &rdb_ext_cmd; + } + else { + warn "$My_name: Either a bug OR a configuration error:\n", + " Need to implement the command for '$rule'\n"; + &traceback(); + $return = -1; + } + if ( $rule =~ /^bibtex/ ) { + my $retcode = &check_bibtex_log($$Pbase); + if ($retcode == 3) { + push @warnings, + "Could not open bibtex log file for '$$Pbase'"; + } + elsif ($retcode == 2) { + push @warnings, "Bibtex errors for '$$Pbase'"; + } + elsif ($retcode == 1) { + push @warnings, "Bibtex warnings for '$$Pbase'"; + } + } + + $updated = 1; + if ($$Ptest_kind == 3) { + # We are time-criterion first time only. Now switch to + # file-change criterion + $$Ptest_kind = 1; + } + $$Pout_of_date = $$Pout_of_date_user = 0; + return $return; +} # END rdb_run1 + +#----------------- + +sub rdb_ext_cmd { + # Call: rdb_ext_cmd + # Assumes rule context. Runs external command with substitutions. + # Uses defaults for the substitutions. See rdb_ext_cmd1. + return rdb_ext_cmd1(); +} #END rdb_ext_cmd + +#----------------- + +sub rdb_ext_cmd1 { + # Call: rdb_ext_cmd1( options, source, dest, base ) or rdb_ext_cmd1() or ... + # Assumes rule context. Returns command with substitutions. + # Null arguments or unprovided arguments => use defaults. + # for %S=source, %D=dest, %B=base, %R=root=base for latex, %O='', %T=texfile + my ($options, $source, $dest, $base ) = @_; + # Apply defaults + $options ||= ''; + $source ||= $$Psource; + $dest ||= $$Pdest; + $base ||= $$Pbase; + + my $ext_cmd = $$Pext_cmd; + + #Set character to surround filenames: + my $q = $quote_filenames ? '"' : ''; + foreach ($ext_cmd) { + s/%O/$options/g; + s/%R/$q$root_filename$q/g; + s/%B/$q$base$q/g; + s/%T/$q$texfile_name$q/g; + s/%S/$q$source$q/g; + s/%D/$q$dest$q/g; + } + # print "quote is '$q'; ext_cmd = '$ext_cmd'\n"; + my ($pid, $return) = &Run_msg($ext_cmd); + return $return; +} #END rdb_ext_cmd1 + +#----------------- + +sub rdb_primary_run { +#?? See multipass_run in previous version Aug 2007 for issues + # Call: rdb_primary_run + # Assumes contexts for: recursion, make, & rule. + # Assumes (a) the rule is a primary, + # (b) a run has to be made, + # (c) source files have been made. + # This routine carries out the run of the rule unconditionally, + # and then parses log file etc. + my $return = 0; + + my $return_latex = &rdb_run1; + + ######### Analyze results of run: + if ( ! -e "$root_filename.log" ) { + $failure = 1; + $failure_msg = "(Pdf)LaTeX failed to generate a log file"; + return -1; + } + ####### NOT ANY MORE! Capture any changes in source file status before we + # check for errors in the latex run + + # Find current set of source files: + &rdb_set_from_logB; + + # For each file of the kind made by epstopdf.sty during a run, + # if the file has changed during a run, then the new version of + # the file will have been read during the run. Unlike the usual + # case, we will need to redo the primary run because of the + # change of this file during the run. Therefore set the file as + # up-to-date: + rdb_do_files( sub { if ($$Pcorrect_after_primary) {&rdb_update1;} } ); + + # There may be new source files, and the run may have caused + # circular-dependency files to be changed. And the regular + # source files may have been updated during a lengthy run of + # latex. So redo the makes for sources of the current rule: + my $submake_return = &rdb_submakeB; + &rdb_clear_change_record; + &rdb_flag_changes_here; + $updated = 1; # Flag that some dependent file has been remade + # Fix the state of the files as of now: this will solve the + # problem of latex and pdflatex interfering with each other, + # at the expense of some non-optimality + #?? Check this is correct: + &rdb_update_filesA; + if ( $diagnostics ) { + print "$My_name: Rules after run: \n"; + rdb_show(); + } + + $return = $return_latex; + if ($return_latex && $$Pout_of_date_user) { + print "Error in (pdf)LaTeX, but change of user file(s), ", + "so ignore error & provoke rerun\n" + if (! $silent); + $return = 0; + } + + # Summarize issues that may have escaped notice: + my @warnings = (); + if ($bad_reference) { + push @warnings, "Latex could not resolve all references"; + } + if ($bad_citation) { + push @warnings, "Latex could not resolve all citations"; + } + if ($#warnings > 0) { + show_array( "$My_name: Summary of warnings:", @warnings ); + } + return $return; +} #END rdb_primary_run + +#************************************************************ + +sub rdb_clear_change_record { + @changed = (); + @disappeared = (); + @no_dest = (); + @rules_to_apply = (); +#??????????????? $failure = 0; +##????????????????????????????????????: variable rules_applied not used + $rules_applied = 0; +} #END rdb_clear_change_record + +#************************************************************ + +sub rdb_flag_changes_here { + # Flag changes in current rule. + # Assumes rule context. + local $dest_mtime = 0; + $dest_mtime = get_mtime($$Pdest) if ($$Pdest); + rdb_do_files( \&rdb_file_change1); + if ( $$Pdest && (! -e $$Pdest) ) { +## ??? 1 Sep. 2008, for cusdep no-file-exists issue + if ( ( $$Pcmd_type eq 'cusdep') && $$Psource && (! -e $$Psource) ) { + # However, if the rule is a custom dependency, this is not by + # itself an error, if also the source file does not exist. In + # that case, we may have the situation that (1) the dest file is no + # longer needed by the tex file, and (2) therefore the user + # has deleted the source and dest files. After the next + # latex run and the consequent analysis of the log file, the + # cusdep rule will no longer be needed, and will be removed. + + # So in this case, do NOT report an error + } + else { + $$Pout_of_date = 1; + push @no_dest, $$Pdest; + } + } + if ($$Pout_of_date) { + push @rules_to_apply, $rule; + } +#?? print "======== flag: $rule $$Pout_of_date ==========\n"; +} #END rdb_flag_changes_here + +#************************************************************ + +sub rdb_file_change1 { + # Call: &rdb_file_change1 + # Assumes rule and file context. Assumes $dest_mtime set. + # Flag whether $file in $rule has changed or disappeared. + # Set rule's make flag if there's a change. + my ($new_time, $new_size, $new_md5) = fdb_get($file); +#?? print "FC1 '$rule':$file $$Pout_of_date TK=$$Ptest_kind\n"; +#?? print " OLD $$Ptime, $$Psize, $$Pmd5\n", +#?? " New $new_time, $new_size, $new_md5\n"; + my $ext = ext( $file ); + if ( ($new_size < 0) && ($$Psize >= 0) ) { + print "Disappeared '$file' in '$rule'\n"; + push @disappeared, $file; + # No reaction is good. + #$$Pout_of_date = 1; + # ??? 1 Sep. 2008: I do NOT think so, for cusdep no-file-exists issue + $$Pout_of_date = 1; + return; + } + if ( ($new_size < 0) && ($$Psize < 0) ) { + return; + } + if ( ($new_size != $$Psize) || ($new_md5 ne $$Pmd5) ) { +#?? print "FC1: changed $file: ($new_size != $$Psize) $new_md5 ne $$Pmd5)\n"; + push @changed, $file; + $$Pout_of_date = 1; + if ( ! exists $generated_exts_all{$ext} ) { + $$Pout_of_date_user = 1; + } + } + if ( ( ($$Ptest_kind == 2) || ($$Ptest_kind == 3) ) + && (! exists $generated_exts_all{$ext} ) + && ( $new_time > $dest_mtime ) + ) { +#?? print "FC1: changed $file: ($new_time > $dest_mtime)\n"; + push @changed, $file; + $$Pout_of_date = $$Pout_of_date_user = 1; + } +} #END rdb_file_change1 + +#************************************************************ + +sub rdb_count_changes { + return $#changed + $#disappeared + $#no_dest + $#rules_to_apply + 4; +} #END rdb_count_changes + +#************************************************************ + +sub rdb_diagnose_changes { + # Call: rdb_diagnose_changes or rdb_diagnose_changes( heading ) + # List changes on STDERR + # Precede the message by the optional heading, else by "$My_name: " + my $heading = defined($_[0]) ? $_[0] : "$My_name: "; + + if ( &rdb_count_changes == 0 ) { + warn "${heading}No changes\n"; + return; + } + warn "${heading}Changes:\n"; + if ( $#changed >= 0 ) { + warn " Changed files, or newly in use since previous run(s):\n"; + foreach (uniqs(@changed)) { warn " '$_'\n"; } + } + if ( $#disappeared >= 0 ) { + warn " No-longer-existing files:\n"; + foreach (uniqs(@disappeared)) { warn " '$_'\n"; } + } + if ( $#no_dest >= 0 ) { + warn " Non-existent destination files:\n"; + foreach (uniqs(@no_dest)) { warn " '$_'\n"; } + } + if ( $#rules_to_apply >= 0 ) { + warn " Rules to apply:\n"; + foreach (uniqs(@rules_to_apply)) { warn " '$_'\n"; } + } +} #END rdb_diagnose_changes + + +#************************************************************ +#************************************************************ +#************************************************************ +#************************************************************ + +#************************************************************ +#************************************************************ +#************************************************************ +#************************************************************ + +# Routines for convenient looping and recursion through rule database +# ================= NEW VERSION ================ + +# There are several places where we need to loop through or recurse +# through rules and files. This tends to involve repeated, tedious +# and error-prone coding of much book-keeping detail. In particular, +# working on files and rules needs access to the variables involved, +# which either involves direct access to the elements of the database, +# and consequent fragility against changes and upgrades in the +# database structure, or involves lots of routines for reading and +# writing data in the database, then with lots of repetitious +# house-keeping code. +# +# The routines below provide a solution. Looping and recursion +# through the database are provided by a set of basic routines where +# each necessary kind of looping and iteration is coded once. The +# actual actions are provided as references to action subroutines. +# (These can be either actual references, as in \&routine, or +# anonymous subroutines, as in sub{...}, or aas a zero value 0 or an +# omitted argument, to indicate that no action is to be performed.) +# +# When the action subroutine(s) are actually called, a context for the +# rule and/or file (as appropriate) is given by setting named +## NEW ?? +# variables to REFERENCES to the relevant data values. These can be +# used to retrieve and set the data values. As a convention, +# references to scalars are given by variables named start with "$P", +# as in "$Pdest", while references to arrays start with "$PA", as in +# "$PAint_cmd", and references to hashes with "$PH", as in "$PHsource". +# After the action subroutine has finished, checks for data +# consistency may be made. +## ??? OLD +# variables to the relevant data values. After the action subroutine +# has finished, the database is updated with the values of these named +# variables, with any necessary consistency checks. Thus the action +# subroutines can act on sensibly named variables without needed to +# know the database structure. +# +# The only routines that actually use the database structure and need +# to be changed if that is changed are: (a) the routines rdb_one_rule +# and rdb_one_file that implement the calling of the action subroutines, +# (b) routines for creation of single rules and file items, and (c) to +# a lesser extent, the routine for destroying a file item. +# +# Note that no routine is provided for destroying a rule. During a +# run, a rule, with its source files, may become inaccessible or +# unused. This happens dynamically, depending on the dependencies +# caused by changes in the source file or by error conditions that +# cause the computation of dependencies, particular of latex files, to +# become wrong. In that situation the files certainly come and go in +# the database, but subsidiary rules, with their content information +# on their source files, need to be retained so that their use can be +# reinstated later depending on dynamic changes in other files. +# +# However, there is a potential memory leak unless some pruning is +# done in what is written to the fdb file. (Probably only accessible +# rules and those for which source files exist. Other cases have no +# relevant information that needs to be preserved between runs.) + +# +# + + +#************************************************************ + +# First the top level routines for recursion and iteration + +#************************************************************ + +sub rdb_recurseA { + # Call: rdb_recurseA( rule | [ rules], + # \&rule_act1, \&file_act1, \&file_act2, + # \&rule_act2 ) + # The actions are pointers to subroutines, and may be null (0, or + # undefined) to indicate no action to be applied. + # Recursively acts on the given rules and all ancestors: + # foreach rule found: + # apply rule_act1 + # loop through its files: + # apply file_act1 + # act on its ancestor rule, if any + # apply file_act2 + # apply rule_act2 + # Guards against loops. + # Access to the rule and file data by local variables, only + # for getting and setting. + + # This routine sets a context for anything recursive, with @heads, + # %visited and $depth being set as local variables. + local @heads = (); + my $rules = shift; + + # Distinguish between single rule (a string) and a reference to an + # array of rules: + if ( ref $rules eq 'ARRAY' ) { @heads = @$rules; } + else { @heads = ( $rules ); } + + # Keep a list of visited rules, used to block loops in recursion: + local %visited = (); + local $depth = 0; + + foreach $rule ( @heads ) { rdb_recurse_rule( $rule, @_ ); } + +} #END rdb_recurseA + +#************************************************************ + +sub rdb_for_all { + # Call: rdb_for_all( \&rule_act1, \&file_act, \&rule_act2 ) + # Loops through all rules and their source files, using the + # specified set of actions, which are pointers to subroutines. + # Sorts rules alphabetically. + # See rdb_for_some for details. + rdb_for_some( [ sort keys %rule_db ], @_); +} #END rdb_for_all + +#************************************************************ + +sub rdb_for_some { + # Call: rdb_for_some( rule | [ rules], + # \&rule_act1, \&file_act, \&rule_act2) + # Actions can be zero, and rules at tail of argument list can be + # omitted. E.g. rdb_for_some( rule, 0, \&file_act ). + # Anonymous subroutines can be used, e.g., rdb_for_some( rule, sub{...} ). + # + # Loops through rules and their source files, using the + # specified set of rules: + # foreach rule: + # apply rule_act1 + # loop through its files: + # apply file_act + # apply rule_act2 + # + # Rule data and file data are made available in local variables + # for access by the subroutines. + + local @heads = (); + my $rules = shift; + # Distinguish between single rule (a string) and a reference to an + # array of rules: + if ( ref $rules eq 'ARRAY' ) { @heads = @$rules; } + else { @heads = ( $rules ); } + + foreach $rule ( @heads ) { + # $rule is implicitly local + &rdb_one_rule( $rule, @_ ); + } +} #END rdb_for_some + +#************************************************************ + +sub rdb_for_one_file { + my $rule = shift; + # Avoid name collisions with general recursion and iteraction routines: + local $file1 = shift; + local $action1 = shift; + rdb_for_some( $rule, sub{rdb_one_file($file1,$action1)} ); +} #END rdb_for_one_file + + +#************************************************************ + +# Routines for inner part of recursion and iterations + +#************************************************************ + +sub rdb_recurse_rule { + # Call: rdb_recurse_rule($rule, \&rule_act1, \&file_act1, \&file_act2, + # \&rule_act2 ) + # to do the work for one rule, recurisvely called from_rules for + # the sources of the rules. + # Assumes recursion context, i.e. that %visited, @heads, $depth. + # We are overriding actions: + my ($rule, $rule_act1, $new_file_act1, $new_file_act2, $rule_act2) + = @_; + # and must propagate the file actions: + local $file_act1 = $new_file_act1; + local $file_act2 = $new_file_act2; + # Prevent loops: + if ( (! $rule) || exists $visited{$rule} ) { return; } + $visited{$rule} = 1; + # Recursion depth + $depth++; + # We may need to repeat actions on dependent rules, without being + # blocked by the test on visited files. So save %visited: + local %visited_at_rule_start = %visited; + # At end, the last value set for %visited wins. + rdb_one_rule( $rule, $rule_act1, \&rdb_recurse_file, $rule_act2 ); + $depth--; + } #END rdb_recurse_rule + +#************************************************************ + +sub rdb_recurse_file { + # Call: rdb_recurse_file to do the work for one file. + # This has no arguments, since it is used as an action subroutine, + # passed as a reference in calls in higher-level subroutine. + # Assumes contexts set for: Recursion, rule, and file + &$file_act1 if $file_act1; + rdb_recurse_rule( $$Pfrom_rule, $rule_act1, $file_act1, $file_act2, + $rule_act2 ) + if $$Pfrom_rule; + &$file_act2 if $file_act2; +} #END rdb_recurse_file + +#************************************************************ + +sub rdb_do_files { + # Assumes rule context, including $PHsource. + # Applies an action to all the source files of the rule. + local $file_act = shift; + my @file_list = sort keys %$PHsource; + foreach my $file ( @file_list ){ + rdb_one_file( $file, $file_act ); + } +} #END rdb_do_files + +#************************************************************ + +# Routines for action on one rule and one file. These are the main +# places (in addition to creation and destruction routines for rules +# and files) where the database structure is accessed. + +#************************************************************ + +sub rdb_one_rule { + # Call: rdb_one_rule( $rule, $rule_act1, $file_act, $rule_act2 ) + # Sets context for rule and carries out the actions. +#===== Accesses rule part of database structure ======= + + local ( $rule, $rule_act1, $file_act, $rule_act2 ) = @_; +#?? &R1; + if ( (! $rule) || ! rdb_rule_exists($rule) ) { return; } + + local ( $PArule_data, $PHsource ) = @{$rule_db{$rule}}; + local ($Pcmd_type, $Pext_cmd, $PAint_cmd, $Ptest_kind, + $Psource, $Pdest, $Pbase, + $Pout_of_date, $Pout_of_date_user, $Prun_time, $Pchanged ) + = Parray( $PArule_data ); + # Correct array ref: + $PAint_cmd = $$PArule_data[2]; + + &$rule_act1 if $rule_act1; + &rdb_do_files( $file_act ) if $file_act; + &$rule_act2 if $rule_act2; + +#?? &R2; +} #END rdb_one_rule + +#************************************************************ + +sub rdb_one_file { + # Call: rdb_one_file($file, $file_act) + # Sets context for file and carries out the action. + # Assumes $rule context set. +#===== Accesses file part of database structure ======= + local ($file, $file_act) = @_; +#?? &F1; + if ( (!$file) ||(!exists ${$PHsource}{$file}) ) { return; } + local $PAfile_data = ${$PHsource}{$file}; + local ($Ptime, $Psize, $Pmd5, $Pfrom_rule, $Pcorrect_after_primary ) + = Parray( $PAfile_data ); + &$file_act if $file_act; + if ( ! rdb_rule_exists( $$Pfrom_rule ) ) { + $$Pfrom_rule = ''; + } +#?? &F2; +} #END rdb_one_file + +#************************************************************ + +# Routines for creation of rules and file items, and for removing file +# items. + +#************************************************************ + +sub rdb_create_rule { + # rdb_create_rule( rule, command_type, ext_cmd, int_cmd, test_kind, + # source, dest, base, + # needs_making, run_time ) + # int_cmd is either a string naming a perl subroutine or it is a + # reference to an array containing the subroutine name and its + # arguments. + # Makes rule. Error if it already exists. + # Omitted arguments: replaced by 0 or '' as needed. +# ==== Sets rule data ==== + my ( $rule, $cmd_type, $int_cmd, $PAext_cmd, $test_kind, + $source, $dest, $base, + $needs_making, $run_time ) = @_; + my $changed = 0; + # Set defaults, and normalize parameters: + foreach ( $cmd_type, $int_cmd, $PAext_cmd, $source, $dest, $base ) { + if (! defined $_) { $_ = ''; } + } + foreach ( $needs_making, $run_time, $test_kind ) { + if (! defined $_) { $_ = 0; } + } + if (!defined $test_kind) { + # Default to test on file change + $test_kind = 1; + } + if ( ref( $PAext_cmd ) eq '' ) { + # It is a single command. Convert to array reference: + $PAext_cmd = [ $PAext_cmd ]; + } + else { + # COPY the referenced array: + $PAext_cmd = [ @$PAext_cmd ]; + } + + $rule_db{$rule} = + [ [$cmd_type, $int_cmd, $PAext_cmd, $test_kind, + $source, $dest, $base, $needs_making, 0, $run_time, + $changed ], + {} + ]; + if ($source) { rdb_ensure_file( $rule, $source ); } +} #END rdb_create_rule + +#************************************************************ + +sub rdb_ensure_file { + # rdb_ensure_file( rule, file[, fromrule] ) + # Ensures the source file item exists in the given rule. + # Initialize to current file state if the item is created. + # Then if the fromrule is specified, set it for the file item. +#============ rule and file data set here ====================================== + my $rule = shift; + local ( $new_file, $new_from_rule ) = @_; + if ( ! rdb_rule_exists( $rule ) ) { + die_trace( "$My_name: BUG in rdb_ensure_file: non-existent rule '$rule'" ); + } + if ( ! defined $new_file ) { + die_trace( "$My_name: BUG in rdb_ensure_file: undefined file for '$rule'" ); + } + rdb_one_rule( $rule, + sub{ + if (! exists ${$PHsource}{$new_file} ) { + ${$PHsource}{$new_file} = [fdb_get($new_file), '', 0]; + } + } + ); + if (defined $new_from_rule ) { + rdb_for_one_file( $rule, $new_file, sub{ $$Pfrom_rule = $new_from_rule; }); + } +} #END rdb_ensure_file + +#************************************************************ + +sub rdb_remove_files { + # rdb_remove_file( rule, file,... ) + # Removes file(s) for the rule. + my $rule = shift; + if (!$rule) { return; } + local @files = @_; + rdb_one_rule( $rule, + sub{ foreach (@files) { delete ${$PHsource}{$_}; } } + ); +} #END rdb_remove_files + +#************************************************************ + +sub rdb_rule_exists { + # Call rdb_rule_exists($rule): Returns whether rule exists. + my $rule = shift; + if (! $rule ) { return 0; } + return exists $rule_db{$rule}; +} #END rdb_rule_exists + +#************************************************************ + +sub rdb_file_exists { + # Call rdb_file_exists($rule, $file): + # Returns whether source file item in rule exists. + local ( $rule, $file ) = @_; + local $exists = 0; + rdb_one_rule( $rule, + sub{ $exists = exists( ${$PHsource}{$file} ) ? 1:0; } + ); + return $exists; +} #END rdb_file_exists + +#************************************************************ + +sub rdb_update_gen_files { + # Call: fdb_updateA + # Assumes rule context. Update source files of rule to current state. + rdb_do_files( + sub{ + if ( exists $generated_exts_all{ ext($file) } ) {&rdb_update1;} + } + ); +} #END rdb_update_gen_files + +#************************************************************ + +sub rdb_update_filesA { + # Call: fdb_updateA + # Assumes rule context. Update source files of rule to current state. + rdb_do_files( \&rdb_update1 ); +} + +#************************************************************ + +sub rdb_update1 { + # Call: fdb_update1. + # Assumes file context. Updates file data to correspond to + # current file state on disk + ($$Ptime, $$Psize, $$Pmd5) = fdb_get($file); +} + +#************************************************************ + +sub rdb_set_file1 { + # Call: fdb_file1(rule, file, new_time, new_size, new_md5) + # Sets file time, size and md5. + my $rule = shift; + my $file = shift; + local @new_file_data = @_; + rdb_for_one_file( $rule, $file, sub{ ($$Ptime,$$Psize,$$Pmd5)=@new_file_data; } ); +} + +#************************************************************ + +sub rdb_dummy_file { + # Returns file data for non-existent file +# ==== Uses rule_db structure ==== + return (0, -1, 0, ''); +} + +#************************************************************ +#************************************************************ + +# Predefined subroutines for custom dependency + +sub cus_dep_delete_dest { + # This subroutine is used for situations like epstopdf.sty, when + # the destination (target) of the custom dependency invoking + # this subroutine will be made by the primary run provided the + # file (destination of the custom dependency, source of the + # primary run) doesn't exist. + # It is assumed that the resulting file will be read by the + # primary run. + + # Remove the destination file, to indicate it needs to be remade: + unlink $$Pdest; + # Arrange that the non-existent destination file is not treated as + # an error. The variable changed here is a bit misnamed. + $$Pchanged = 1; + # Ensure a primary run is done + &cus_dep_require_primary_run; + # Return success: + return 0; +} + +#************************************************************ + +sub cus_dep_require_primary_run { + # This subroutine is used for situations like epstopdf.sty, when + # the destination (target) of the custom dependency invoking + # this subroutine will be made by the primary run provided the + # file (destination of the custom dependency, source of the + # primary run) doesn't exist. + # It is assumed that the resulting file will be read by the + # primary run. + + local $cus_dep_target = $$Pdest; + # Loop over all rules and source files: + rdb_for_all( 0, + sub { if ($file eq $cus_dep_target) { + $$Pout_of_date = 1; + $$Pcorrect_after_primary = 1; + } + } + ); + # Return success: + return 0; +} + + +#************************************************************ +#************************************************************ +#************************************************************ +# +# UTILITIES: +# + +#************************************************************ +# Miscellaneous + +sub show_array { +# For use in diagnostics and debugging. +# On stderr, print line with $_[0] = label. +# Then print rest of @_, one item per line preceeded by some space + warn "$_[0]\n"; + shift; + foreach (@_){ warn " $_\n";} +} + +#************************************************************ + +sub Parray { + # Call: Parray( \@A ) + # Returns array of references to the elements of @A + my $PA = shift; + my @P = (undef) x (1+$#$PA); + foreach my $i (0..$#$PA) { $P[$i] = \$$PA[$i]; } + return @P; +} + +#************************************************************ + +sub glob_list { + # Glob a collection of filenames. Sort and eliminate duplicates + # Usage: e.g., @globbed = glob_list(string, ...); + my @globbed = (); + foreach (@_) { + push @globbed, glob; + } + return uniqs( @globbed ); +} + +#================================================== + +sub glob_list1 { + # Glob a collection of filenames. + # But no sorting or elimination of duplicates + # Usage: e.g., @globbed = glob_list1(string, ...); + # Since perl's glob appears to use space as separator, I'll do a special check + # for existence of non-globbed file (assumed to be tex like) + + my @globbed = (); + foreach my $file_spec (@_) { + # Problem, when the PATTERN contains spaces, the space(s) are + # treated as pattern separaters (in MSWin at least). + # MSWin: I can quote the pattern (is that MSWin native, or also + # cygwin?) + # Linux: Quotes in a pattern are treated as part of the filename! + # So quoting a pattern is definitively wrong. + # The following hack solves this partly, for the cases that there is no wildcarding + # and the specified file exists possibly space-containing, and that there is wildcarding, + # but spaces are prohibited. + if ( -e $file_spec || -e "$file_spec.tex" ) { + # Non-globbed file exists, return the file_spec. + # Return $file_spec only because this is not a file-finding subroutine, but + # only a globber + push @globbed, $file_spec; + } + else { + # This glob fails to work as desired, if the pattern contains spaces. + push @globbed, glob( "$file_spec" ); + } + } + return @globbed; +} + +#************************************************************ +# Miscellaneous + +sub prefix { + #Usage: prefix( string, prefix ); + #Return string with prefix inserted at the front of each line + my @line = split( /\n/, $_[0] ); + my $prefix = $_[1]; + for (my $i = 0; $i <= $#line; $i++ ) { + $line[$i] = $prefix.$line[$i]."\n"; + } + return join( "", @line ); +} + + +#************************************************************ +#************************************************************ +# File handling utilities: + + +#************************************************************ + +sub get_latest_mtime +# - arguments: each is a filename. +# - returns most recent modify time. +{ + my $return_mtime = 0; + foreach my $include (@_) + { + my $include_mtime = &get_mtime($include); + # The file $include may not exist. If so ignore it, otherwise + # we'll get an undefined variable warning. + if ( ($include_mtime) && ($include_mtime > $return_mtime) ) + { + $return_mtime = $include_mtime; + } + } + return $return_mtime; +} + +#************************************************************ + +sub get_mtime_raw +{ + my $mtime = (stat($_[0]))[9]; + return $mtime; +} + +#************************************************************ + +sub get_mtime { + return get_mtime0($_[0]); +} + +#************************************************************ + +sub get_mtime0 { + # Return time of file named in argument + # If file does not exist, return 0; + if ( -e $_[0] ) { + return get_mtime_raw($_[0]); + } + else { + return 0; + } +} + +#************************************************************ + +sub get_size { + # Return time of file named in argument + # If file does not exist, return 0; + if ( -e $_[0] ) { + return get_size_raw($_[0]); + } + else { + return 0; + } +} + +#************************************************************ + +sub get_size_raw +{ + my $size = (stat($_[0]))[7]; + return $size; +} + +#************************************************************ + +sub get_time_size { + # Return time and size of file named in argument + # If file does not exist, return (0,-1); + if ( -e $_[0] ) { + return get_time_size_raw($_[0]); + } + else { + return (0,-1); + } +} + +#************************************************************ + +sub get_time_size_raw +{ + my $mtime = (stat($_[0]))[9]; + my $size = (stat($_[0]))[7]; + return ($mtime, $size); +} + +#************************************************************ + +sub get_checksum_md5 { + my $source = shift; + my $input = new FileHandle; + my $md5 = Digest->MD5; + my $ignore_pattern = ''; + + if ( $source eq "" ) { + # STDIN: + open( $input, '-' ); + } + else { + open( $input, '<', $source ) + or return 0; + my ($base, $path, $ext) = fileparseA( $source ); + $ext =~ s/^\.//; + if ( exists $hash_calc_ignore_pattern{$ext} ) { + $ignore_pattern = $hash_calc_ignore_pattern{$ext}; + } + } + + if ( $ignore_pattern ) { + while (<$input>) { + if ( /$ignore_pattern/ ){ + $_= ''; + } + $md5->add($_); + } + } + else { + $md5->addfile($input); + } + close $input; + return $md5->hexdigest(); +} + +#************************************************************ + +#?? OBSOLETE +# Find file with default extension +# Usage: find_file_ext( name, default_ext, ref_to_array_search_path) +sub find_file_ext +#?? Need to use kpsewhich, if possible. Leave to find_file? +{ + my $full_filename = shift; + my $ext = shift; + my $ref_search_path = shift; + my $full_filename1 = &find_file($full_filename, $ref_search_path, '1'); +#print "Finding \"$full_filename\" with ext \"$ext\" ... "; + if (( $full_filename1 eq '' ) || ( ! -e $full_filename1 )) + { + my $full_filename2 = + &find_file("$full_filename.$ext",$ref_search_path,'1'); + if (( $full_filename2 ne '' ) && ( -e $full_filename2 )) + { + $full_filename = $full_filename2; + } + else + { + $full_filename = $full_filename1; + } + } + else + { + $full_filename = $full_filename1; + } +#print "Found \"$full_filename\".\n"; + return $full_filename; +} + +#************************************************************ +#?? OBSOLETE +# given filename and path, return full name of file, or die if none found. +# when force_include_mode=1, only warn if an include file was not +# found, and return 0 (PvdS). +# Usage: find_file(name, ref_to_array_search_path, warn_on_continue) +sub find_file +#?? Need to use kpsewhich, if possible +{ + my $name = $_[0]; + my $ref_path = $_[1]; + my $dir; + if ( $name =~ /^\// ) + { + #Aboslute pathname (by UNIX standards) + if ( (!-e $name) && ( $_[2] eq '' ) ) { + if ($force_include_mode) { + warn "$My_name: Could not find file [$name]\n"; + } + else { + die "$My_name: Could not find file [$name]\n"; + } + } + return $name; + } + # Relative pathname + foreach $dir ( @{$ref_path} ) + { +#warn "\"$dir\", \"$name\"\n"; + if (-e "$dir/$name") + { + return("$dir/$name"); + } + } + if ($force_include_mode) + { + if ( $_[2] eq '' ) + { + warn "$My_name: Could not find file [$name] in path [@{$ref_path}]\n"; + warn " assuming in current directory (./$name)\n"; + } + return("./$name"); + } + else + { + if ( $_[2] ne '' ) + { + return(''); + } +# warn "\"$name\", \"$ref_path\", \"$dir\"\n"; + die "$My_name: Could not find file [$name] in path [@{$ref_path}]\n"; + } +} + +#************************************************************ + +sub find_file1 { +#?? Need to use kpsewhich, if possible + + # Usage: find_file1(name, ref_to_array_search_path) + # Modified find_file, which doesn't die. + # Given filename and path, return array of: + # full name + # retcode + # On success: full_name = full name with path, retcode = 0 + # On failure: full_name = given name, retcode = 1 + + my $name = $_[0]; + # Make local copy of path, since we may rewrite it! + my @path = @{$_[1]}; + if ( $name =~ /^\// ) { + # Absolute path (if under UNIX) + # This needs fixing, in general + if (-e $name) { return( $name, 0 );} + else { return( $name, 1 );} + } + foreach my $dir ( @path ) { + #??print "-------------dir='$dir', "; + # Make $dir concatenatable, and empty for current dir: + if ( $dir eq '.' ) { + $dir = ''; + } + elsif ( $dir =~ /[\/\\:]$/ ) { + #OK if dir ends in / or \ or : + } + elsif ( $dir ne '' ) { + #Append directory separator only to non-empty dir + $dir = "$dir/"; + } + #?? print " newdir='$dir'\n"; + if (-e "$dir$name") { + return("$dir$name", 0); + } + } + my @kpse_result = kpsewhich( $name ); + if ($#kpse_result > -1) { + return( $kpse_result[0], 0); + } + return("$name" , 1); +} #END find_file1 + +#************************************************************ + +sub find_file_list1 { + # Modified version of find_file_list that doesn't die. + # Given output and input arrays of filenames, a file suffix, and a path, + # fill the output array with full filenames + # Return a status code: + # Retcode = 0 on success + # Retocde = 1 if at least one file was not found + # Usage: find_file_list1( ref_to_output_file_array, + # ref_to_input_file_array, + # suffix, + # ref_to_array_search_path + # ) + + my $ref_output = $_[0]; + my $ref_input = $_[1]; + my $suffix = $_[2]; + my $ref_search = $_[3]; + +#?? show_array( "=====find_file_list1. Suffix: '$suffix'\n Source:", @$ref_input ); +#?? show_array( " Bibinputs:", @$ref_search ); + + my @return_list = (); # Generate list in local array, since input + # and output arrays may be same + my $retcode = 0; + foreach my $file (@$ref_input) { + my ($tmp_file, $find_retcode) = &find_file1( "$file$suffix", $ref_search ); + if ($tmp_file) { + push @return_list, $tmp_file; + } + if ( $find_retcode != 0 ) { + $retcode = 1; + } + } + @$ref_output = @return_list; +#?? show_array( " Output", @$ref_output ); +#?? foreach (@$ref_output) { if ( /\/\// ) { print " ====== double slash in '$_'\n"; } } + return $retcode; +} #END find_file_list1 + +#************************************************************ + +sub kpsewhich { +# Usage: kpsewhich( filespec, ...) +# Returns array of files with paths as found by kpsewhich +# kpsewhich( 'try.sty', 'jcc.bib' ); +# Can also do, e.g., +# kpsewhich( '-format=bib', 'trial.bib', 'file with spaces'); + my $cmd = $kpsewhich; + my @args = @_; + foreach (@args) { + if ( ! /^-/ ) { + $_ = "\"$_\""; + } + } + foreach ($cmd) { + s/%[RBTDO]//g; + } + $cmd =~ s/%S/@args/g; + my @found = (); + local $fh; + open $fh, "$cmd|" + or die "Cannot open pipe for \"$cmd\"\n"; + while ( <$fh> ) { + s/^\s*//; + s/\s*$//; + push @found, $_; + } + close $fh; +# show_array( "Kpsewhich: '$cmd', '$file_list' ==>", @found ); + return @found; +} + +#################################################### + +sub add_cus_dep { + # Usage: add_cus_dep( from_ext, to_ext, flag, sub_name ) + # Add cus_dep after removing old versions + my ($from_ext, $to_ext, $must, $sub_name) = @_; + remove_cus_dep( $from_ext, $to_ext ); + push @cus_dep_list, "$from_ext $to_ext $must $sub_name"; +} + +#################################################### + +sub remove_cus_dep { + # Usage: remove_cus_dep( from_ext, to_ext ) + my ($from_ext, $to_ext) = @_; + my $i = 0; + while ($i <= $#cus_dep_list) { + if ( $cus_dep_list[$i] =~ /^$from_ext $to_ext / ) { + splice @cus_dep_list, $i, 1; + } + else { + $i++; + } + } +} + +#################################################### + +sub show_cus_dep { + show_array( "Custom dependency list:", @cus_dep_list ); +} + +#################################################### + +sub find_dirs1 { + # Same as find_dirs, but argument is single string with directories + # separated by $search_path_separator + find_dirs( &split_search_path( $search_path_separator, ".", $_[0] ) ); +} + + +#************************************************************ + +sub find_dirs { +# @_ is list of directories +# return: same list of directories, except that for each directory +# name ending in //, a list of all subdirectories (recursive) +# is added to the list. +# Non-existent directories and non-directories are removed from the list +# Trailing "/"s and "\"s are removed + local @result = (); + my $find_action + = sub + { ## Subroutine for use in File::find + ## Check to see if we have a directory + if (-d) { push @result, $File::Find::name; } + }; + foreach my $directory (@_) { + my $recurse = ( $directory =~ m[//$] ); + # Remove all trailing /s, since directory name with trailing / + # is not always allowed: + $directory =~ s[/+$][]; + # Similarly for MSWin reverse slash + $directory =~ s[\\+$][]; + if ( ! -e $directory ){ + next; + } + elsif ( $recurse ){ + # Recursively search directory + find( $find_action, $directory ); + } + else { + push @result, $directory; + } + } + return @result; +} + +#************************************************************ + +sub uniq +# Read arguments, delete neighboring items that are identical, +# return array of results +{ + my @sort = (); + my ($current, $prev); + my $first = 1; + while (@_) + { + $current = shift; + if ($first || ($current ne $prev) ) + { + push @sort, $current; + $prev = $current; + $first = 0; + } + } + return @sort; +} + +#================================================== + +sub uniq1 { + # Usage: uniq1( strings ) + # Returns array of strings with duplicates later in list than + # first occurence deleted. Otherwise preserves order. + + my @strings = (); + my %string_hash = (); + + foreach my $string (@_) { + if (!exists( $string_hash{$string} )) { + $string_hash{$string} = 1; + push @strings, $string; + } + } + return @strings; +} + +#************************************************************ + +sub uniqs { + # Usage: uniq2( strings ) + # Returns array of strings sorted and with duplicates deleted + return uniq( sort @_ ); +} + +#************************************************************ + +sub ext { + # Return extension of filename. Extension includes the period + my $file_name = $_[0]; + my ($base_name, $path, $ext) = fileparseA( $file_name ); + return $ext; + } + +#************************************************************ + +sub fileparseA { + # Like fileparse but replace $path for current dir ('./' or '.\') by '' + # Also default second argument to get normal extension. + my $given = $_[0]; + my $pattern = '\.[^\.]*'; + if ($#_ > 0 ) { $pattern = $_[1]; } + my ($base_name, $path, $ext) = fileparse( $given, $pattern ); + if ( ($path eq './') || ($path eq '.\\') ) { + $path = ''; + } + return ($base_name, $path, $ext); + } + +#************************************************************ + +sub fileparseB { + # Like fileparse but with default second argument for normal extension + my $given = $_[0]; + my $pattern = '\.[^\.]*'; + if ($#_ > 0 ) { $pattern = $_[1]; } + my ($base_name, $path, $ext) = fileparse( $given, $pattern ); + return ($base_name, $path, $ext); + } + +#************************************************************ + +sub split_search_path +{ +# Usage: &split_search_path( separator, default, string ) +# Splits string by separator and returns array of the elements +# Allow empty last component. +# Replace empty terms by the default. + my $separator = $_[0]; + my $default = $_[1]; + my $search_path = $_[2]; + my @list = split( /$separator/, $search_path); + if ( $search_path =~ /$separator$/ ) { + # If search path ends in a blank item, the split subroutine + # won't have picked it up. + # So add it to the list by hand: + push @list, ""; + } + # Replace each blank argument (default) by current directory: + for ($i = 0; $i <= $#list ; $i++ ) { + if ($list[$i] eq "") {$list[$i] = $default;} + } + return @list; +} + +################################# + + +sub tempfile1 { + # Makes a temporary file of a unique name. I could use file::temp, + # but it is not present in all versions of perl + # Filename is of form $tmpdir/$_[0]nnn$suffix, where nnn is an integer + my $tmp_file_count = 0; + my $prefix = $_[0]; + my $suffix = $_[1]; + while (1==1) { + # Find a new temporary file, and make it. + $tmp_file_count++; + my $tmp_file = "${tmpdir}/${prefix}${tmp_file_count}${suffix}"; + if ( ! -e $tmp_file ) { + open( TMP, ">$tmp_file" ) + or next; + close(TMP); + return $tmp_file; + } + } + die "$My_name.tempfile1: BUG TO ARRIVE HERE\n"; +} + +################################# + +#************************************************************ +#************************************************************ +# Process/subprocess routines + +sub Run_msg { + # Same as Run, but give message about my running + warn_running( "Running '$_[0]'" ); + Run($_[0]); +} + +sub Run { +# Usage: Run ("program arguments "); +# or Run ("start program arguments"); +# or Run ("NONE program arguments"); +# First form is just a call to system, and the routine returns after the +# program has finished executing. +# Second form (with 'start') runs the program detached, as appropriate for +# the operating system: It runs "program arguments &" on UNIX, and +# "start program arguments" on WIN95 and WINNT. If multiple start +# words are at the beginning of the command, the extra ones are removed. +# Third form (with 'NONE') does not run anything, but prints an error +# message. This is provided to allow program names defined in the +# configuration to flag themselves as unimplemented. +# Return value is a list (pid, exitcode): +# If process is spawned sucessfully, and I know the PID, +# return (pid, 0), +# else if process is spawned sucessfully, but I do not know the PID, +# return (0, 0), +# else if process is run, +# return (0, exitcode of process) +# else (I fail to run the requested process) +# return (0, suitable return code) +# where return code is 1 if cmdline is null or begins with "NONE" (for +# an unimplemented command) +# or the return value of the system subroutine. + + +# Split command line into one word per element, separating words by +# one (OR MORE) spaces: +# The purpose of this is to identify latexmk-defined pseudocommands +# 'start' and 'NONE'. +# After dealing with them, the command line is reassembled + my $cmd_line = $_[0]; + if ( $cmd_line eq '' ) { + traceback( "$My_name: Bug OR configuration error\n". + " In run of'$rule', attempt to run a null program" ); + return (0, 1); + } + if ( $cmd_line =~ /^start +/ ) { + #warn "Before: '$cmd_line'\n"; + # Run detached. How to do this depends on the OS + # But first remove extra starts (which may have been inserted + # to force a command to be run detached, when the command + # already contained a "start"). + while ( $cmd_line =~ s/^start +// ) {} + #warn "After: '$cmd_line'\n"; + return &Run_Detached( $cmd_line ); + } + elsif ( $cmd_line =~ /^NONE/ ) { + warn "$My_name: ", + "Program not implemented for this version. Command line:\n"; + warn " '$cmd_line'\n"; + return (0, 1); + } + else { + # The command is given to system as a single argument, to force shell + # metacharacters to be interpreted: + return( 0, system( $cmd_line ) ); + } +} + +#************************************************************ + +sub Run_Detached { +# Usage: Run_Detached ("program arguments "); +# Runs program detached. Returns 0 on success, 1 on failure. +# Under UNIX use a trick to avoid the program being killed when the +# parent process, i.e., me, gets a ctrl/C, which is undesirable for pvc +# mode. (The simplest method, system ("program arguments &"), makes the +# child process respond to the ctrl/C.) +# Return value is a list (pid, exitcode): +# If process is spawned sucessfully, and I know the PID, +# return (pid, 0), +# else if process is spawned sucessfully, but I do not know the PID, +# return (0, 0), +# else if I fail to spawn a process +# return (0, 1) + + my $cmd_line = $_[0]; + +## warn "Running '$cmd_line' detached...\n"; + if ( $cmd_line =~ /^NONE / ) { + warn "$My_name: ", + "Program not implemented for this version. Command line:\n"; + warn " '$cmd_line'\n"; + return (0, 1); + } + + if ( "$^O" eq "MSWin32" ){ + # Win95, WinNT, etc: Use MS's start command: + return( 0, system( "start $cmd_line" ) ); + } else { + # Assume anything else is UNIX or clone + # For this purpose cygwin behaves like UNIX. + ## warn "Run_Detached.UNIX: A\n"; + my $pid = fork(); + ## warn "Run_Detached.UNIX: B pid=$pid\n"; + if ( ! defined $pid ) { + ## warn "Run_Detached.UNIX: C\n"; + warn "$My_name: Could not fork to run the following command:\n"; + warn " '$cmd_line'\n"; + return (0, 1); + } + elsif( $pid == 0 ){ + ## warn "Run_Detached.UNIX: D\n"; + # Forked child process arrives here + # Insulate child process from interruption by ctrl/C to kill parent: + # setpgrp(0,0); + # Perhaps this works if setpgrp doesn't exist + # (and therefore gives fatal error): + eval{ setpgrp(0,0);}; + exec( $cmd_line ); + # Exec never returns; it replaces current process by new process + die "$My_name forked process: could not run the command\n", + " '$cmd_line'\n"; + } + ##warn "Run_Detached.UNIX: E\n"; + # Original process arrives here + return ($pid, 0); + } + # NEVER GET HERE. + ##warn "Run_Detached.UNIX: F\n"; +} + +#************************************************************ + +sub find_process_id { +# find_process_id(string) finds id of process containing string and +# being run by the present user. Typically the string will be the +# name of the process or part of its command line. +# On success, this subroutine returns the process ID. +# On failure, it returns 0. +# This subroutine only works on UNIX systems at the moment. + + if ( $pid_position < 0 ) { + # I cannot do a ps on this system + return (0); + } + + my $looking_for = $_[0]; + my @ps_output = `$pscmd`; + +# There may be multiple processes. Find only latest, +# almost surely the one with the highest process number +# This will deal with cases like xdvi where a script is used to +# run the viewer and both the script and the actual viewer binary +# have running processes. + my @found = (); + + shift(@ps_output); # Discard the header line from ps + foreach (@ps_output) { + next unless ( /$looking_for/ ) ; + my @ps_line = split (' '); +# OLD return($ps_line[$pid_position]); + push @found, $ps_line[$pid_position]; + } + + if ($#found < 0) { + # No luck in finding the specified process. + return(0); + } + @found = reverse sort @found; + if ($diagnostics) { + print "Found the following processes concerning '$looking_for'\n", + " @found\n", + " I will use $found[0]\n"; + } + return $found[0]; +} + +#************************************************************ +#************************************************************ +#************************************************************ + +# Directory stack routines + +sub pushd { + push @dir_stack, cwd(); + if ( $#_ > -1) { chdir $_[0]; } +} + +#************************************************************ + +sub popd { + if ($#dir_stack > -1 ) { chdir pop @dir_stack; } +} + +#************************************************************ + +sub ifcd_popd { + if ( $do_cd ) { + warn "$My_name: Undoing directory change\n"; + &popd; + } +} + +#************************************************************ + +sub finish_dir_stack { + while ($#dir_stack > -1 ) { &popd; } +} + +#************************************************************ +#************************************************************ +#************************************************************ +#************************************************************ +#************************************************************ +#************************************************************ +#************************************************************ +#************************************************************ |