% I am ./templates/labels/labels.tex.tx
\documentclass[12pt]{letter}
\usepackage{graphicx}
\usepackage{labels}
\begin{document}
: for $data -> $label {
: include 'label.tex.tx' { label => $label };
: }
\end{document}
####
% I am ./templates/labels/label.tex.tx
\genericlabel{
\begin{tabular}{|c|}
\hline
: if $label.sender.logo {
\includegraphics[width=1cm,angle=0]{<: $label.sender.logo :>}\\
: }
\hline
<: $label.recipient.fullname :>\\
\hline
: for $label.recipient.addresslines -> $addressline {
<: $addressline :>
: }
\\
<: $label.recipient.postcode :>\\
\hline
\end{tabular}
}
##
##
use LaTeX::Easy::Templates;
use FindBin;
my $curdir = $FindBin::Bin;
# the templates can be placed anywhere as long these
# paths are adjusted. As it is now, they
# must both be placed in ./templates/labels
# the main entry is ./templates/labels/labels.tex.tx
# which calls/includes ./templates/labels/label.tex.tx
my $template_filename = File::Spec->catfile($curdir, 'templates', 'labels', 'labels.tex.tx');
# optionally specify a logo image
my $logo_filename = File::Spec->catfile($curdir, 'templates', 'images', 'logo.png');
if( ! -e $logo_filename ){ $logo_filename = undef }
my $output_filename = 'labels.pdf';
# see LaTeX::Driver's doc for other formats, e.g. pdf(xelatex)
my $latex_driver_and_format = 'pdf(pdflatex)';
# debug settings:
my $verbosity = 1;
# keep intermediate latex file for inspection
my $cleanup = 1;
my $sender = {
fullname => 'Gigi Comp',
addresslines => [
'Apt 5',
'25, Jen Way',
'Balac'
],
postcode => '1An34',
# this assumes that ./templates/images/logo.png exists, else comment it out:
logo => $logo_filename,
};
my @labels_data = map {
{
recipient => {
fullname => "Teli Bingo ($_)",
addresslines => [
'Apt 5',
'25, Jen Way',
'Balac'
],
postcode => '1An34',
},
sender => $sender,
}
} (1..42); # create many labels yummy
my $latter = LaTeX::Easy::Templates->new({
'debug' => {
'verbosity' => $verbosity,
'cleanup' => $cleanup
},
'processors' => {
'custom-labels' => {
'template' => {
'filepath' => $template_filename,
},
'latex' => {
'filepath' => 'xyz.tex',
'latex-driver-parameters' => {
'format' => $latex_driver_and_format,
}
}
},
}
});
die "failed to instantiate 'LaTeX::Easy::Templates'" unless defined $latter;
my $ret = $latter->format({
'template-data' => \@labels_data,
'output' => {
'filepath' => $output_filename,
},
'processor' => 'custom-labels',
});
die "failed to format the document, most likely latex command has failed." unless defined $ret;
print "$0 : done, output in '$output_filename'.\n";