如何根据特殊的“变量”从一个模板创建多个文档?

如何根据特殊的“变量”从一个模板创建多个文档?

我目前正在尝试设置一个文档模板,以便根据特定的“输入”自动创建不同的输出文件。
“输入”可以是变量或某种命令。

我想要实现的目标是

\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}

到目前为止,我只找到了将数字与\ifnum或 宏与进行比较的“if”示例\ifx
但这似乎不适用于字符串。我知道includeonlyexcludeonly包,但是一旦文档变大,它们就需要大量调整。
此外,从文档外部进行控制可能很困难includeonly/excludeonly(文档构建将通过 自动化ant

答案1

您还可以使用\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}

答案2

当我需要完成类似的任务时,我使用了以下包:字符串

文档在这里:http://mirrors.ctan.org/macros/generic/xstring/xstring_doc_en.pdf

相关内容