Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm creating a class which should define a command if some package is available:

\IfFileExists{eforms.sty}{
   \usepackage[xetex]{eforms}
   \everyTextField{\textFont{GaramondNo8}\textSize{12}}
   \newcommand{\dsaTextInput}[3][12]{\raisebox{-0.35ex}{\textField[\textSize{#1}]{#2}{#3}{1em}}}
}{}

However, if I try to compile this, I get:

! Illegal parameter number in definition of \reserved@a.
<to be read again>
                   1
l.7 }{}

l.7 is the last line of the code I've shown. If I remove the conditional, it works as expected. What am I doing wrong?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

You just need to double the # symbols:

\IfFileExists{eforms.sty}{
   \usepackage[xetex]{eforms}
   \everyTextField{\textFont{GaramondNo8}\textSize{12}}
   \newcommand{\dsaTextInput}[3][12]{\raisebox{-0.35ex}{\textField[\textSize{##1}]{##2}{##3}{1em}}}
}{}

Why the doubling? Because the "true" and "false" branches are passed to \def\reserved@a{<true>} and \def\reserved@b{<false>}, so the usual rule applies.

See What is the meaning of double pound symbol (##1) in an argument? for more information

share|improve this answer

Similar to answers like Expandable version of \InputIfFileExists or \IfFileExists

\documentclass{article}
\IfFileExists{eforms.sty}{\def\x{T}}{\def\x{F}}
\if T\x%
   \usepackage{eforms}
   \everyTextField{\textFont{GaramondNo8}\textSize{12}}
   \newcommand{\dsaTextInput}[3][12]{\raisebox{-0.35ex}{\textField[\textSize{#1}]{#2}{#3}{1em}}}
\else
  \newcommand{\dsaTextInput}[3]{dsaTextInput Not Defined}
\fi
\begin{document}
\x
\dsaTextInput{10pt}{12pt}{Text}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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