3

So I'm trying to create a simplified kind of list inside of an environment, so that calling one command will create an enumerated item and calling another will create a subitem.

Here's my code:

\newcounter{usagenumber}
\newcommand\enumerate{\stepcounter{usagenumber}{\small \arabic{usagenumber}.}}
\newenvironment{usages}
{
   \setcounter{usagenumber}{0}
   \begin{description*}
   \newcommand\itemdef[1]{\item[\enumerate] #1}
   \newcommand\itemex[1]
   {
      \begin{description*}
         \item[$\cdot$] #1
      \end{description*}
   }
}
{
   \end{description*}
}

I'm using the mdwlist package for the modified asterisk list, just for spacing. Typeset with xelatex.

  • Welcome to TeX.SX! You can't use \enumerate, because it's already defined (for the enumerate environment). – egreg Feb 26 '15 at 20:20
  • 1
    When defining commands in the context of other macros/environments, one must use ##1, instead of #1, one extra # for each level of command-within-a-command. – Steven B. Segletes Feb 26 '15 at 20:20
  • 1
    @StevenB.Segletes -- "one extra #"? I thought you needed to double: #1, ##1, ####1, etc.... – jon Feb 26 '15 at 22:10
  • @jon You know? I have never programmed at that depth until just now. And you are correct I have discovered through testing. – Steven B. Segletes Feb 26 '15 at 23:34
  • @StevenB.Segletes -- Me neither! (Hence the tentative 'thought'.) – jon Feb 26 '15 at 23:37
2

Not sure of your full intent, but perhaps something like this. As egreg pointed out in the comments, enumerate was already taken; and as I pointed out, the occurrences of #1 in the definitions of \itemdef and \itemex had to be recast as ##1, since they occurred in the context of environment usages.

\documentclass{article}
\newcounter{usagenumber}
\newcommand\xenumerate{\stepcounter{usagenumber}{\small \arabic{usagenumber}.}}
\newenvironment{usages}
{
   \setcounter{usagenumber}{0}
   \begin{description}
   \newcommand\itemdef[1]{\item[\xenumerate] ##1}
   \newcommand\itemex[1]
   {
      \begin{description}
         \item[$\cdot$] ##1
      \end{description}
   }
}
{
   \end{description}
}
\begin{document}
\begin{usages}
\itemdef{define xxx}
\itemdef{define yyy}
\itemex{example of yyy}
\itemdef{define zzz}
\itemex{example of zzz}
\itemdef{define aaa}
\end{usages}
\end{document}

enter image description here

  • I had misspelled enumerate in my document, so that wasn't the problem. But thank you, the ##1 fixed it. Sorry for being an idiot. – Shepard Feb 26 '15 at 20:55

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.