📄 tex2pdf
字号:
print "Parameter: ".$key."\n"; print $description."\n\n"; print $explanation."\n\n" if($explanation ne ""); ### ask him what he wants if ($type eq 'bool') { $new_value=&question_ynu($question, $current_value, $NO); } elsif ($type eq 'three') { $new_value=&question_ynu($question, $current_value, $YES); } elsif ($type eq 'directory') { $new_value=&input_dir($question, $current_value, $YES); } elsif ($type eq 'text') { $new_value=&input_text($question, $current_value); } elsif ($type eq 'integer') { $new_value=&input_number($question, $current_value, $NUM_PARAM_MIN, $NUM_PARAM_MAX); } else { my $enum_array_ref; $enum_array_ref=&type_enum_array($type); if (! defined($enum_array_ref)) { &abort("Do not know how to configure this parameter: $key (type: $type)"); } $new_value=&choose_value($question,$current_value,$enum_array_ref); } ### store his choice &set_param_value($key, $new_value);}### save configuration in rc file# parameter 1: file name# return value: nonesub write_configuration { my $file_name = $_[0]; my $date; open(RCFILE, ">$file_name") or &abort("Could not open configuration file for writing ($file_name)"); select RCFILE; $date = `date`; chomp($date); print "# Configuration file for $MYNAME V$MYRELEASE\n"; print "# Generated $date by $MYUSER on $MYHOSTNAME\n"; print "$RCVERSION_STRING=$MYRCFILE_VERSION\n"; foreach my $key (@PARAMETER_ORDER) { my $value = $CONFIGURATION{$key}; if(&full_param($key)) { print $key.'='.$value."\n"; } } print "# EOF\n"; select STDOUT; close RCFILE;}### print the configuration parameterssub print_configuration { print "\nConfiguration for $MYNAME V$MYRELEASE\n"; foreach my $key (@PARAMETER_ORDER) { my $value = $CONFIGURATION{$key}; if(&full_param($key)) { print $key.'='.$value."\n"; } } print "\n";}### load parameters from rc file# parameter 1: file name# return value: version of read rc file or 0 if no version givensub read_configuration { my $file_name = $_[0]; my $file_version= 0; &check_file($file_name, "Could not access configuration file"); open(RCFILE, "<$file_name") or &abort("Could not open configuration file for reading ($file_name)"); while (<RCFILE>) { chomp; if( /^([^#=]+)=(.*)$/ ) { if( exists $CONFIGURATION{$1} ) { $CONFIGURATION{$1} = $2; } elsif ( $1 eq $RCVERSION_STRING ) { $file_version = $2; } else { print "Ignoring unknown parameter in RC file: $1=$2\n"; } } } close RCFILE; return $file_version;}### print script versionsub print_version { print "\n$MYNAME Version $MYRELEASE\n";}###################### Specific functions (for use with this script only)### print usage of commandsub print_usage { print "\nUsage: $MYNAME [OPTIONS] DOCUMENT.lyx\n"; print " $MYNAME [OPTIONS] DOCUMENT[.tex]\n\n"; print " $MYNAME -c | --configure modify/set up configuration\n"; print " $MYNAME -h | --help give a short help\n"; print " $MYNAME -o | --print_config print current configuration\n"; print " $MYNAME -v | --version print my version\n\n";}### print command helpsub print_help { &print_version; &print_usage; foreach my $key (@PARAMETER_ORDER) { my @param_def = @{$PARAMETER_LIST{$key}}; my $description = $param_def[$DESCRIPTION]; my $takes_value = $param_def[$OPT_SPEC] =~ /[=:]/ ? $TRUE : $FALSE; my $negation = $param_def[$OPT_SPEC] eq '!' ? $TRUE : $FALSE; my $alias = $param_def[$OPT_ALIAS]; $alias =~ s/\|(([a-zA-Z])(\||$))/ | -$1/g; $alias =~ s/\|(([a-zA-Z][a-zA-Z0-9_]+)(\||$))/ | --$1/g; print "--"; print "[no]" if($negation); print $key.$alias; print " VALUE" if ($takes_value); print ":\n ".$description."\n\n"; } print "\n";}### configure all tex2pdf parameters interactively# parameters: none# return value: nonesub configure { print "\n--------------------------------------------------------\n"; print "\n***** Configuration for $MYNAME *****\n\n"; print "The following answers are considered as defaults in later "; print "executions\n"; print "of $MYNAME. You can change these values by using the option "; print "--configure \nagain."; print "Additionally, all command-line options override these settings.\n"; print "Many parameters can be set to '$NIL' or '$UNDEF'. This means that NO"; print "\nvalue at all (not even an empty value) is passed over to the "; print "called\napplication (e.g. latex package hyperref).\n"; $NUM_PARAM_MIN=1; $NUM_PARAM_MAX=9; foreach my $key (@PARAMETER_ORDER) { if(&full_param($key)) { &config_param($key); } } print "\nConfiguration for $MYNAME finished.\n\n";}### check if the most important executables are installed on the system# parameters: nonesub check_commands { my $exec_epstopdf; ### check for which command &checkCommand("which","You can switch off all command checks to fix this."); ### pdftex executables # Homepage: http://tug.org/applications/pdftex &checkCommand("pdflatex","See pdftex homepage for details: http://tug.org/applications/pdftex"); &checkCommand("epstopdf","See pdftex homepage for details: http://tug.org/applications/pdftex"); $exec_epstopdf = `which epstopdf`; chomp $exec_epstopdf; my $compat = "-dCompatibilityLevel=1\\.1"; if (defined($ENV{'GS_OPTIONS'}) && $ENV{'GS_OPTIONS'} =~ /$compat/o) { &report(9, "Good: ghostscript option '-dCompatibilityLevel=1.1' detected " ."in\n'\$GS_OPTIONS'."); } elsif (&grep_file($exec_epstopdf, $compat, $TRUE) > 0) { &report(9, "Good: ghostscript option '-dCompatibilityLevel=1.1' detected " ."in\n'$exec_epstopdf'."); } else { &report(4, "\nWARNING: no ghostscript option '-dCompatibilityLevel=1.1' " ."in\n'$exec_epstopdf'.\n" ."You might run into trouble with the conversions of bitmaps.\n" ."Adjusting epstopdf or setting the environment variable GS_OPTIONS " ."to \n".'"$GS_OPTIONS -dCompatibilityLevel=1.1" before calling this ' ."script\nmight help in this case.\n"); } if ( ¶m_value('thumbpdf') eq $YES ) { &checkCommand("thumbpdf","You can switch off thumbpdf support to fix this."); } if ( ¶m_value('ppower') eq $YES ) { &checkCommand("ppower","You can switch off ppower support to fix this."); } ### authorindex perl script if ( ¶m_value('authorindex') eq $YES ) { &checkCommand("authorindex","You can switch off authorindex support to fix this."); } ### bibtex executable if ( ¶m_value('bibtex') ne $NO or ¶m_value('gloss') ne $NO) { &checkCommand("bibtex","You can switch off BibTeX support to fix this."); }}#### generate the tmp file name from the original tex filename#### and make sure that they are not the same# parameter 1: orignal filename (with or without a path or .tex)# parameter 2: path for the tmp file (default: doc path)# return value: tmp namesub reserve_tmp_texname { my $original_name = $_[0]; my $tmp_path = $_[1]; my $tmp_base_suffix = ¶m_value('tmp_base_suffix'); my $overwrite = ¶m_value('overwrite'); my $original_path; my $original_base; my $suffix; my $pathed_tmp_base; my @existing_files; # separate path, base and suffix ($original_base,$original_path,$suffix) = fileparse($original_name, '\.tex'); # set the path of the tmp file if(!$tmp_path) { $tmp_path=$original_path; } else { $tmp_path .= '/' if( $tmp_path ne "" and ! ($tmp_path =~ m#/$#) ); } # abort if no absolute path is given if( index($tmp_path, "/") != 0 ) { &abort("Internal error: Illegal argument for reserve_tmp_texname:". "Given file has no absolute path: $original_name"); } # make sure that tmp_base_suffix is set correctly if($tmp_base_suffix eq "") { &abort("Temporary filename base suffix is empty."); } $pathed_tmp_base = $tmp_path.$original_base.$tmp_base_suffix; # make sure no file with this base exists in this directory @existing_files = glob "$pathed_tmp_base.*"; if (@existing_files != 0) { &report(3, "Problems detected while reserving temporay file name!\n", "In this directory are already files with this basename.\n", "A list of the conflicting, existing files:\n", join("\n", @existing_files), "\n"); if ($overwrite eq $YES) { &report(4, "As you have activated the parameter 'overwrite' I will " ."continue.\n", "However, in order to protect the existing files I will not\n", "delete any files with this basename at the final clean-up."); } else { &report(2, "You could activate the parameter 'overwrite' or remove ", "the\n corresponding files in order to avoid these problems."); &abort("No temporary name found for $original_name."); } } else { push(@TMP_TEX_FILES, $pathed_tmp_base); } return $pathed_tmp_base.$suffix;}### generate LaTeX file from LyX document with LyX itself# parameter ($1): Lyx document# parameter ($2): Latex documentsub generate_tex_file { my $lyx_doc = $_[0]; my $tex_doc = $_[1]; my $lyx_dir; my $lyx_output; my $lyx_exec=¶m_value('lyx_exec'); $lyx_dir = ¶m_value('lyxrc_path'); $lyx_dir .= '/' if( ! ($lyx_dir =~ m#/$#) ); $lyx_dir .= '/' if( ! ($lyx_dir =~ m#/$#) ); ### Check if LyX file can be accessed &check_file($lyx_doc,"Cannot read the specified LyX document!"); ### Check if LaTeX file exists and is newer than the LyX file if ( -f $tex_doc and -M $tex_doc < -M $lyx_doc ) { &report(4, "\nLaTeX file is newer than LyX document ($lyx_doc).\n", "Using existing TeX file: $tex_doc\n", "Remove it to force its new generation."); } else { ### export LaTeX file with LyX (needs a display!) &checkCommand($lyx_exec, "Cannot generate LaTeX document without LyX!"); &report(6, "\nExporting LaTeX file"); ### move some files out of the way that stop LyX from exporting foreach my $file ($lyx_dir."lyxpipe.out",$lyx_dir."lyxpipe.in",$tex_doc) { if ( -f $file ) { rename($file, $file.'~'); } } $lyx_output = `$lyx_exec --export latex $lyx_doc 2>&1`; ### check if LaTeX file now really exists if ( ! -f $tex_doc ) { &report(2, "Lyx Output:\n$lyx_output"); &report(2, "\nSorry. I cannot find '$tex_doc'."); &abort("The LaTeX document was not generated by LyX!"); } else { &report(8, "Lyx Output:\n$lyx_output"); } }}#### search TeX document for a certain text tag (e.g. author, title)# parameter 1: file to parse# parameter 2: full TeX tag name# return value: list of the contents strings of all matching tagssub extract_tag_contents { my $source=$_[0]; my $tag_name=$_[1]; my $contents; my @results=(); my $error_message="Could not read TeX document to extract $tag_name"; &check_file($source, $error_message.'.'); open(EXTRACT_SOURCE, "<$source") or &abort($error_message." ($source)."); while(<EXTRACT_SOURCE>) { ### ignore comments s/(^|[^\\])%.*/$1/; # ignore \thanks{} s/\\thanks\{.*?\}//g; # change \and to and s/\\and/ and/g; $contents .= $_; } close EXTRACT_SOURCE; $_ = $contents; # add contents of all occurences of this tag in a line to result list while ( /\\($tag_name)(\[[^]]*?\])*?{+([^{}]*?)}/s ) { my $text = $3; $_ = $'; # remove newlines $text =~ s/\n//g; $text="" if (!defined($text)); push(@results, $text); } return @results;}#### search for filenames in given TeX Tag in entire document### skip all comments and duplicates while parsing# parameter 1: file to parse# parameter 2: full TeX tag name# parameter 3: reference to a list of possible filename suffixes (without '.')# parameter 4: regexp for suffix to ignore when specified in TeX file# (undef if not used)# return value: list of identified filessub identify_files { my $source=$_[0]; my $tag_name=$_[1]; my @suffixes=@{$_[2]}; my $ignore_suffix=$_[3]; my @matched_tags; my @found_files=(); my $regexp_suffixes; # create one large regexp from given suffixes and escape dots in them $regexp_suffixes= '.('.join('|', @suffixes).')'; $regexp_suffixes =~ s/\./\\./g; @matched_tags = &extract_tag_contents($source, $tag_name); foreach my $tag_contents (@matched_tags) { my $path;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -