运行LaTeX文件以生成PDF

时间:2017-07-30 19:34:11

标签: perl latex

我在互联网上发现了这个代码而且我非常困惑。你能帮帮我吗?

似乎生成的文件将保存到名为cover_letters的文件夹中,该文件夹应该已存在。我运行了代码,但即使没有给出错误,我也找不到生成的文件。我误解了什么吗?

use strict;

use Schools;

sub main;
sub generate_latex;

# Set this to 1 if you want to generate cover letters for all
# schools regardless of whether their DO_GENERATE_KEY is set.
my $generate_all_ = 0;

# The directory where the files will go (should be created already).
my $cover_letter_dir_ = "cover_letters";

# The prefix that will be prepended to each file.
my $fname_pre_ = "coverletter_";

# A log file to see an errors.
my $log_file_ = "coverletter.log";

main();

sub main {

    my $key;
    my $num_keys = scalar(keys(%Schools::univ_));
    my $ctr = 1;

    print "\n";

    if(-e $cover_letter_dir_."/".$log_file_) {
        unlink($cover_letter_dir_."/".$log_file_);
    }

    my $i;
    if($generate_all_ == 1) {
        my @prev_fnames = glob($cover_letter_dir_."/".$fname_pre_."*");
        foreach $i (@prev_fnames) {
            unlink $i;
        }
    }

    foreach $key (keys(%Schools::univ_)) {
        if($generate_all_ == 1 || 
                (defined $Schools::univ_{$key}{$Schools::DO_GENERATE_KEY} &&
                $Schools::univ_{$key}{$Schools::DO_GENERATE_KEY} > 0)) {
            print "Generating $key, $ctr of $num_keys\n";
            generate_latex($key);
            $ctr++;
        }
    }

    print "\n";

}

# NOTE: You should change the LaTeX in this function
# to generate the format you desire.  I used the newlfm
# and charter (a font) packages to create my files.

sub generate_latex {


    my $key = shift;
    my $fname = $cover_letter_dir_."/".$fname_pre_.$key.".tex";
    local *OUT;

    open(OUT, '>', $fname) || die "Cannot open $fname\n";

    # newlfm is available at:
    # http://www.tug.org/tex-archive/help/Catalogue/entries/newlfm.html
    print OUT "\\documentclass[10pt,stdletter]{newlfm}\n";
    print OUT "\\usepackage{charter}\n\n";

    # Determines how forceful LaTeX is in making sure page breaks
    # do not leave orphaned lines.
    print OUT "\\widowpenalty=1000\n";
    print OUT "\\clubpenalty=1000\n\n";

    # Replace "figures/logo" with the logo you want to use and
    # ".eps" with the extension of your file.
    print OUT "\\newsavebox{\\Luiuc}\n";
    print OUT "\\sbox{\\Luiuc}{%\n";
    print OUT "\t\\parbox[b]{1.75in}{%\n";
    print OUT "\t\t\\vspace{0.5in}%\n";
    print OUT "\t\t\\includegraphics[scale=1.0,ext=.eps]\n";
    print OUT "\t\t{figures/logo}%\n";
    print OUT "\t}%\n";
    print OUT "}%\n";
    print OUT "\\makeletterhead{Uiuc}{\\Lheader{\\usebox{\\Luiuc}}}\n\n";

    print OUT "\\newlfmP{headermarginskip=20pt}\n";
    print OUT "\\newlfmP{sigsize=50pt}\n";
    #print OUT "\\newlfmP{sigskipbefore=20pt}\n";
    print OUT "\\newlfmP{dateskipafter=20pt}\n";
    print OUT "\\newlfmP{addrfromphone}\n";
    print OUT "\\newlfmP{addrfromemail}\n";
    print OUT "\\PhrPhone{Phone}\n";
    print OUT "\\PhrEmail{Email}\n\n";

    print OUT "\\lthUiuc\n\n";

    print OUT "\\namefrom{Your Name}\n";
    print OUT "\\addrfrom{%\n";
    print OUT "\tYour Street\\\\\n";
    print OUT "\tBeverly Hills, CA 90210\n";
    print OUT "}\n";
    print OUT "\\phonefrom{217-555-5555}\n";
    print OUT "\\emailfrom{you\@school.edu}\n\n";

    if(defined $Schools::univ_{$key}{$Schools::ADDR_KEY}) {
        if(defined $Schools::univ_{$key}{$Schools::TO_NAME_KEY}) {
            print OUT "\\nameto{".
                "$Schools::univ_{$key}{$Schools::TO_NAME_KEY}}\n";
        }
        print OUT "\\addrto{%\n";
        print OUT "$Schools::univ_{$key}{$Schools::ADDR_KEY}";
        print OUT "}\n\n";
    }

    # Specify the default string to use if no TO_NAME key is defined.
    my $to_str = "To Whom It May Concern";
    #my $to_str = "Dear Faculty Search Committee";
    if(defined $Schools::univ_{$key}{$Schools::TO_NAME_KEY}) {
        my @name = split(/ /, 
            $Schools::univ_{$key}{$Schools::TO_NAME_KEY});
        $to_str = "Dear $name[0] $name[$#name]";
    }

    print OUT "\\greetto{$to_str,}\n";
    print OUT "\\closeline{Sincerely,}\n";

    print OUT "\\begin{document}\n";
    print OUT "\\begin{newlfm}\n\n";

    # Specify a default string to use if no UNIV_KEY or DEPT_KEY is defined.
    my $dept_str = "your department";
    if(defined $Schools::univ_{$key}{$Schools::UNIV_KEY} && 
            defined $Schools::univ_{$key}{$Schools::DEPT_KEY}) {
        # Make the school possessive...deal with school names ending
        # in 's'.
        my $poss_str = "'s";
        my $name_str = $Schools::univ_{$key}{$Schools::UNIV_KEY};
        if(substr($name_str,(length($name_str) - 1), 1) eq "s") {
            $poss_str = "'";
        }
        $dept_str = "$Schools::univ_{$key}{$Schools::UNIV_KEY}$poss_str ".
        "$Schools::univ_{$key}{$Schools::DEPT_KEY} Department"
    }

    # By default, do not include any string about your research 
    # background.
    my $area_str = "";
    if(defined $Schools::univ_{$key}{$Schools::AREA_KEY}) {
        # If the ad is relevant to your specific background, use this
        # string.
        $area_str =
        "My background is particularly applicable to your advertised\n".
        "preference in the area of ".
        "$Schools::univ_{$key}{$Schools::AREA_KEY}.\n";
    }

    # By default, do not print anything extra for the school.
    my $loc_str = "";
    if(defined $Schools::univ_{$key}{$Schools::LOCATION_KEY}) {
        # If extra info is defined for the school, print it.
        $loc_str = $Schools::univ_{$key}{$Schools::LOCATION_KEY};
    }

    # Here's the actual text that will go in your cover letter.
    # I will leave mine in as an example, but it is NOT a template.
    # DO NOT PLAGERIZE THIS!!!  The cover letter should be unique
    # to you.  Plus, it is a well-known fact that the job gods
    # look very unfavorably upon anyone that doesn't write their
    # own cover letter.

    print OUT "I am writing to apply for the position of assistant\n".
    "professor in $dept_str.  I plan to receive my\n".
    "Ph.D.\\ degree from the University of Illinois at\n".
    "Urbana-Champaign in Summer of 2006.  My adviser is\n".
    "Prof.\\ Nitin H.\\ Vaidya, and my general areas of interest\n".
    "include wireless and sensor network performance and security.\n".
    "$area_str $loc_str\n";

    print OUT "In my graduate work, I focus on the design of\n".
    "energy-efficient protocols and secure key distribution.\n".
    "More specifically, I have explored various techniques at\n".
    "multiple layers of the network stack to effectively reduce\n".
    "the energy consumption of wireless communication.  In security,\n".
    "my work was the first to propose leveraging channel diversity\n".
    "for sensor network key distribution.  My research appears in \n".
    "the \\textit{IEEE Transactions on Mobile Computing} journal as\n".
    "well as \\textit{Infocom 2006} and \\textit{ICDCS 2005},\n".
    "prestigious conferences in the areas of networking and distributed\n".
    "systems, respectively.\n\n";

    print OUT "Enclosed is my curriculum vitae (including a list of\n".
    "publications), contact information for my references, a research\n".
    "statement, and a teaching statement.  All of my publications and\n".
    "presentations are available at:\n\n";

    print OUT "http://www.crhc.uiuc.edu/\$\\sim\$mjmille2/publications/\n\n";

    print OUT "Please let me know if there are any other materials\n".
    "or information that will assist you in processing my application.\n\n";

    print OUT "Thank you for your consideration.  I look forward to\n".
    "hearing from you.\n\n";

    print OUT "\\end{newlfm}\n";
    print OUT "\\end{document}\n\n";

    close OUT;

    chdir($cover_letter_dir_);
    # Change this command if you generate LaTeX with a different
    # series of commands.
    system("latexmk -pdfps $fname_pre_$key >> $log_file_ 2>&1");
    chdir("..");

}

0 个答案:

没有答案