Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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}

The chapterX.tex files follow this pattern:

\section{Addition}

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

When commenting the line

\refstepcounter{exCounter}

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

What seems strange to me is that no error at all is thrown when commenting the line, and LaTeX manage to access exCounter (since it prints the value 0), but as soon as I try to increment it (even using \addtocounter), this "no counter defined" error appears.

Thank you very much!

like image 946
R2B2 Avatar asked Aug 08 '14 19:08

R2B2


1 Answers

Perhaps

\refstepcounter{exCoutner}

should be

\refstepcounter{exCounter}
like image 194
David Gorsline Avatar answered Sep 28 '22 09:09

David Gorsline