Passing parameters to \input{text} (included text file)
\documentclass[letterpaper,10pt]{article}
% Definition of the variables
\newcommand{\myInterest}{Golf}
\newcommand{\myPosition}{Senior Engineer}
\newcommand{\myPlace}{New York}
\begin{document}
Dear So and So,
% Use
% \myPlace{}
% \myPosition{}
% \myInterest{}
% in boilerplate.tex
\input{boilerplate.tex}
\end{document}
The {}
after the commands are important in order to prevent that LaTeX "eats" the space after the command, see here for example. Consider to use the xspace package if you like my solution.
Using the listofitems
package, here is a homemade key-value interface that can handle an arbitrary number of specified values in the \input
file. If that is overkill, one of the original approaches that follow should suffice.
\documentclass[letterpaper,10pt]{article}
\usepackage{filecontents,listofitems}
\begin{filecontents*}{boilerplate.tex}
I am excited to apply for the position of [POSITION] at [PLACE]. Your organization's
reputation for rigorous, high-quality programming on topics in align perfectly with
my ambitions. I would relish the opportunity to collaborate with top coders on our
shared interests in [INTERESTS]. I am committed to excellence in programming
and supporting the Chicago Cubs.
\end{filecontents*}
\catcode`[=\active %
\def[#1]{\csname #1\endcsname{}}%
\catcode`[=12 %
\newcommand\myinput[2]{%
\setsepchar{,}%
\readlist*\mydata{#2}%
\foreachitem\myvardef\in\mydata{%
\setsepchar{=}%
\readlist*\myvar{\myvardef}%
\expandafter\edef\csname\myvar[1]\endcsname{\myvar[2]}%
}%
\catcode`[=\active %
\input{#1}%
\catcode`[=12 %
}
\begin{document}
Dear So and So,
\myinput{boilerplate}{POSITION=engineer, PLACE=IBM, INTERESTS=omphaloskepsis}
\end{document}
ORIGINAL APPROACHES
\documentclass[letterpaper,10pt]{article}
\usepackage{filecontents}
\begin{filecontents*}{boilerplate.tex}
I am excited to apply for the position of \POSITION{} at \PLACE{}. Your organization's
reputation for rigorous, high-quality programming on topics in align perfectly with
my ambitions. I would relish the opportunity to collaborate with top coders on our
shared interests in \INTERESTS{}. I am committed to excellence in programming
and supporting the Chicago Cubs.
\end{filecontents*}
\newcommand\myinput[4]{%
\def\POSITION{#2}%
\def\PLACE{#3}%
\def\INTERESTS{#4}%
\input{#1}%
}
\begin{document}
Dear So and So,
\myinput{boilerplate}{engineer}{IBM}{omphaloskepsis}
\end{document}
And if one really wanted to use bracketed delimiters in the input file, then this works (EDITED to allow arbitrary number of comma separated arguments in #2
):
\documentclass[letterpaper,10pt]{article}
\usepackage{filecontents,listofitems}
\begin{filecontents*}{boilerplate.tex}
I am excited to apply for the position of [POSITION] at [PLACE]. Your organization's
reputation for rigorous, high-quality programming on topics in align perfectly with
my ambitions. I would relish the opportunity to collaborate with top coders on our
shared interests in [INTERESTS]. I am committed to excellence in programming
and supporting the Chicago Cubs, [FOUR], [FIVE], [SIX], [SEVEN], [EIGHT], [NINE],
and [TEN].
\end{filecontents*}
\catcode`[=\active %
\def[#1]{\csname #1\endcsname{}}%
\catcode`[=12 %
\newcommand\myinput[2]{%
\setsepchar{,}%
\readlist*\mydata{#2}%
\def\POSITION{\mydata[1]}%
\def\PLACE{\mydata[2]}%
\def\INTERESTS{\mydata[3]}%
\def\FOUR{\mydata[4]}%
\def\FIVE{\mydata[5]}%
\def\SIX{\mydata[6]}%
\def\SEVEN{\mydata[7]}%
\def\EIGHT{\mydata[8]}%
\def\NINE{\mydata[9]}%
\def\TEN{\mydata[10]}%
\catcode`[=\active %
\input{#1}%
\catcode`[=12 %
}
\begin{document}
Dear So and So,
\myinput{boilerplate}{engineer,IBM,omphaloskepsis, Orioles, Red Sox, Cardinals,
Phillies, Tigers, Blue Jays, Braves}
\end{document}
You can hide almost everything in the boilerplate.tex
file. The trick is to define the text in a macro that will be called at the end, when the values to the appropriate keys will have been defined.
File boilerplate.tex
% define the text
\newcommand{\boilerplate}{%
I am excited to apply for the position of \use{position} at \use{place}.
Your organization's reputation for rigorous, high-quality programming
on topics in align perfectly with my ambitions. I would relish the
opportunity to collaborate with top coders on our shared interests
in \use{interests}. I am committed to excellence in programming and
supporting the Chicago Cubs.}
% define the infrastructure
\ExplSyntaxOn
\keys_define:nn { boilerplate }
{
position .tl_set:N = \l_invictus_position_tl,
place .tl_set:N = \l_invictus_place_tl,
interests .tl_set:N = \l_invictus_interests_tl,
}
\cs_new_protected:Nn \invictus_use_boilerplate:n
{
\keys_set:nn { boilerplate } { #1 }
\boilerplate
}
\cs_set_eq:NN \printboilerplate \invictus_use_boilerplate:n
\cs_new:Nn \invictus_use_variable:n
{
\tl_use:c { l_invictus_#1_tl }
}
\cs_set_eq:NN \use \invictus_use_variable:n
\ExplSyntaxOff
File test.tex
\documentclass{article}
\usepackage{xparse}
\usepackage{parskip} % normal choice for business letters
\input{boilerplate}
\begin{document}
Dear So and So,
\printboilerplate{
position = pitcher,
place = Wrigley Field,
interests = strikeouts,
}
Best regards.
\end{document}