\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{dnTheorems}[2026/09/01 Environnements de type theoreme]

%%% Theoremes, definitions, remarques, notations, demonstrations.
%%%
%%% DEPENDANCE A LA LANGUE -- ce module utilise \theoname, \lemmaname,
%%% \definitionname, \indicationname... qui sont definis par
%%% Flanguage.sty ou Elanguage.sty.  L'un des deux doit donc etre
%%% charge AVANT ce fichier.  C'est ce que fait new.sty via son
%%% option [F]/[E] ; le test ci-dessous rend l'exigence explicite
%%% pour qui chargerait dnTheorems seul.

\RequirePackage{dnBase}
\RequirePackage{amsthm}

\@ifundefined{theoname}{%
  \PackageError{dnTheorems}{%
    Aucun fichier de langue n'est charge}{%
    Chargez Flanguage ou Elanguage avant dnTheorems, ou passez par
    \MessageBreak \protect\usepackage[F]{new} / [E].}}{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% espace avant et apres les enonces (\thmsep vient de dnBase)
\makeatletter
\def\thm@space@setup{%
  \thm@preskip=1.1\thmsep plus .5ex minus .2ex
  \thm@postskip=1.1\thmsep plus .5ex minus .1ex
}
\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% type theoreme
\newtheorem{thm}{\theoname}[section]
\newtheorem{lem}[thm]{\lemmaname}
\newtheorem{pro}[thm]{\propositionname}
\newtheorem{cor}[thm]{\corollaryname}
\newtheorem*{thm*}{\theoname}
\newtheorem*{lem*}{\lemmaname}
\newtheorem*{pro*}{\propositionname}
\newtheorem*{cor*}{\corollaryname}

%%% enonce a nom libre : \begin{likethm}{Lemme des segments emboites}
\newcommand{\thistheoremname}{}
\newtheorem{genericthm}[thm]{\thistheoremname}
\newenvironment{likethm}[1]{%
  \renewcommand{\thistheoremname}{#1}\begin{genericthm}%
  }{\end{genericthm}}

\newtheorem*{genericthm*}{\thistheoremname}
\newenvironment{likethm*}[1]{%
  \renewcommand{\thistheoremname}{#1}\begin{genericthm*}%
  }{\end{genericthm*}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% type definition
\theoremstyle{definition}
\newtheorem{definition}[thm]{\definitionname}
\newtheorem{definitions}[thm]{\definitionsname}
\newtheorem{exa}[thm]{\examplename}
\newtheorem{examples}[thm]{\examplesname}
\newtheorem{rem}[thm]{\remarkname}
\newtheorem{remarks}[thm]{\remarksname}
\newtheorem*{definition*}{\definitionname}
\newtheorem*{definitions*}{\definitionsname}
\newtheorem*{exa*}{\examplename}
\newtheorem*{examples*}{\examplesname}
\newtheorem*{rem*}{\remarkname}
\newtheorem*{remarks*}{\remarksname}

%%% type remarque
\theoremstyle{remark}
\newtheorem*{notation}{\notationname}

\theoremstyle{plain}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% indication d'exercice.  La macro est de la mise en forme, donc elle
%%% vit ici ; seul le mot change de langue (\indicationname).
%%% Le ':' produit " :" tout seul sous babel-french et ":" sous british.
\newcommand{\indication}[1]{({\itshape\indicationname:}~#1)}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% fin de demonstration
%%% proof et endproof viennent d'amsthm ; \qed est redefini pour gerer
%%% le cas d'une demonstration s'achevant sur une formule hors texte.
\renewcommand{\qed}{%
  {% set up
    \ifdim\lastskip<.5pt%  % previously, a display
    \par%  % to pass in the vertical mode
    \vspace{-\belowdisplayshortskip}%  % pushing the halmos upward
    \vspace{-1ex}
    \widowpenalty=10000%  % so we dont break the page before \square
    \displaywidowpenalty=10000%  % ditto
    \else%
    \parfillskip=0pt%  % so \par doesnt push \square to left
    \widowpenalty=10000%
    \displaywidowpenalty=10000%
    \finalhyphendemerits=0%  % TeXbook exercise 14.32
    %
    % horizontal
    \leavevmode%  % \nobreak means lines not pages
    \unskip%  % remove previous space or glue
    \nobreak%  % don't break lines
    \hfil%  % ragged right if we spill over
    \penalty20%  % discouragement to do so
    \hskip.75em%  % ensure some space
    \null%  % anchor following \hfill
    \fi%
    \hfill%  % push \square to right
    \raisebox{-.33pt}{$\square$}%  % the end-of-proof mark
    \par%  % build paragraph
  }%
}
