📄 tex2pdf
字号:
#!/usr/bin/perl -w# tex2pdf - script for translating latex docs to pdf## Copyright (C) 2000-2002 by Steffen Evers and others## This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation.## 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., 675 Mass Ave, Cambridge, MA 02139, USA.## The GNU General Public License is also available online:# http://www.gnu.org/licenses/gpl.html## Thanks a lot to all the people that have already contributed to this project!## The changelog including the credits has become too long. So, I have removed it# from the script, but it is still available online (see below). ## Special thanks to the following people for their contribution# (see the changelog for details):# Matej Cepl, Herbert Voss, Nicolas Marsgui, Bruce Foster, Mark van Rossum,# Matt Bandy, Garrick Chien Welsh, Stacy J. Prowell, Pavel Sedivy,# Holger Daszler, Olaf Gabler, Ahmet Sekercioglui, Richard, Steffen Macke,# Rainer Dorsch & friends, Jean-Pierre Chretien, Fernando Perez,# Ha Duong Minh, Oscar Lopez## Project Homepage: http://tex2pdf.berlios.de# Developer Homepage: http://developer.berlios.de/projects/tex2pdf# Mailing lists: http://developer.berlios.de/mail/?group_id=57# Changelog: http://tex2pdf.berlios.de/changelog.html## Anyone is invited to help to improve tex2pdf. Therefore any kind of feedback# is welcome. Maybe you even would like to hack the code and send us your# changes. This would help a lot and is highly appreciated. Think about it :-)# Subscribing to the developer mailing list might be a first step (see above).## Send feedback to: tex2pdf-devel@lists.berlios.de######### Importsuse File::Basename;use File::Copy;use Getopt::Long;use Sys::Hostname;use Cwd;use strict;####### global variablesmy $MYRELEASE="3.0.21";my $MYHOSTNAME=hostname;my $MYNAME=basename $0;my $MYUSER=$ENV{'USER'};my $USER_HOME=$ENV{'HOME'};if (not $MYUSER) { $MYUSER = 'nobody'; }if (not $USER_HOME) { $USER_HOME = '/tmp'; }my @TMPFILES=();my @TMP_TEX_FILES=(); my $NUM_PARAM_MIN=0;my $NUM_PARAM_MAX=9; my @REF_DOCS;my $MTP_PREAMBLE_FILENAME="preamble.cfg";my $MTP_TMP_BASESUFFIX="-mp";my @EPS_SUFFIXES=('eps','ps','ps.gz','eps.gz' );my $PDF_ORIG_SUFFIX='pdf.orig';my @BITMAP_SUFFIXES=( 'jpg', 'png', 'tif' );# (initial) log file of this script# this log file will be moved to the specified log_dir after configuration# and the variable will be updated to the new namemy $MYLOGFILE="$USER_HOME/tex2pdf-$$.log"; my $LOGFILE_VERBOSITY=9;### text token for no valuemy $NIL="NOVALUE";my $UNDEF="undefined";### token for boolean 'false', 'no' my $NO="no";my $FALSE=0;### token for boolean 'true', 'yes' my $YES="yes";my $TRUE=1;### file to store private parameters# If you only want to change your private parameters change them there# default: $HOME/.tex2pdf3rcmy $RC_FILENAME="$USER_HOME/.tex2pdf3rc";my $MYRCFILE_VERSION=7;my $RCVERSION_STRING="rcfile_version";## set global variable configured to prevent access to configuration# parameters before configuration process is finishedmy $CONFIGURED=$FALSE;my $PRE_CONFIG_VERBOSITY=4;########################## NEW PERL CONFIGURATONmy %CONFIGURATION = ();my %PARAMETER_LIST = ();my @PARAMETER_ORDER = ();my %PARAMETER_TYPES = (); ## Array index for the various information in each parameter specifcation## referenced by %PARAMETER_LISTmy $TYPE=0;my $OPT_ALIAS=1;my $OPT_SPEC=2;my $DEF_VALUE=3;my $DESCRIPTION=4;my $QUESTION=5;my $EXPLANATION=6;&add_param_type('paper', [ ['a4paper' , 'a4 paper' ], [ 'letterpaper', 'letter paper' ], [ 'legalpaper', 'legal paper' ], [ 'executivepaper', 'executive paper' ], [ $NIL, 'do not set value - leave it to hyperref' ] ] ); &add_param_type('color', [ [ 'yellow', 'LaTeX color yellow' ], [ 'red', 'LaTeX color red' ], [ 'green', 'LaTeX color green' ], [ 'cyan', 'LaTeX color cyan' ], [ 'blue', 'LaTeX color blue' ], [ 'magenta', 'LaTeX color magenta' ], [ 'black', 'LaTeX color black' ], [ $NIL , 'do not set this value - leave it to hyperref' ] ] );&add_param_type('destination', [ [ 'source', 'directory of the LaTeX source document' ] , [ 'input', 'root directory of referenced material' ], [ 'custom', 'custom directory as specified' ] ] );### Option parameters: these parameters have no default value and can not# be configured interactively, but only as a command line option# an option parameter is not allowed to have a default value, question or# explanation# and all parameter of type action are treated as option parameters# $key, $type, $def_value, $opt_alias, $opt_spec, $description, $question, $explanation&add_param('help', 'action', undef, '|h', '', 'print a short help text and exit');&add_param('version', 'action', undef, '|v', '', 'print the version of this script and exit');&add_param('print_config', 'action', undef, '|o', '', 'print the current configuration and exit');&add_param('configure', 'action', undef, '|c', '', 'configure all parameters interactivly, store them and exit');&add_param('title', 'text', undef, '|t', '=s', 'set PDF info title for specified document');&add_param('author', 'text', undef, '|a', '=s', 'set PDF info author for specified document');&add_param('input_path', 'directory', undef, '', '=s', 'set path for referenced material in main document');### Full parameters# parameter type action is not allowed# $key, $type, $def_value, $opt_alias, $opt_spec, $description, $question, $explanation&add_param('logdir', 'directory',"$USER_HOME/tex2pdf-log/", '', '=s', 'set directory for saving log files', 'What log directory should be used?', "The log directory is used to store information about the generation\n" ."process for later review, e.g. for debugging.");&add_param('lyxrc_path', 'directory', "$USER_HOME/.lyx/", '', '=s', 'set the configuration directory of LyX', 'What is the directory for your LyX configuration data?', "If I have to generate a LateX file from a LyX file I need to clear two " ."temporary\nfiles in your LyX configuration directory. They will " ."be backuped and normally\ndo not contain any valuable data anyway. If " ."you do not use LyX, simply leave\nthe default.");&add_param('lyx_exec', 'text', "lyx", '', '=s', 'specify the LyX executable for converting lyx to latex', 'Which executable should I use for converting LyX docs to LaTeX?', "I use LyX to generate a LateX file from a LyX file. As you might use\n" ."several versions of LyX at the same time or do not have it in your path" ."\nyou can give me the apropriate executable here (e.g. '/usr/bin/lyx')." ."\nIn most cases the default 'lyx' should be fine.");&add_param('debug', 'bool', $NO, '', '!','do not delete temporary files after execution and be as verbose as possible', 'Do you want to debug this script?', "I will not remove any temporary files. This could cause problems on a " ."second\nexecution as I might refuse to overwrite these files for security " ."reasons.\nYou have to remove them manually in this case. Additionally, I " ."will provide\nas much information during execution as possible.");&add_param('delete_pdf_images', 'bool', $NO, '', '!', 'delete generated PDF image files after execution', 'Should generated PDF image files be deleted after execution?', "Pdflatex cannot handle EPS images. Therefore all such images need to be\n" ."translated to PDF in advance. After a successful generation of the final " ."PDF \ndocument or after encountering an error I could leave this PDF " ."images for\n later executions or simply delete them.");&add_param('clean_on_abort', 'bool', $YES, '', '!', 'also delete temporary files after abort', 'Should temporary files be deleted when aborting?', "When the generation of the PDF file fails for some reason you might still " ."want\nto keep already generated temporary files for some reason, e.g. " ."debugging.\nIf you do not want to keep them set this parameter to 'yes'.");&add_param('tmp_base_suffix', 'text', '-pdf', '', '=s', 'specify the extension of the basename for temporary TeX files', 'What string should be used as basename suffix for temporary files?', "I have to find names for my temporary files. Therefore I construct a new " ."name\nfrom the original filename and this string. Me and various called " ."applications\nwill then create several files with this constructed " ."basename and different\nextensions. When cleaning up I will simple " ."delete all files with the\nconstructed basenames I have used.");&add_param('overwrite', 'bool', $NO, '', '!', 'ignore existence of files with same basename as temporary TeX files', 'Should I overwrite existing (temporary) files?', "In spite of the precaution with the appended base suffix, there still " ."might\nexist files with an identical basename. If you set this option I " ."will consider\nsuch files as old temporary files and overwrite them " ."during generation.\nHowever, I will not remove any files with this " ."constructed basename on the\nclean up. You have to remove them manually.");&add_param('clean_logs', 'bool', $YES, '|l', '!', 'delete all log files in log directory before execution', 'Should the old log files be removed before execution?', "I can remove old log files prior to execution. However, you might " ."experience\nproblems if you run the script on several documents at the " ."same time. If you\nwant to be on the safe side, answer '$NO'. Than you " ."have to remove the logs\nmanually from time to time.");&add_param('check_commands', 'bool', $YES, '', '!', 'make sure that required shell commands does exist before start', 'Should I look for required executables?', "As I use several different applications for PDF generation you might want " ."to \nmake sure that they are available before the real work starts.");&add_param('destination', 'destination', 'source', '', '=s', 'specifiy final location of generated PDF document', 'Where should I store the resulting PDF document?', "Depending on the application that starts this script (or you if you call " ."it\ndirectly) you might want to have the resulting PDF document located " ."at\ndifferent places.");&add_param('custom_path', 'directory', $USER_HOME.'/', '|d', '=s', "specify custom path for 'destination' parameter", 'What custom directory should be used?', "When ever you specifiy to store the generated PDF document (command line " ."or\nconfiguration) in a custom directory I will put it here.");&add_param('colorlinks', 'three', $YES, '', '!', 'activate colored links in PDF doc (hyperref)', 'Should colors be used for links?', "I can use different colors for links inside the PDF document.\nYou can " ."use '$UNDEF' to tell me that you would like to leave this up to\n" ."independent hyperref configuration.");&add_param('paper', 'paper', 'a4paper', '|p', '=s', 'specify papersize of the PDF doc (hyperref)', 'What papersize should be used?', "I can set the papersize of the resulting PDF document");&add_param('citecolor', 'color', 'blue', '', '=s', 'specify color of citations in PDF doc (hyperref)', 'What color should be used for citation?', "");&add_param('urlcolor', 'color', 'blue', '', '=s', 'specify color of URLs in PDF doc (hyperref)', 'What color should be used for URLs?', "");&add_param('linkcolor', 'color', 'blue', '', '=s', 'specify color of internal links in PDF doc (hyperref)', 'What color should be used for normal internal links?', "");&add_param('pagecolor', 'color', 'blue', '', '=s', 'specify color of links to other pages in PDF doc (hyperref)', 'What color should be used for page links?', "");&add_param('link_toc_page', 'bool', $YES, '', '!', 'link table of contents to pages instead of sections (hyperref)', 'Should TOC be linked to pages?', "The table of contents of the resulting PDF document is normally linked to " ."the\ncorresponding section. However, you can also link it to the " ."corresponding page\ninstead.");&add_param('default_title', 'text', $NIL, '', '=s', 'set default PDF info title', 'What is the default title?', "A PDF document contains meta data about itself: the document info.\nOne " ."of the info fields is the document title. You can set a default value\n" ."which will be used in the case the script cannot determine a proper " ."title from\nthe LaTeX document and you have not set one on the command " ."line.\nYou can use '$NIL' to tell me that you would like to leave this " ."up to\nindependent hyperref configuration.");&add_param('default_author', 'text', $NIL, '', '=s', 'set default PDF info author', 'What is the default author?', "A PDF document contains meta data about itself: the document info.\nOne " ."of the info fields is the document author. You can set a default value\n" ."which will be used in the case the script cannot determine a proper " ."author\nfrom the LaTeX document and you have not set one on the command " ."line.\nYou can use '$NIL' to tell me that you would like to leave this " ."up to\nindependent hyperref configuration.");&add_param('force_index', 'bool', $NO, '|i', '!', 'force explicit inclusion of (existing) index in PDF doc', 'Should the call of makeindex be forced?', "Older versions of pdflatex have not included the index of a document\n" ."automatically. If you are missing the index in your document you can " ."force the\ncall of makeindex on the condition that an index file was " ."generated.");&add_param('makeindex_opts', 'text', '', '', '=s', 'specify extra options for shell execution of makeindex', 'What additional options for makeindex should be used?', "Sometimes, people would like to pass some extra options over to makeindex. " ."This\nis the right place to do that. Everyone else can leave this empty.");&add_param('bibtex', 'three', $NIL, '|b', '!', 'set bibtex behavior', 'How should bibtex be used?', "The bibtex usage can be specified.\nPossible values are: '$YES' (always " ."run bibtex), '$NO' (never run bibtex)\nand '$UNDEF' (scan tex file for " ."a bibtex entry and run it if required).");&add_param('gloss', 'three', $NIL, '', '!', 'set gloss behavior', 'How should gloss be used?', "The gloss usage can be specified.\nPossible values are: '$YES' (always " ."run bibtex on file.gls), '$NO' (never run bibtex on file.gls)\nand '$UNDEF' (scan tex file for " ."a gloss entry and run it if required).");&add_param('thumbpdf', 'bool', $NO, '|n', '!', 'generate thumbnails for PDF document', 'Should PNG thumbnails be created?', "I can use thumbpdf to include thumbnails of the document pages in the PDF " ."file.\nThis requires Ghostscript 5.50 or higher.");&add_param('ppower', 'bool', $NO, '|w', '!', 'postprocess PDF document with ppower', 'Should ppower postprocess the PDF document?', "I can use ppower to postprocess the PDF " ."file.\nThis requires ppower 4.0 or higher.");&add_param('authorindex', 'bool', $NO, '', '!', 'generate author index for PDF document', 'Should authorindex process the PDF document?', "I can use authorindex to process to include an author index in the PDF " ."file.\nThis requires authorindex.");&add_param('mtp_preamble', 'bool', $NO, '|r', '!', "add the file $MTP_PREAMBLE_FILENAME at the current dir to metapost files", "Should the $MTP_PREAMBLE_FILENAME file be added to the metapost files?", "I can add $MTP_PREAMBLE_FILENAME to metapost " ."files.\nThis requires an existing $MTP_PREAMBLE_FILENAME file.");&add_param('maxrun', 'integer', 6, '', '=i', 'specify maximal number of pdflatex runs if problems are detected', 'What should be the maximum number of runs for pdflatex (1-6)?', "");&add_param('minrun', 'integer', 2, '', '=i', 'specify minimal number of pdflatex runs if no problems are detected', 'What should be the minimum number of runs for pdflatex (1-6)?', "");&add_param('verbosity', 'integer', 5, '', '=i', 'set the level of verbosity', 'Which level of verbosity do you want (0-9)', "Different people want different amounts of information about what the " ."script\nactually does. Therefore you can adjust the verbosity to your " ."personal needs\nby setting this parameter to a value from 0 to 9. 0 " ."means no output at all\nand 9 means maximal output.");&add_param('pdftex_opts', 'text', '', '', '=s', 'specify extra options for shell execution of pdflatex', 'What additional options for pdflatex should be used?', "Sometimes, people would like to pass some extra options over to pdflatex. " ."This\nis the right place to do that. Everyone else can leave this empty.");&add_param('hyperref_args', 'text', '', '', '=s', 'specify extra arguments for the hyperref package', 'What additional arguments should be passed to the hyperref package?', "Sometimes, people would like to pass some extra options over to hyperref. " ."This\nis the right place to do that. Everyone else can leave this empty.");# the following parameter types should be set now:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -