1

I am trying to use the KOMA-Script command \newcaptionname which takes a macro name as its second argument, but I need spaces in it:

\documentclass{scrartcl}

\newcaptionname{english}{\namewithoutspaces}{With spaces.}
\newcaptionname{english}{\csname name with spaces\endcsname}{Without Spaces} % fails

\usepackage[english]{babel}

\begin{document}
    \namewithoutspaces

    \csname name with spaces\endcsname
\end{document}

\namewith is properly defined, but obviously, the definition of \csname name with spaces\endcsname fails. I know that this has something to do with expansion, but I think I still do not fully understand this concept (together with all related commands like \expandafter, \noexpand, \edef, ...).

How do I have to modify

\newcaptionname{english}{\csname name with spaces\endcsname}{Without Spaces}

to make it work?

  • 1
    why do you need to define a macro with spaces in its name ? (The \csname usage you show does that, but it is hard to see why you need that here? – David Carlisle May 5 '14 at 14:34
  • The names I have to use in \newcaptionname come from a list of predefined keywords which in my case contain spaces. – porst17 May 5 '14 at 14:47
  • I'd normalise your keywords first:-) – David Carlisle May 5 '14 at 14:59
3

It is hard to see why you would need this, but

\documentclass{scrartcl}

\newcaptionname{english}{\namewithoutspaces}{With spaces.}
\def\tmp{\newcaptionname{english}}
\expandafter\tmp\csname name with spaces\endcsname{Without Spaces} % works

\usepackage[english]{babel}

\begin{document}
    \namewithoutspaces

    \csname name with spaces\endcsname
\end{document}

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.