1

For LaTeX-submitted articles (e.g. journal papers) I have a very simple Remark environment:

\newcounter{remarkno}%
\renewcommand{\theremarkno}{\arabic{remarkno}}%
\newenvironment{remark}{\small%
   \refstepcounter{remarkno}%
   \noindent\textbf{Remark~\theremarkno}.%
   \par}%
{}%

This definition numbers remarks 1,2,... over the whole article. I would like to extend this to a textbook under preparation so that the Remark labels for Chapter 3, say, are 3.1, 3.2,... Question: assuming amsmath is loaded, would it be enough to change \renewcommand to

\renewcommand{\theremarkno}{\arabic{\numberwithin{remarkno}{chapter}}}

N.B. This change would be needed for 6 more environments, namely exercise, solution, datedremark, myfootnote, chapternotes, comment. So the above replacement, if it works, would be easily replicated. And only standard LaTeX 2.0 would be needed. (My experience is that inserting newer packages often breaks code).

1 Answer 1

1

Make an abstraction.

\documentclass{article} % or book

\makeatletter
\newcommand{\newnumberedenvironment}[3]{%
  \newcounter{#1}%
  \newenvironment{#1}{#2}{#3}%
  \@ifundefined{chapter}{}{\counterwithin{#1}{chapter}}%
}
\makeatother
\newnumberedenvironment{remark}{\small%
   \refstepcounter{remark}%
   \noindent\textbf{Remark~\theremark}.%
   \par}%
{}%
\newnumberedenvironment{solution}{...}{...}
\newnumberedenvironment{datedremark}{...}{...}
\newnumberedenvironment{myfootnote}{...}{...}
\newnumberedenvironment{chapternotes}{...}{...}
\newnumberedenvironment{comment}{...}{...}

\begin{document}

\begin{remark}
Something
\end{remark}

\end{document}

enter image description here

If I change article into book and add \chapter{Test}, I get

enter image description here

It's a bit more complicated if you want to support arguments for the new environments.

\documentclass{book} % or book

\makeatletter
\newcommand{\newnumberedenvironment}[1]{%
  \def\numberedenv@name{#1}%
  \@newnumberedenvironment
}
\newcommand{\@newnumberedenvironment}[3][0]{%
  \newcounter{\numberedenv@name}%
  \newenvironment{\numberedenv@name}[#1]{#2}{#3}%
  \@ifundefined{chapter}{}{%
    \expandafter\counterwithin\expandafter{\numberedenv@name}{chapter}%
  }%
}
\makeatother

\newnumberedenvironment{remark}{\small%
   \refstepcounter{remark}%
   \noindent\textbf{Remark~\theremark}.%
   \par}%
{}%
\newnumberedenvironment{solution}{...}{...}
\newnumberedenvironment{datedremark}{...}{...}
\newnumberedenvironment{myfootnote}{...}{...}
\newnumberedenvironment{chapternotes}{...}{...}
\newnumberedenvironment{comment}{...}{...}

\begin{document}

\chapter{Test}

\begin{remark}
Something
\end{remark}

\end{document}

You must log in to answer this question.

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