[Tex/LaTex] Problem with an environment definition

environmentserrors

I know it is an easy and quite specific request but I've been on it all day and I cannot really understand what's wrong!

\documentclass[12pt,a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage[italian]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amssymb,amsthm,mathtools}
\usepackage{amsmath, textcomp}
\usepackage{titling}

\theoremstyle{definition}
\newtheorem{Gcal}{Grande Caloria \textit{Cal} o \textit{kcal}}[section]
\theoremstyle{definition}
\newtheorem{Pcal}[Gcal]{Piccola Caloria \textit{cal}}
\theoremstyle{definition}
\newtheorem{CalS}[Pcal]{Calore Specifico}

\begin{document}

\chapter{1}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah 
\chapter{2}
\section{2.1}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah 

\begin{itemize}
\itemsep0em
\item[] \begin{Gcal}
    blah blah blah blah blah blah blah blah blah blah blah blah blah blah  
    \end{Gcal}
    \item[] \begin{Pcal}
        blah blah blah blah blah blah blah blah blah blah blah blah blah               
 \end{Pcal}
    \end{itemize}

    blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah 

\begin{CalS}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah  
\end{CalS}

\end{document}

Errors Report

  1. ! LaTeX Error: No counter 'Pcal' defined.
    See the LaTeX manual or LaTeX Companion for explanation.
    Type H for immediate help.

    l.22 \newtheorem{CalS}[Pcal]{Calore Specifico}
    Your command was ignored.

  2. ! LaTeX Error: Environment CalS undefined.
    See the LaTeX manual or LaTeX Companion for explanation.
    Type H for immediate help.

    l.45 \begin{CalS}
    Your command was ignored.
    Type I to replace it with another command,
    or to continue without it.
    ! LaTeX Error: \begin{document} ended by \end{CalS}.
    See the LaTeX manual or LaTeX Companion for explanation.
    Type H for immediate help.

    l.47 \end{CalS}
    Your command was ignored.

  3. ! LaTeX Error: \begin{document} ended by \end{CalS}.
    See the LaTeX manual or LaTeX Companion for explanation.
    Type H for immediate help.

    l.47 \end{CalS}
    Your command was ignored.

Can someone explain what did I do wrong? Why only the third enviroment gives problem even if I've copyed/pasted them all?

Best Answer

When you say

 \newtheorem{abc}{Abc}[section]
 \newtheorem{xyz}[abc]{Xyz}

you're telling LaTeX that the statement environments abc and xyz must share the counter; so no counter xyz is defined.

You could do

\theoremstyle{definition}
\newtheorem{Gcal}{Grande Caloria \textit{Cal} o \textit{kcal}}[section]
\newtheorem{Pcal}[Gcal]{Piccola Caloria \textit{cal}}
\newtheorem{CalS}[Gcal]{Calore Specifico}

Note that one \theoremstyle{definition} declaration suffices.

Actually there's a better way.

\documentclass[12pt,a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage[italian]{babel}
\usepackage[utf8]{inputenc}

\usepackage{amssymb,amsthm,mathtools}
\usepackage{amsmath, textcomp}
\usepackage{titling}

\theoremstyle{definition}
\newtheorem{vardef*}{\vardefname}[section]
\newcommand\vardefname{} % initialize
\newenvironment{vardef}[1]
 {\renewcommand\vardefname{#1}\begin{vardef*}}
 {\end{vardef*}}

\begin{document}

\chapter{1}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah 

\chapter{2}
\section{2.1}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah 

\begin{vardef}{Grande Caloria \textit{Cal} o \textit{kcal}}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah  
\end{vardef}

\begin{vardef}{Piccola Caloria \textit{cal}}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\end{vardef}

blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah 

\begin{vardef}{Calore Specifico}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah  
\end{vardef}

blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah 

\end{document}

You have just a generic environment for definitions and give the title at statement time rather than having a different environment for each in the preamble.

enter image description here

Related Question