8

I am trying to use \StrDel to modify a parameter to use within a command. For example, say my .tex file contains:

\command{Word Anotherword}

and the .sty file I reference contains:

\newcommand{\dosomething}[1]{

\some{#1}

\thing{\StrDel{#1}{ }}

}

I want it so when the command is called, the commands it contains are called as follows:

\some{Word Anotherword}

\thing{WordAnotherword}

So, in the second command \StrDel is used to delete the spaces in the parameter. But this keeps generating an the following error:

Use of \@item doesn't match its definition. \new@ifnextchar ...served@d = #1\def \reserved@a {#2}\def \reserved@d {#3}\f...

Have I made a mistake? And if not, is there a solution?

egreg
  • 1,121,712

1 Answers1

5

Whether this can work or not depends on what \thing is supposed to do. For instance, if it were \textit there would be no problem; but if \thing is \label then such an approach cannot work.

The problem is that \StrDel{a b c}{ } is not the string abc, but the set of instructions necessary to produce it and \label cannot process these instructions. The same would happen with many other commands.

There is a way out:

\newcommand{\something}[1]{%
  \some{#1}%
  \StrDel{#1}{ }[\temp]% remove spaces and store the string in \temp
  \expandafter\thing\expandafter{\temp}%
}

Depending on \thing, the two \expandafter commands may not be necessary (for instance \label would expand \temp anyway), but they don't harm.

egreg
  • 1,121,712
  • Thank you for taking the time to reply. This worked very well. Shamefully, I did not know of \temp until now. I will look it up! – jamesthenabignumber Aug 12 '13 at 22:09
  • @jamesthenabignumber \temp is as good as any other (usually undefined) command. It's just used for temporary storage. – egreg Aug 12 '13 at 22:42