[Tex/LaTex] Conflict between ntheorem and amsthm

etoolboxincompatibilityntheorempackagestheorems

I am using etoolbox and ntheorem packages to have a custom numbering of theorems and equations. Everything works but these side errors occur:

  • \qedhere command is unknown (EDIT: following some suggestions I worked something out, so the \qedhere issue is somehow solved)
  • theorems title (the optional argument) is typeset in bold

As a MWE, the following code

\documentclass{book}  
\usepackage{amsmath}  
\usepackage{etoolbox}  
\usepackage[amsmath,amsthm,framed,thmmarks]{ntheorem}  
%  
\renewcommand{\theequation}{\thechapter.\arabic{equation}}  
\setcounter{equation}{0}  
\newcounter{tempcounter}  
\newtheorem{thm}{Theorem}[chapter]  
%  
\BeforeBeginEnvironment{thm}{\setcounter{tempcounter}{\arabic{equation}}}  
\AtBeginEnvironment{thm}  
{\setcounter{thm}{\thetempcounter}\subequations}  
\AtEndEnvironment{thm}{\endsubequations}  
%  
\begin{document}  
\chapter{This is a chapter}  
\begin{equation}\label{Eq:A}  
2+2=4  
\end{equation}  
\begin{thm}[First Theorem]\label{Thm:First}  
\begin{equation}\label{Eq:B}  
1+1=2  
\end{equation}  
\begin{proof}  
If equation \ref{Eq:A} was trivial, equation \ref{Eq:B} in Theorem \ref{Thm:First} is even more \qedhere \\  
trivial.  
\end{proof}  
\end{thm}  
\end{document}

results in this output:

Output of the above MWE

The \qedhere command is unknown and therefore ignored. I think that the problem is a conflict between the amsthm option in ntheorem package and the amsthm package. However, if I add \usepackage{amsthm} in the preamble I get errors like

! LaTeX Error: Command \theoremstyle already defined.

and many more.

I would like either to solve the two problems listed above, or to have an alternative code in order to have:

  • theorems and equations following the same numbering, resetting at each chapter
  • equations in theorem environments subnumbered as shown in the above MWE's output.

Any other suggestion is highly appreciated.

Best Answer

The ntheorem package covers the \qedhere in different ways. Here's an example on which you can elaborate. The "normal font attribution" is easily obtained by (re)defining the theorem style.

\documentclass{book}  
\usepackage{amsmath,amssymb}  
\usepackage{etoolbox}  
\usepackage[amsmath,framed,thmmarks]{ntheorem}  
%  
\numberwithin{equation}{chapter}
\newcommand{\qedhere}{\ifmmode\qed\else\hfill\proofSymbol\fi}

\makeatletter
\renewtheoremstyle{plain}
  {\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]}%
  {\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\ {\normalfont(##3)}\theorem@separator]}
\makeatother
\theoremstyle{plain}

\newtheorem{thm}{Theorem}[chapter]

\theoremstyle{nonumberplain}
\theoremheaderfont{\itshape}
\theorembodyfont{\normalfont}
\theoremsymbol{\ensuremath{\square}}
\newtheorem{proof}{Proof}
\qedsymbol{\ensuremath{\square}}

\newcounter{tempcounter}
\BeforeBeginEnvironment{thm}{\setcounter{tempcounter}{\arabic{equation}}}  
\AtBeginEnvironment{thm}  
{\setcounter{thm}{\thetempcounter}\subequations}  
\AtEndEnvironment{thm}{\endsubequations}  
%  
\begin{document}  
\chapter{This is a chapter}  
\begin{equation}\label{Eq:A}  
2+2=4  
\end{equation}  
\begin{thm}[First Theorem]\label{Thm:First}  
\begin{equation}\label{Eq:B}  
1+1=2  
\end{equation}  
\begin{proof}  
If equation \ref{Eq:A} was trivial, equation \ref{Eq:B} in Theorem \ref{Thm:First} is even more
trivial.
\[ 0+0=0 \qedhere\]
\end{proof}  
\end{thm}  

\begin{thm}[Second Theorem]\label{Thm:Second}  
\begin{equation}\label{Eq:C}  
1+1=2  
\end{equation}  
\begin{proof}  
If equation \ref{Eq:A} was trivial, equation \ref{Eq:C} in Theorem \ref{Thm:Second} is even more
trivial.
\end{proof}  
\end{thm}  

Let's see another proof.
\begin{proof}
\begin{itemize}
\item Fact one
\item Fact two
\item Fact three\qedhere
\end{itemize}
\end{proof}

\begin{proof}
Here the proof ends with an \texttt{align*} environment.
\begin{align*}
0&=0+0\\
1&=0+1\qedhere
\end{align*}
\end{proof}

\end{document}
Related Question