# How can i create multiple documents from one template - depending on special “variables”?

I am currently trying to set up a document template that allows for automated creation of different output files depending on a certain "input".
The "input" could be a variable or a certain kind of command.

What i am trying to achieve is something along the lines of

\documentclass{article}

\newcommand{\tool}{Photoshop}

\begin{document}

\section{Install Guide for the tool \tool}

\ldots

After installation, you can find the tool under C:\textbackslash Program
Files\textbackslash\tool''. \par\bigskip

Pseudocode starts here: \par\bigskip

if (\textbackslash tool == Photoshop''): \newline

The amazing thing about \textbackslash tool\ is: it is quite
expensive\ldots\newline

fi\par\bigskip

else if (\textbackslash tool == GIMP''):  \newline

The amazing thing about \textbackslash tool is: it is freeware and
Open-Source as well!\newline

fi\par\bigskip

else: \newline

I don't know what tool you are talking about, please tell me more!

\end{document}


So far, i have only found "if" examples comparing numbers with \ifnum or macros with \ifx.
This does not seem to work with strings, however. I am aware of the includeonly and excludeonlypackages, which would however require a lot of fiddling once the document grows bigger.
Also, it would probably be difficult to steer includeonly/excludeonly from outside of the document (document build will be automatized via ant)

-
Take a look at tex.stackexchange.com/questions/29133/… - there you can find \ifstrequal from etoolbox. This can handle your string matching. – Dominikus K. Mar 19 '13 at 9:26
This has come up several times as TeX's idea of a comparison is somewhat different to many other languages, see for example String equality in \ifx conditional using output from concatenating macros or String test, with complicated arguments for some background. These might help you. – Joseph Wright Mar 19 '13 at 9:26
For me it is not clear what you want to achieve. For string comparison the ifthen package could be used. You should avoid includeonly and the like in this context, since it has several side effects. – Chris Mar 19 '13 at 9:27

You can also use \ifcsname:

\documentclass{article}
%\newcommand{\tool}{Photoshop}
%\newcommand{\tool}{GIMP}
%\newcommand{\tool}{Libre Office}
\newcommand{\tool}{Invisibility cloak}
%
The amazing thing about #1 is: #2\newline}}
%
\newcommand{\toolInfo}[1]{%
\ifcsname [#1]\endcsname
\csname [#1]\endcsname
\else
#1'', really? I don't know what tool you are talking about, please tell me more!
\fi
}
%
\defineTool{Photoshop}{it is quite expensive\ldots}
\defineTool{GIMP}{it is freeware and Open-Source as well!}
\defineTool{Libre Office}{%
it is the free power-packed open source personal productivity suite
for Windows, Macintosh and Linux.
}

\begin{document}
\section{Install Guide for the tool \tool}
\ldots
After installation, you can find the tool under C:\textbackslash Program
Files\textbackslash\tool''. \par\bigskip

\toolInfo{\tool}
\end{document}

-
Thank you! Could you elaborate a bit on the \definetool part? Especially, why is \expandafternecessary? – barghest Mar 19 '13 at 12:17
@Fabian Schmidt: Here \expandafter is necessary, because it instructs TeX to prepare a command name to be defined (e.g. [GIMP], which can be used directly as \csname[GIMP]\endcsname as a \newcommand. Without \expandafter a command name would be considered as just csname. – g.kov Mar 19 '13 at 12:56

When I needed to accomplish a similar task, I used the package: xstring.

The documentation is here: http://mirrors.ctan.org/macros/generic/xstring/xstring_doc_en.pdf

-