hesco has asked for the wisdom of the Perl Monks concerning the following question:

I have a short Template::Toolkit script meant to handle a mail merge between a csv file and a template.tex file.

The perl side of this is working fine for me (from almost the first moment I drafted it), but getting the LaTeX part of this right has been a hair pulling experience. perldoc makes sense to me in ways that spending the day reading LaTeX artciles has not.

I have two, perhaps three issues at this point:

(1) Making my letterhead render with the logo in the top left corner (even inside the generous margins LaTeX offers by default), with the copy from the letterhead centered in a box to its right, all above the horizontal line offered by the letterhead.tex template;

(2) sorting out where the \begin and \end{document} commands ought to go given that I have one .tex file seeking to include another .tex file; and

(3) figuring out how to make that indentation work for all the lines related to the pollwatcher which are pulled from the data.

My letterhead.tex file:

\documentclass{article} \usepackage{fancyhdr} \usepackage[letterpaper]{geometry} \usepackage[pdftex]{graphicx} \pagestyle{fancy} \addtolength{\headheight}{0.25in} \begin{document} \fancyheadoffset[L]{10pt} \fancyhead[L]{\includegraphics{ggp_logo_100px}}% \begin{minipage}[t]{5in} \setlength\oddsidemargin{2in} \begin{center} \Large\textbf{The Georgia Green Party} \\ \normalsize {P.O. Box 450012; Atlanta GA 31145 \\ 404-574-3471 * ggp@greens.org \\ \underline{http://www.greens.org/georgia/}} \bigskip \small\emph{Ecological Wisdom * Grassroots Democracy * Social Justice +* Peace and Nonviolence \\ Decentralisation * Community-Based Economics * Feminism * Respect for +Diversity \\ Personal and Global Responsibility * Future Focus on Sustainability } \end{center} \end{minipage} \end{document}
and my pollwatcher_408b1.tmpl file:

\documentclass{article} % \include{letterhead} \begin{document} {The Superintendent of Elections \\ for [% County_Name %] County Georgia \\ [% County_Addr1 %] \\ [% County_Addr2 %] \\ [% County_city_st_zip %] \\ [% date %] \\ The undersigned, Chairperson(s) and Secretary of the Georgia Green Par +ty, pursuant to our authority under the Georgia Election Code, [% co +de_authority %], designate the below individual as a poll watcher for + the [% Election_Date_and_Type %] and assign them to observe operatio +ns at [% Precinct_Name %]; [%Precinct_Address %]. \\ \setlength\parindent{4em} [% Poll_Watcher %] \\ \setlength\parindent{4em} Birthday: [% Poll_Watcher_Birthdate %] \\ \setlength\parindent{4em} [% Poll_Watcher_Addr1 %]; [% Poll_Watcher_city_st_zip %] \\ \setlength\parindent{0em} We are yours for a just and sustainable future, \\ Thano Paris, Co-Chair \\ Harry Rezzemini, Secretary \\ \end{document}
And the trivial test script that is supposed to put it altogether (merging data from database awaits a working test of what is shown above), called: create_pollwatcher_letter.pl

#!/usr/bin/perl -w use strict; use warnings; use Template; use Template::Plugin::Latex; my $cfg = { INCLUDE_PATH => '/home/hesco/GP/GGP/PollWatchers/Templates' }; my $template = Template->new($cfg); my $vars = { County_Name => 'Camden County', County_Addr1 => '208 East 4th Street', County_Addr2 => 'P.O. Box 608', County_city_st_zip => 'Woodbine GA 31569-0608', date => 'Monday, October 27th, 2008', code_authority => '21-2-408(b)(1)', Election_Date_and_Type => 'November 4th, 2008 General Election', Precinct_Name => 'Woodbine City Hall 03 Precinct', Precinct_Address => '310 Bedell Avenue; Woodbine GA 31569' +, County => 'Camden', Poll_Watcher => 'Jane Citizen', Poll_Watcher_Birthdate => 'January 31, 1956', Poll_Watcher_Addr1 => '197 Some Drive', Poll_Watcher_city_st_zip => 'Brunswick GA 31525', }; my $input = 'pollwatcher_408b1.tmpl'; my $output = 'test'; $template->process($input,$vars,"$output.tex", binmode => 1) || die $t +emplate->error(); # my $result = `latex "$output.tex"`; # $result = `dvips "$output.dvi"`; # $result = `ps2pdf "$output.ps"`; 1;
Any and all advise is appreciated. Thanks,

-- Hugh

if( $lal && $lol ) { $life++; }

Replies are listed 'Best First'.
Re: OFF-TOPIC: Seeking LaTeX advice, please
by kvale (Monsignor) on Oct 28, 2008 at 00:41 UTC
    You should only have one document environment per document. I'd to something like
    % \include{preamble} \begin{document} % \include{header} {The Superintendent of Elections \\ for [% County_Name %] County Georgia \\ [% County_Addr1 %] \\ [% County_Addr2 %] \\ [% County_city_st_zip %]} \\ ...
    where the preamble is
    \documentclass{article} \usepackage{fancyhdr} \usepackage[letterpaper]{geometry} \usepackage[pdftex]{graphicx} \pagestyle{fancy} \addtolength{\headheight}{0.25in}
    and the header is
    \fancyheadoffset[L]{10pt} \fancyhead[L]{\includegraphics{ggp_logo_100px}}% \begin{minipage}[t]{5in} \setlength\oddsidemargin{2in} \begin{center} \Large\textbf{The Georgia Green Party} \\ \normalsize {P.O. Box 450012; Atlanta GA 31145 \\ 404-574-3471 * ggp@greens.org \\ \underline{http://www.greens.org/georgia/}} \bigskip \small\emph{Ecological Wisdom * Grassroots Democracy * Social Justice +* Pea +ce and Nonviolence \\ Decentralisation * Community-Based Economics * Feminism * Respect for +Diver +sity \\ Personal and Global Responsibility * Future Focus on Sustainability } \end{center} \end{minipage}
    For (1) and (3), The Latex Companion is an invaluable book for finding the tricks needed to force your will upon LaTeX.

    -Mark

Re: OFF-TOPIC: Seeking LaTeX advice, please
by CountZero (Bishop) on Oct 28, 2008 at 06:36 UTC
    Is there a reason you are not using the standard letter class or one of the many other letter classes (such as akletter? Most of these provide even for automated mailmerges.

    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

Re: OFF-TOPIC: Seeking LaTeX advice, please
by moritz (Cardinal) on Oct 28, 2008 at 06:37 UTC
    Why do you use \documentclass{article} when you write a letter? There are better, specific document classes for letters that would make your live much easier.

    Since I write my letters mostly in German and according to German standards I don't know much about the English, but it doesn't look very complicated either.