Revised question
(Trying to follow suggestion in comment by David Carlisle.)
I want to assign a string as the value of a command and then take alternative actions (by means of ifthenelse
) according to whether the value of that string equals a particular value.
Example:
\documentclass{article}
\newcommand{\thing}{whatever}
\usepackage{ifthen}
\ifthenelse{\equal{\thing}{\string whatever}}{%
{\newcommand{\result}{thing is `whatever'.}}
{\newcommand{\result}{thing is something else.}}%
}
\begin{document}
\result
\end{document}
What is wrong there with my \ifthenelse{\equal{\thing...
test there? The command \result
is never given a value, for a latex run gives error:
./whatever.tex:13: Undefined control sequence.
l.13 \result
Underlying purpose
In the actual project, which is book-length and involves a preamble consisting of some dozen "helper" files that are input in the root document, several "style" commands such as \thing
are defined in root document in order to allow choosing among alternatives for each of various aspects of the overall document design, e.g., text width, font families, header styles. In those "helper" files, \ifthenelse
tests are used for each such "style" command (instead of the simple-minded definition of \result
shown in my MWE).
Thus I will be able to change such style parameters just by changing a word in the root document preamble, without having to burrow into the individual "helper" files and make edits there.
Original question
Using the generic TeX package texapi
— or otherwise — (along with ifthen
) I want to "declare" a string name, assign a string value to that name, and then take some action conditional upon that value.
For example:
\documentclass{article}
\input{texapi.tex}
\newstring{thing}
% HOW assign a value here to the string `thing'?
\usepackage{ifthen}
\ifthenelse{\equal{thing}{\string whatever}}{%
{\newcommand{\result}{``It's whatever.''}}
{\newcommand{\result}{``It's something else.''}}%
}
\begin{document}
\result
\end{document}
Is this possible and, if so, how?
(The packages I've looked at, namely, xstring
and stringstring
, give lots of commands for manipulating and testing strings, but do not seem to have commands to assign a string value.)
\newstring{thing}
definesthing
as the string, to be used in comparisons such as\ifprefix
,\ifsuffix
or\ifcontains
. Definitely not to be used with\ifthenelse
and you can't assign it a value.\newcommand\thing{whatever}
to be tested via\ifthenelse{\thing}{whatever}....
?pgfkeys
for that? They allow you to do all sort of things, of course also to implement switches. One way is to sayblabla/.code={\blablatrue}
, of course you need to introduce\newif\ifblabla
before. Then you can say\ifblabla\typeout{true}\else\typeout{false}\fi
, where you can replace the typepouts with more meaningful commands.\string whatever
where\string
makes (just) thew
a catcode 12 punctuation character so not equal to the letterw
, and then you have a spurious{...}
around the\newcommand\result
so that whichever branch is taken\result
is defined but not visible after the test.