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.

5
  • Welcome to TeX.SX! You can't use \enumerate, because it's already defined (for the enumerate environment).
    – egreg
    Feb 26, 2015 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. Feb 26, 2015 at 20:20
  • 1
    @StevenB.Segletes -- "one extra #"? I thought you needed to double: #1, ##1, ####1, etc....
    – jon
    Feb 26, 2015 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. Feb 26, 2015 at 23:34
  • @StevenB.Segletes -- Me neither! (Hence the tentative 'thought'.)
    – jon
    Feb 26, 2015 at 23:37

1 Answer 1

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

1
  • 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, 2015 at 20:55

You must log in to answer this question.

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