I'm trying to create an environment with a given macro as name:
\newcommand{\newproblemset}[1]{\newenvironment{#1}{}}
\newproblemset{problem}
However, the compiler gives the following error, though I don't define \problem
directly:
LaTeX Error: Command \problem already defined.
The purpose is that I want to create a command, that supports creating an environment with a user-specified environment name.
Another issue arises when I want to define a counter with user-specified name. Although I managed to create the counter successfully, I don't how to refer to that counter, since the counter name should be in the form of \the
followed by the counter name.
It seems the issue lies in the way how LaTeX does macro expansion. In fact, what I want to do is exactly what \newtheorm
does, which creates an environment with user-given names.
Update: a full example
\documentclass{article}
\newcommand{\newproblemset}[1]{\newenvironment{#1}{c1}{c2}}
\newproblemset{aa}
\begin{document}
\begin{aa}
content
\end{aa}
\end{document}
Compiler's error:
root.tex
LaTeX Error: Command \aa already defined.
For defining a counter:
\documentclass{article}
\newcommand{\newproblemset}[1]{\newcounter{#1}[section]\renewenvironment{#1}{c1 \refstepcounter{#1} \the#1 }{c2}}
\newproblemset{aa}
\begin{document}
\begin{aa}
aa
\end{aa}
\end{document}
It gives an error:
root.tex (line 8)
You can't use `the letter a' after \the. ( \begin{aa} ...)
problem
environment (or command). Also,\newenvironment
takes 3 arguments, not just 2: One for the environment name, one for the\begin
part of the environment and a final one for the\end
part.\newcommand{\newproblemset}[1]{\newenvironment{#1}{}{}} \newproblemset{aa}
gives the same error\aa is defined
. I'm using XeLaTeX.\documentclass
and end with\end{document}
and allow us to copy-and-paste-and-compile and see exactly what you're experiencing. It should be minimal though, only the necessary packages that replicates the behaviour. Can you do that?\aa
is a command already (see the Comprehensive LaTeX Symbol List). It would be different forproblem
, which doesn't exist by default. Do you want to define\newproblemset
to completely ignore whether a command already exists?