0

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)

barghest
  • 562

2 Answers2

2

You can also use \ifcsname:

\documentclass{article}
%\newcommand{\tool}{Photoshop}
%\newcommand{\tool}{GIMP}
%\newcommand{\tool}{Libre Office}
\newcommand{\tool}{Invisibility cloak}
%
\newcommand{\defineTool}[2]{\expandafter\newcommand\csname [#1]\endcsname{%
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}
g.kov
  • 21,864
  • 1
  • 58
  • 95
  • Thank you! Could you elaborate a bit on the \definetool part? Especially, why is \expandafternecessary? – barghest Mar 19 '13 at 12:17
  • 1
    @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
1

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

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036