Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make key sibling more sensible with \declaretheorem{<env list>} #20

Open
muzimuzhi opened this issue Apr 4, 2021 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@muzimuzhi
Copy link
Owner

Use case:

Define multiple theorem environments simultaneously and make them share the same counter. So with

\documentclass{article}
\usepackage{thmtools}

\declaretheorem{theorem, definition} % which (new) option here? to be decided

\begin{document}
\begin{theorem}     content \end{theorem}
\begin{definition}  content \end{definition}
\begin{theorem}     content \end{theorem}
\end{document}

one will get

Theorem 1
Definition 2
Theorem 3

(from user José Gil Férez by email)

Discussions:

Suppose \declaretheorem{theorem, definition}[<key>=theorem] does the work, then the logic is "use key value (theorem) as sibling value, or ignore it if it is the same as the env name to be defined". It seems this logic can be directly added to the existing key sibling, because normally it's non-sense to use \declaretheorem{env}[sibling=env].

Cons: This requires that the sibling value to be the first one in the env list. As a counterexample, \declaretheorem{theorem, definition}[sibling=definition] won't work.

@muzimuzhi muzimuzhi added the enhancement New feature or request label Apr 4, 2021
@muzimuzhi muzimuzhi changed the title Make key sibling more sensible with \declaretheorem{thm, defn} Make key sibling more sensible with \declaretheorem{<env list>} Apr 4, 2021
@muzimuzhi
Copy link
Owner Author

Suppose \declaretheorem{theorem, definition}[<key>=theorem] does the work, then the logic is "use key value (theorem) as sibling value, or ignore it if it is the same as the env name to be defined". It seems this logic can be directly added to the existing key sibling, because normally it's non-sense to use \declaretheorem{env}[sibling=env].

This solely could be implemented as simple as

diff --git a/source/thm-kv.dtx b/source/thm-kv.dtx
index 7859126..dd34ecd 100644
--- a/source/thm-kv.dtx
+++ b/source/thm-kv.dtx
@@ -409,7 +409,9 @@
     \@nx\thmt@newtheorem
     \ifthmt@isnumbered
       {#1}%
-      \ifx\thmt@sibling\@empty\else [\thmt@sibling]\fi
+      \ifx\thmt@sibling\@empty
+      \else\ifx\thmt@sibling\thmt@envname
+      \else [\thmt@sibling]\fi\fi
       {\thmt@thmname}%
       \ifx\thmt@parent\@empty\else [\thmt@parent]\fi
     \else

A continued example:

\documentclass{article}
\usepackage{thmtools}
\usepackage{xpatch}

\makeatletter
\xpatchcmd\declaretheorem@iii
  {\ifx\thmt@sibling\@empty\else [\thmt@sibling]\fi}
  {\ifx\thmt@sibling\@empty
   \else\ifx\thmt@sibling\thmt@envname
   \else [\thmt@sibling]\fi\fi}
  {}{\fail}
\makeatother

\declaretheorem{theorem, definition}[sibling=theorem]

\begin{document}
\begin{theorem}     content \end{theorem}
\begin{definition}  content \end{definition}
\begin{theorem}     content \end{theorem}
\end{document}

This will give the desired output.

But since sibling/numberlike and parent/numberwithin are mutually exclusive, the above patch will NOT resolve José's request: use

\declaretheorem[style=theorem, numberwithin=chapter]
   {theorem, lemma, proposition, corollary}

to define env theorem numbered within chapter, and all the following envs numbered like theorem.

José's proposal, a new boolean option siblings, is closer (to the final decision).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant