# How to use \begin & \end in a new command

I am trying to define a new command to customize the item-based behavior within the LaTeX, as below:

\newcommand{\myitemize}[2]{
\begin{description}
\item[$\{#1}$]{#2}
\end{description}
}


It is supposed to be called as:

\myitemize{bullet}{matinking}


But there is an error, as below, which does not let the document to be compiled:

! LaTeX Error: Missing \begin{document}.


The problem is seemingly with the utilization of the \begin & \end within the command.

Would you please guide me how to handle this case?

PS. I've declared the new command before the \begin{document}.

• Don't reinvent the wheel: use enumitem. – cfr Oct 9 '15 at 13:10
• I think the problem is not related to what you say, but is due to the non-matching \{ and } (the first typesets a {, while the second closes a group, which had not been opened). – LucaD Oct 9 '15 at 13:11
• @cfr: Thanks for the suggestion. But I am eager to realize my fault within above definition, too... – Roboticist Oct 9 '15 at 13:11
• In that case, see @LucaD 's comment. – cfr Oct 9 '15 at 13:12
• I have to use \ to apply the command effect... such as \bullet... right? – Roboticist Oct 9 '15 at 13:13

The problem with your code is that you match \{ with } in your command definition. { and } are used to create a group, while \{ and \} could be used to typeset a couple of braces. The error message is given because you close a group which has not been opened.

Indeed the following code works and prints the first argument between braces. However, looking at your example use, it probably doesn't do what you intended:

\documentclass{article}
\newcommand{\myitemize}[2]{
\begin{description}
\item[$\{#1\}$]{#2}
\end{description}
}
\begin{document}
\myitemize{bullet}{matinking}
\end{document}


I guess that what you are trying to achieve is to turn the first argument of your command into a macro: this can be done using the \csnames \endcsname tex primitives, as already mentioned by cfr

\documentclass{article}
\newcommand{\myitemize}[2]{
\begin{description}
\item[$\csname #1\endcsname$]{#2}
\end{description}
}
\begin{document}
\myitemize{bullet}{matinking}
\end{document}

• Such an omni-aspect explanation. Thanks... Would you please tell me the difference between the two cases you illustrated?... Which one might be preferable?... – Roboticist Oct 9 '15 at 13:33
• The first is only a valid code similar to what you posted, but it produces {bullet}, which is not what you wanted, I susupect. The second turns the text bullet into the \bullet macro. – LucaD Oct 9 '15 at 13:40

LucaD explained the problem. To do what you want, you need to use something like \csname... \endcsname here:

\documentclass{article}
\newcommand{\myitemize}[2]{%
\begin{description}
\item[$\csname #1\endcsname$]{#2}
\end{description}%
}
\begin{document}
\myitemize{bullet}{matinking}
\end{document}


• I would appreciate... – Roboticist Oct 9 '15 at 13:17