\ProvidesExplPackage{stexthm}{2023/03/19}{3.3.0}{Default Typesetting for sTeX Statements}

\RequirePackage{stex}
\RequirePackage{amsthm}
\RequirePackage{thmtools}

\ExplSyntaxOn

\cs_new_protected:Nn \_@@_stex_patch_env:nnn {
  \cs_if_exist:cF {#1}{
    \declaretheorem[#2]{#1}
  }
  \clist_map_inline:nn{#3}{
    \use:c{stexstyle##1}[#1]{
      \tl_if_empty:NTF\thistitle{
        \begin{#1}
      }{
        \begin{#1}[\thistitle]
      }
    }{ \end{#1} }
  }
}

\_@@_stex_patch_env:nnn{theorem}{parent=section}{assertion}
\_@@_stex_patch_env:nnn{observation}{sibling=theorem}{assertion}
\_@@_stex_patch_env:nnn{corollary}{sibling=theorem}{assertion}
\_@@_stex_patch_env:nnn{lemma}{sibling=theorem}{assertion}
\_@@_stex_patch_env:nnn{axiom}{sibling=theorem}{assertion}
\_@@_stex_patch_env:nnn{remark}{sibling=theorem}{assertion,paragraph}

\cs_if_exist:cF {example}{
  \declaretheorem[sibling=theorem,style=definition]{example}
}
\stexstyleexample{
  \tl_if_empty:NTF\thistitle{
    \begin{example}
  }{
    \begin{example}[\thistitle]
  }
}{
    \end{example}
}

\cs_if_exist:cF {definition}{
  \declaretheorem[sibling=theorem,style=definition]{definition}
}
\stexstyledefinition{
  \tl_if_empty:NTF\thistitle{
    \begin{definition}
  }{
    \begin{definition}[\thistitle]
  }
}{
    \end{definition}
}

\ExplSyntaxOff