Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Template::Latex Frustrations . . .

by CountZero (Bishop)
on May 05, 2010 at 06:07 UTC ( [id://838451]=note: print w/replies, xml ) Need Help??


in reply to Template::Latex Frustrations . . .

Hugh,

I cannot help you directly with Template::Latex as I do not use that module --and it seems from the lack of response that few of us Monks do-- but I do use LaTeX quite a lot to produce standard reports from databases. The formatting done by LaTeX can't be beaten!

Just like you I use Template::Toolkit to produce the LaTeX source file, but rather than running it through Template::Latex or Latex::Driver (which I found rather complicated to use) I use a nice little utility called latexmk which is a make-like utility (written in Perl!) specially made to compile LaTeX-files. I call it from within my Perl-script using backticks or the system command. It has a lot of switches to configure it exactly as you like. One of the more useful functions is a clean function to get rid of the lot of temporary files LaTeX uses.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^2: Template::Latex Frustrations . . .
by hesco (Deacon) on May 06, 2010 at 04:39 UTC
    CountZero:

    Thank you kindly. That is exactly what was needed to move me off of stuck. I just deployed the app tonight. I believe it to be doing the trick as I write, based on feedback from three testers (including myself).

    And the working code looks like this:

    $self->{'tt'} = Template->new({ INCLUDE_PATH => $self->{'cfg'}->param("pdf.include_path"), OUTPUT_PATH => $self->{'cfg'}->param("pdf.tmp_path") }); $self->{'tt'}->process($template,{ field => $field },$self->{'pdf_ou +tput'} . '.tex',binmode => 1) || die $self->{'tt'}->error(); my $cwd = cwd(); chdir $self->{'cfg'}->param("pdf.tmp_path"); $ENV{'USER'} = $self->{'cfg'}->param("pdf.user"); $ENV{'HOME'} = $self->{'cfg'}->param("pdf.home"); `latexmk -pdf $tmp_file.tex`; chdir $cwd; rename "$tmp_file.pdf", $file; unlink <$tmp_file.*>; $self->{'pdf_output_file'} = $file; $self->{'pdf_output_file_name'} = $self->{'pdf_output'} . '.pdf';
    As I see this posted, it seems I ought to refactor some of my config paramters which no longer point to pdf files but now to tex files. But other than that, your solution moved me forward in rather quick style.

    This is meeting all of my requirements, with respect to filing the resulting file appropriately and avoiding the risk of race conditions which would corrupt our archives. I have control over what to name the files.

    So far, the only complaint I've had about latexmk is how noisy it has been when I'm running my test suite. I'll have to review the --help on that script again. I'll bet their is a switch to quiet it down. But it was an easy install. I would be more comfortable calling methods somehow, for some reason using backticks other than in a quick throw-away script makes me nervous. But I have no idea if there is any reason for that.

    With this trick, the only thing holding me back now is my rudimentary latex skills.

    But I'd guess this will give me more reason to practice with that.

    Thanks again for the lead.

    -- Hugh

    if( $lal && $lol ) { $life++; }
    if( $insurance->rationing() ) { $people->die(); }
      Pleased to have been able to assist!

      Indeed latexmk is very loud by nature. calling it as follows:

      $result = `latexmk -pdf -f -silent $filenaam`;
      will quite it down a bit, but not totally.

      I usually add the -f (force) option, so latexmk doesn't quit at the first unresolvable error it encounters.

      the only thing holding me back now is my rudimentary latex skills
      Perhaps we should found a "LaTeXmonks" site, but thay will perhaps attract the wrong type of people! ;-)

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://838451]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 16:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found