Just started learning LaTeX, because I'm trying to write a short math book. I started out using LyX, but ultimately I want more control over the typesetting, so I have to learn LaTeX.
Anyway, I want the \newenvironment{Example}
that I defined to update its counter in the same way that \exercise
does.
\exercise
updates the way I want it to when I use \counterwithin{Exercise}{section}
, but it does not work when I use \counterwithin{Example}{section}
. I have no idea what the problem is, any help would be greatly appreciated.
Code that illustrates my problem:
\documentclass{memoir}
\usepackage{exercise,chngcntr}
\begin{document}
%Memoir
\setcounter{secnumdepth}{2}
\chapter{Chapter name}
\section{Section1}
\newcounter{Example}
\counterwithin{Exercise}{section} %Ties exercises counter to memoir section?
\counterwithin{Example}{section} %Use this to tie the example counter to the memoir sections?
\newenvironment{Example}{\begin{Exercise}[name={Example},
counter={Example}]}
{\end{Exercise}}
%Exercises below:
\begin{Exercise}
Exercise text
\end{Exercise}
\begin{Example}
Example text
\end{Example}
\begin{Exercise} %counter is the way I want it to be
Exercise text
\end{Exercise}
\section{Section2}
\begin{Exercise}
Exercise text
\end{Exercise}
\begin{Example}
Example text
\end{Example}
\begin{Example} %Counter does not increment
Example text
\end{Example}
\begin{Exercise}
Exercise text
\end{Exercise}
\end{document}
Edit: For clarification, the problem is in the second section, Section2, where the Example doesn't update: Example 2.1.1 and then Example 2.1.1 again, instead of Example 2.1.1 and then Example 2.1.2.
\counterwithin{Example}{section}
after you define theExample
environment.