muzimuzhi / thmtools

New home for LaTeX package bundle thmtools
LaTeX Project Public License v1.3c
16 stars 3 forks source link

Option clash: `numbered=no` and `thmbox` #25

Open syvshc opened 2 years ago

syvshc commented 2 years ago

as the question mentioned: https://tex.stackexchange.com/questions/222122/problem-with-thmtools-thmbox-and-numbered-no

muzimuzhi commented 2 years ago

Analysis

\declaretheorem[numbered=no, thmbox=M, name=Theorem]{theo} will eventually call (in \thmt@newtheoremiv)

\newboxtheorem[M]*{theo}{Theorem}

But thmbox's \newboxtheorem doesn't support this starred form, hence raises error.

Discussion

I would like to prevent the error and maybe add proper warning messages, but hesitate to make thmbox={<kv-list>} compatible with numbered=no and probably other options.

Users are suggested to use thmbox={L, headstyle=...} in thmtools, or drop thmtools and use tcolorbox. tcolorbox typesets env contents either in minipage or in \hbox, while normal theorem envs simply typeset env contents in a trivlist. That's the only difference as I can tell.

Misc - thmbox side Although thmbox has options headstyle=<code using #1 and #2> documented, currently you have to manually double the hashes:

\documentclass{article}
\usepackage{thmbox}

\newboxtheorem[L, headstyle={\bfseries\boldmath####1 ####2}]{theo}{Theorem}
% works
\newboxtheorem[L, headstyle={\bfseries\boldmath#1 #2}]{cor}{Corollary}
% raises error
%     ! Illegal parameter number in definition of \thmbox@temp.

\begin{document}
\end{document}

A possible patch to thmbox:

\usepackage{regexpatch}

\makeatletter
% double the hashes in #1
\xpatchcmd\thmbox@newA
  {\def\thmbox@temp##1{#1}}
  {\edef\thmbox@temp##1{\unexpanded{#1}}}
  {}{\PatchFailed}

\xpatchcmd\thmbox@new
  {%
    \expandafter\def\csname#2\endcsname{%
      \setkeys{thmbox}{#1}%
      \@ifnextchar[{\thmbox@beginA{#3}{#4}}{%
        \thmbox@begin{#3}{#4}{}}}%
  }
  {%
    \expandafter\edef\csname#2\endcsname{%
      % expand #1 (\thmbox@temp) by one-step, then double the hashes
      \noexpand\setkeys{thmbox}{\unexpanded\expandafter{#1}}%
      \unexpanded{\@ifnextchar[{\thmbox@beginA{#3}{#4}}{%
        \thmbox@begin{#3}{#4}{}}}}%
  }
  {}{\PatchFailed}
\makeatother
muzimuzhi commented 2 years ago

I've mailed the above issue to thmbox's author.

muzimuzhi commented 2 years ago

Users are suggested to use thmbox={L, headstyle=...} in thmtools, or drop thmtools and use tcolorbox.

Currently, users have to double hashes four times, leading to 16 hashes:

\declaretheorem[thmbox={M, headstyle=\bfseries\boldmath ################1 ################2}, name=Theorem]{theo}

WIth the above thmbox patch, only four hashes are needed. Still some work to do on thmtools' side.

syvshc commented 2 years ago

Thanks, the problem is solved temporarily. Will there be a compatibility of numbered=no and thmbox? Or will there will be a notice of not using numbered when thmbox is used?

muzimuzhi commented 2 years ago

Will there be a compatibility of numbered=no and thmbox? Or will there will be a notice of not using numbered when thmbox is used?

My plan:

Might not been implemented soon.

muzimuzhi commented 2 years ago

WIth the above thmbox patch, only four hashes are needed. Still some work to do on thmtools' side.

% patch \define@key{thmdef}{thmbox}{...}
\xpatchcmd\KV@thmdef@thmbox
  {\def\thmt@theoremdefiner{\newboxtheorem[#1]}}
  {\edef\thmt@theoremdefiner{\unexpanded{\newboxtheorem[#1]}}}
  {}{\PatchFailed}

\xpatchcmd\declaretheorem
  {\@ifnextchar}
  {\thmt@ifnextchar}
  {}{\PatchFailed}

% Compared to \@ifnextchar from kernal, this one uses
%     \edef\...{\unexpanded{...}}
% to prevent the number of hash characters reduced to half
\long\def\thmt@ifnextchar#1#2#3{%
  \let\reserved@d=#1%
  \edef\reserved@a{\unexpanded{#2}}%
  \edef\reserved@b{\unexpanded{#3}}%
  \futurelet\@let@token\@ifnch}
muzimuzhi commented 2 years ago

Side note: \tl_set:Nn is equivalent to \edef#1{\unexpanded{#2}}.