2

I am trying to create a template document in LaTeX, which contains text placeholders that I would define during compilation. For example:

\documentclass{article}

\begin{document}
\section{Introduction}

This is a placeholder document which contains [p1], [p2] and [p3].

\end{document}

So that I can later compile latex mydoc.tex p1=First p2=Second p3=Third

and get an output of This is a placeholder document which contains First, Second and Third.

I am wondering how can I achieve this (or some similar behavior)?

1 Answers1

1

You could use Heiko's trick. Suppose your file is called test.tex. Then compiling

\documentclass{article}

\begin{document}
\section{Introduction}

This is a placeholder document which contains \PlaceHolder1, \PlaceHolder2 and \PlaceHolder3.

\end{document}

with

pdflatex '\def\PlaceHolder#1{\ifcase#1\or blub\or bla\or pft\fi}\input{test}'

yields

enter image description here

Or, a more fancy version: assume placeholders.txt contains

p1=First,p2=Second,p3=Third

and the TeX file

\documentclass{article}
\usepackage{catchfile}
\usepackage{pgf}
\newcommand{\PlaceHolder}[1]{\pgfkeysvalueof{/placeholder/p#1}}
\CatchFileEdef{\PlaceHolderKeys}{placeholders.txt}{}
\edef\tmp{\noexpand\pgfkeys{/placeholder/.cd,p1/.initial={},p2/.initial={},p3/.initial={},%
\PlaceHolderKeys}}\tmp
\begin{document}
\section{Introduction}

This is a placeholder document which contains \PlaceHolder{1},
 \PlaceHolder{2} and \PlaceHolder{3}.

\end{document}

yields

enter image description here