1

How can I expand a macro inside an optional argument list

\newcommand{\sss}{%
label={$\bullet$},topsep=0mm, parsep=0mm,% leftmargin=3mm,rightmargin=0cm,labelwidth=5mm,labelsep=3mm%
}

\begin{itemize}[\sss] 
\item gugus
\end{itemize}

This does not work, (not giving any good debuggin message). So the expansion is wrong?

How can I fix this?

4
  • This is the typical trap with key-value-interfaces, it won't work this way
    – user31729
    Aug 26, 2015 at 13:24
  • What is the trap here :-) or better what does latex do when inserting the macro?
    – Gabriel
    Aug 26, 2015 at 13:25
  • The trap is the non-expansion of key-value - parsers, but David Carlisle stated this already
    – user31729
    Aug 26, 2015 at 15:14
  • There are some solutions to this question as well other answers to your other questions, but you rarely accept answers -- that's not really a proof of approving the efforts by users in order to help you
    – user31729
    Dec 2, 2015 at 20:46

2 Answers 2

3

keyval parsers typically don't expand the arguments (otherwise things like font=\small would blow up badly as \small would expand too early.

so the simplest thing is to use

\newenvironment{sss}{%
\begin{itemize}[label={$\bullet$},topsep=0mm, parsep=0mm,% leftmargin=3mm,rightmargin=0cm,labelwidth=5mm,labelsep=3mm%
]}
{\end{itemize}}

\begin{sss}
\item gugus
\end{sss}
0
1

Usually a key value parser needs to see the syntax characters = and , directly. Therefore, the macro \sss should be expanded once. This can be done with lots of \expandafter:

\expandafter\begin\expandafter{\expandafter i\expandafter t ...\expandafter}\expandafter[\sss]

or the whole expression can be expanded as macro:

\edef\next{%
  \noexpand\begin{itemize}[\unexpanded\expandafter{\sss}]%
}\next

Here, \unexpanded prevents the further expansion of \sss after it was expanded once to prevent values from expanding too early.

2
  • Do you have some good reference to learn about expansions?
    – Sigur
    Aug 26, 2015 at 13:32
  • 1
    "The TeXbook" by Donald E. Knuth or "TeX by Topics" by Victor Eijkhout. Aug 26, 2015 at 13:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .