2

I am trying to create a TextField whose value is conditional on a boolean. If the boolean is true, the default value in the TextField is some value; if it is false, the TextField starts blank (the value is empty).

Here's my attempt:

\documentclass{article}

\usepackage{hyperref}
\usepackage{ifthen}

\newboolean{withcorrect}   
\setboolean{withcorrect}{false}   

\newcommand{\correctAnsBlankPlain}[1]{%
\ifthenelse{\boolean{withcorrect}}{%
#1%
}{}%
}

\begin{document}

\correctAnsBlankPlain{5.0}

\TextField[name=H%
,value=\correctAnsBlankPlain{5.0}%
]{}

\end{document}

which yields the error "./exam.tex:21: Argument of \boolean has an extra }."

I know the \correctAnsBlankPlain command works, because when I comment out the line containing the value, it compiles fine. I can also make the withcorrect boolean true and see the 5.0 printed as expected before the TextField.

So, I assume that I'm doing something wrong by including a command within the optional argument of TextField, but I'm not sure 1) what or 2) how to best get around it.

4

the commands in ifthen are not expandable and so unsuited in such places. Use e.g. the tools from etoolbox:

\documentclass{article}

\usepackage{hyperref}
\usepackage{etoolbox}
\newbool{withcorrect}
\setbool{withcorrect}{false}
\newcommand{\correctAnsBlankPlain}[1]{%
 \ifbool{withcorrect}{#1}{}}
\begin{document}

%\correctAnsBlankPlain{5.0}

\TextField[name=H1%
,value=\correctAnsBlankPlain{5.0}%
]{}

\setbool{withcorrect}{true}

\TextField[name=H2%
,value=\correctAnsBlankPlain{5.0}%
]{}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.