Latex, "No counter" counterName "defined" error using \ include

I get the following error:

! LaTeX Error: No counter 'exCoutner' defined.

when i try to compile this code:

\documentclass[]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}

\usepackage{amsmath}

\newcounter{exCounter}
\numberwithin{exCounter}{section}
\newenvironment{example}[1]{
    \begin{center}
    \begin{minipage}[t][\height][c]{0.8\textwidth}
    \hrulefill\newline
    \refstepcounter{exCoutner}
    \textit{Example \arabic{exCounter}} - \textbf{#1}\newline
    }{
    \vspace{-0.5\baselineskip}
    \hrulefill
    \end{minipage}
    \end{center}
    \vspace{\baselineskip}
    }

\begin{document}

\include{chapter1}

\include{chapter2}

\include{chapter3}

\end{document}

ChapterX.tex files follow this pattern:

\section{Addition}

\begin{example}{Addition}
$1 + 1 = 2$
\end{example}

When commenting a line

\refstepcounter{exCounter}

everything works fine, but obviously the counter does not increment, and "Example 0" is printed every time I use the "example" environment.

It seems strange to me that commenting out a line does not raise any error, and LaTeX manages to access exCounter (since it prints the value 0), but as soon as I try to increase it (even using \ addtocounter), the error message "no counter defined "

Many thanks!

+4
source share
1

\refstepcounter{exCoutner}

\refstepcounter{exCounter}
+3

All Articles