I'm glad you found a solution for this problem, especially since it uses perl. Here are just a few suggestions:

1) Since LaTeX has uses backslashes a lot, you can make it easier on yourself by using a 'here'-document with single quotes:

print <<'END'; \documentclass{article} \usepackage{graphicx} \usepackage{fullpage} \begin{document} END
2) Unfortunately, perl's own variable interpolation syntax is disabled when using here-documents within single quotes. On the other hand, writing your own mini-templating system is just a few lines in perl:
sub substitute_vars { my ($template, $hash) = @_; (my $out = $template) =~ s/\${([^}]+)}/$$hash{$1}/ge; $out; }
and here's how you could use it (write ${imfile} whenever you want to insert the value of imfile, etc.):
my $template = <<'TEMPLATE_END'; \section{${imfile}} \begin{figure}[!hbp] \centerline{\includegraphics[width=9cm, height=9cm]{ims/${imfile}_gd.p +ng}} \end{figure} \begin{figure}[!hbp] \centerline{\includegraphics[width=12cm, height=9cm]{${imfile}mfm.png} +} \end{figure} \newpage TEMPLATE_END for (@text) { chomp; print substitute_vars($template, { imfile => $_ } ); }
Of course, once your needs started to get more demanding, I'd consider using an existing templating system.

3) Finally, you can define your own macros in LaTeX with \newcommand. You might try something along the lines of this:

\newcommand{\insert_figures}[1]{ \section{#1} ... \centerline{\includegraphics[width=9cm, height=9cm]{ims/#1_gd.png}} ... \centerline{\includegraphics[width=12cm, height=9cm]{#1mfm.png}} ... \newpage }
However, if you have to manipulate the macro arguments, you might find using something you are familiar with (like perl) easier.

In reply to Re^3: repetitive latex doc: in vim or perl? by pc88mxer
in thread repetitive latex doc: in vim or perl? by stabu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.