% This package defines a "\newproof" command similar to "\newtheorem".
% Its arguments are
%     #1  Name of proof environment, eg, "proof".
%     #2  Starting text, eg, Proof.
%     #3  Finishing text, eg, [] flushed right.
%
% The package goes on to define a "proof" environment with exactly the
% above setup, but other unnumbered environments can be set up in the
% same way.
%
% The created environments take one optional argument, which, if present,
% goes in brackets after #2.   Eg,
%
% \begin{proof}
%   A proof.
% \end{proof}
%
% \begin{proof}[B. L. User]
%   A named proof.
% \end{proof}
%
% \begin{proof}[of Theorem \ref{thm}]
%   Yet another.
% \end{proof}
%
% Command "\qed" is set up to flush "\qedtext" right; "\qedtext" defaults
% to a square, but can be re-defined as "QED" or whatever.
%
% Original author: Mike Piff

% https://github.com/LaTeX-Package-Repositories/piff

%
% This file is placed in the public domain.  No provision is made for
% support of the use of the facilities herein.
%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{newproof}[2026-11-03]

\newif\ifDocumentMetadata
\IfDocumentMetadataT{\DocumentMetadatatrue}

\ifDocumentMetadata

%--------------- new code -----------------

\ExplSyntaxOn

\newcommand\newproof[3]{
%
% put the optional argument in the note key
%
  \DeclareDocumentEnvironment{#1}{ ={note}o }
     {
%
% test if \qedtext is defined and if so put it in \qedsymbol
%
       \cs_if_exist:NT \qedtext { \def\qedsymbol{\qedtext} }
       %
% rest is std for proof
%
       \pushQED{#3}
       \ParseLaTeXeTheoremlike {#1} \BooleanTrue {##1}  }
     { \popQED \BlockEnvEnd }
%
% define its blockenv instance
%
   \DeclareInstance{blockenv}{#1}{std}{
     name                 = #1
    ,tag-name             = \UseStructureName{block/proof}
    ,tagging-recipe       = standalone
    ,standalone           = true
    ,transparent-level    = true
    ,block-instance       = proof
    ,inner-instance-type  = captionedtext
    ,inner-instance       = #1
%    ,para-instance        = justify
  }
%
% define its captiontext instance
%
  \DeclareInstance{captionedtext}{#1}{proof}{
    ,title         = #2
    ,order         = {title,separator,note}
    ,caption-decls = \bfseries
    ,note-format   = (##1)        % that's actually also the default
  }
}
\newproof{proof}{Proof}{\qed}     % overwrite our own definition

\ExplSyntaxOff

\else  % old 2e definitions

%--------------- original code -----------------

\newcommand{\newproof}[3]{
   \newenvironment{#1}[1][]%
   {%
      \begin{trivlist}%
         \item[\hspace{\labelsep}\textnormal{\textbf{#2%
            \def\op@@@arg{##1}%
            \ifx\op@@@arg\empty
            \else~(##1)\fi
         }}]%
   }%
   {%
      #3
      \end{trivlist}%
   }%
}
\newproof{proof}{Proof}{\qed}
\def\qed{{\ifhmode\unskip\nobreak\hfil\penalty50 \hskip1em \else\nobreak\fi
   \mbox{}\nobreak\hfil\qedtext%
   \parfillskip=0pt \finalhyphendemerits=0 \par}}

\def\qedtext{\ensuremath{\square}}
\RequirePackage{amsfonts}
\DeclareMathSymbol{\square}       {\mathord}{AMSa}{"03}

\fi
