0

I am using the following code for an environment similar to Question environment:

\documentclass[12pt,b5paper,twoside]{book}
\usepackage{amsmath,amsthm}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\theoremstyle{splcommon}
\newtheorem{Alemma}{Question}
\renewcommand\theAlemma{\Alph{Alemma}}
\newenvironment{question}[1]{%
    \renewcommand\theAlemma{\thechapter-\Alph{Alemma}}%
    \Alemma
}{\endAlemma}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
    \chapter{title}
    \section{Questions}
    \begin{question}
        this is a question
    \end{question}
\begin{question}
    this is a question
\end{question}
\begin{question}
    this is a question
\end{question}
\begin{question}
    this is a question
\end{question}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    \chapter{title}
\section{Questions}
\begin{question}
    this is a question
\end{question}
\begin{question}
    this is a question
\end{question}
\begin{question}
    this is a question
\end{question}
\begin{question}
    this is a question
\end{question}
\end{document}

enter image description here

But this has three main issues. It produces error when I add a \label{} to it. Second its counter doesn't reset per chapter and it removes the first letter of environment text.

1 Answer 1

3

To get a theorem-like environment numbered within chapters, you need to use the optional argument after the final argument of \newtheorem to specify that you're numbering within chapters:

\newtheorem{Alemma}{Question}[chapter]

Next, to get your desired numbering style (with letters, you should renew the \theAlemma command as:

\renewcommand{\theAlemma}{\thechapter-\Alph{Alemma}}

It's not clear what's going on with the question environment that you've defined. When you specify [1] on the \newenvironment command, you're telling LaTeX that \begin{question} takes a single required argument. It looks ahead and since you didn't specify such an argument, it instead grabs the first letter of the environment which is not what you wanted but is exactly what you told it to do. I'm guessing that the problem you ran into with \label was connected to this—if you put the \label at the beginning of the question environment, then \label would be taken as the argument and discarded and if you had a label name like foo_bar or something else with special characters you would have gotten an error message from that.

If you want questions to have different numbering from Alemmas (which is what appears to be the case), then you should just define question with \newtheorem rather than trying to modify Alemma.

You must log in to answer this question.

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