\ProvidesExplPackage{stexthm}{2026/06/24}{4.1.0}{Default Typesetting for sTeX Statements}

\RequirePackage{stex}
\RequirePackage{amsthm}

\ExplSyntaxOn

\AddToHook{begindocument}{
   \ExplSyntaxOn\makeatletter
    \input{stexthm-english.ldf}
    \ltx@ifpackageloaded{babel}{
      \clist_set:Ne \l_tmpa_clist {\exp_args:No \tl_to_str:n \bbl@loaded}
      \exp_args:NNe \clist_if_in:NnT \l_tmpa_clist {\detokenize{ngerman}}{
        \input{stexthm-ngerman.ldf}
      }
      \exp_args:NNe \clist_if_in:NnT \l_tmpa_clist {\detokenize{finnish}}{
         \input{stexthm-finnish.ldf}
      }
      \exp_args:NNe \clist_if_in:NnT \l_tmpa_clist {\detokenize{french}}{
         \input{stexthm-french.ldf}
      }
      \exp_args:NNe \clist_if_in:NnT \l_tmpa_clist {\detokenize{russian}}{
         \input{stexthm-russian.ldf}
      }
 }{}
  \makeatother\ExplSyntaxOff
}

\cs_new_protected:Nn \_@@_stex_patch_env:nnnn {
  \AddToHook{begindocument}{
    \cs_if_exist:cF {#1}{
      \theoremstyle{plain}
      \tl_if_empty:nTF{#4}{
        \newtheorem{#1}{#2}[section]
      }{
        \newtheorem{#1}[#4]{#2}
      }
    }
  }
  \clist_map_inline:nn{#3}{
    \use:c{stexstyle##1}[#1]{
      \tl_if_empty:NTF\thistitle{
        \begin{#1}
      }{
        \begin{#1}[\thistitle]
      }
    }{ \end{#1} }
  }
}

\stexstyleexample{
  \tl_if_empty:NTF\thistitle{
    \begin{example}
  }{
    \begin{example}[\thistitle]
  }
}{
    \end{example}
}
\stexstyledefinition{
  \tl_if_empty:NTF\thistitle{
    \begin{definition}
  }{
    \begin{definition}[\thistitle]
  }
}{
    \end{definition}
}

\cs_new:Nn \_stexthm_css:n {
  font-weight:~bold;
  font-size:inherit;
  &::before~{
    content:~"#1"~"~"counter(ftml-section)~"."~counter(ftml-para);
  }
  &::after~{
    content: ".~";
  }
}

\AddToHook{begindocument}{
  \stexcssassertion[theorem,counter=para,parent=section]{
  }{\_stexthm_css:n \stexthm@kw@theorem}
  \stexcssassertion[observation,counter=para,parent=section]{
  }{\_stexthm_css:n \stexthm@kw@observation}
  \stexcssassertion[corollary,counter=para,parent=section]{
  }{\_stexthm_css:n \stexthm@kw@corollary}
  \stexcssassertion[lemma,counter=para,parent=section]{
  }{\_stexthm_css:n \stexthm@kw@lemma}
  \stexcssassertion[axiom,counter=para,parent=section]{
  }{\_stexthm_css:n \stexthm@kw@axiom}
  \stexcssassertion[remark,counter=para,parent=section]{
  }{\_stexthm_css:n \stexthm@kw@remark}
  \stexcssparagraph[remark,counter=para,parent=section]{
  }{\_stexthm_css:n \stexthm@kw@remark}
  \stexcssdefinition[counter=para,parent=section]{
  }{\_stexthm_css:n \stexthm@kw@definition}
  \stexcssexample[counter=para,parent=section]{
  }{\_stexthm_css:n \stexthm@kw@example}
}

\_@@_stex_patch_env:nnnn{theorem}{\stexthm@kw@theorem}{assertion}{}
\_@@_stex_patch_env:nnnn{observation}{\stexthm@kw@observation}{assertion}{theorem}
\_@@_stex_patch_env:nnnn{corollary}{\stexthm@kw@corollary}{assertion}{theorem}
\_@@_stex_patch_env:nnnn{lemma}{\stexthm@kw@lemma}{assertion}{theorem}
\_@@_stex_patch_env:nnnn{axiom}{\stexthm@kw@axiom}{assertion}{theorem}
\_@@_stex_patch_env:nnnn{remark}{\stexthm@kw@remark}{assertion,paragraph}{theorem}
\AddToHook{begindocument}{
  \theoremstyle{definition}
  \cs_if_exist:cF {example}{
    \newtheorem{example}[theorem]{\stexthm@kw@example} % style=definition
  }
  \cs_if_exist:cF {definition}{
    \newtheorem{definition}[theorem]{\stexthm@kw@definition} % style=definition
  }
}

\ExplSyntaxOff
