Debian Codegraph @

texmf-dist/source/latex/csthm/csthm.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2024 by Agni Datta
4 % -----------------------------------
5 %
6 % This file may be distributed and/or modified under the
7 % conditions of the LaTeX Project Public License, either version 1.3c
8 % of this license or (at your option) any later version.
9 % The latest version of this license is in:
10 %
11 % http://www.latex-project.org/lppl.txt
12 %
13 % and version 1.3c or later is part of all distributions of LaTeX
14 % version 2008/05/04 or later.
15 %
16 % \fi
17 %
18 % \iffalse
19 %<*driver>
20 \ProvidesFile{csthm.dtx}
21 %</driver>
22 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
23 %<package>\ProvidesPackage{csthm}[2025/01/16 v1.3 Theorem Environments for Computer Science]
24 %
25 %<*driver>
26 \documentclass{ltxdoc}
27 \usepackage{csthm}
28 \usepackage{parskip}
29 \usepackage{microtype}
30 \usepackage[margin=3cm]{geometry}
31 \usepackage{hyperref}
32 \EnableCrossrefs
33 \CodelineIndex
34 \RecordChanges
35 \begin{document}
36 \DocInput{csthm.dtx}
37 \PrintChanges
38 \PrintIndex
39 \end{document}
40 %</driver>
41 % \fi
42 %
43 % \CheckSum{0}
44 %
45 % \CharacterTable
46 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
47 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
48 % Digits \0\1\2\3\4\5\6\7\8\9
49 % Exclamation \! Double quote \" Hash (number) \#
50 % Dollar \$ Percent \% Ampersand \&
51 % Acute accent \' Left paren \( Right paren \)
52 % Asterisk \* Plus \+ Comma \,
53 % Minus \- Point \. Solidus \/
54 % Colon \: Semicolon \; Less than \<
55 % Equals \= Greater than \> Question mark \?
56 % Commercial at \@ Left bracket \[ Backslash \\
57 % Right bracket \] Circumflex \^ Underscore \_
58 % Grave accent \` Left brace \{ Vertical bar \|
59 % Right brace \} Tilde \~}
60 %
61 % \changes{v1.0}{2024/01/01}{Initial version}
62 % \changes{v1.1}{2024/05/15}{Added cleveref support}
63 % \changes{v1.2}{2024/08/31}{Enhanced theorem styling and QED symbols}
64 % \changes{v1.3}{2025/01/16}{Added major new environments and modified styles}
65 %
66 % \DoNotIndex{\newcommand,\newenvironment}
67 %
68 % \GetFileInfo{csthm.dtx}
69 % \title{The \textsf{csthm} package}
70 % \author{Agni Datta \\ \texttt{[email protected]}}
71 % \date{\filedate}
72 %
73 % \maketitle
74 %
75 % \section{Introduction}
76 %
77 % This package offers a robust and flexible solution for typesetting theorems,
78 % definitions, proofs, and related content typically found in computer science
79 % literature. The package provides a variety of specialized environments, each
80 % with distinct visual markers and formatting styles suited to different types
81 % of content.
82 %
83 % \section{Usage}
84 %
85 % Load the package with:
86 % \begin{verbatim}
87 % \usepackage{csthm}
88 % \end{verbatim}
89 %
90 % To use the package with cleveref support:
91 % \begin{verbatim}
92 % \usepackage[cleveref]{csthm}
93 % \end{verbatim}
94 %
95 % \section{Implementation}
96 %
97 % First, we'll implement the package options and basic setup.
98 %
99 % \begin{macrocode}
100 %<*package>
101 \newif\if@csthm@loadcleveref
102
103 \DeclareOption{cleveref}{\@csthm@loadclevereftrue}
104 \ProcessOptions\relax
105
106 % Load required packages
107 \RequirePackage{amsmath}
108 \RequirePackage{amssymb}
109 \RequirePackage{amsthm}
110 \RequirePackage{enumitem}
111 \RequirePackage{thmtools}
112 \RequirePackage{xcolor}
113
114 % Define accent color
115 \providecommand{\accentcolor}{blue!50!black}
116 \providecommand{\setaccentcolor}[1]{\renewcommand{\accentcolor}{#1}}
117
118 % Common styling elements
119 \providecommand{\commonfont}{\color{\accentcolor}\sffamily}
120 \providecommand{\commonsymb}{\ensuremath{\color{\accentcolor}\lrcorner}}
121
122 % Handle cleveref loading
123 \if@csthm@loadcleveref
124 \AtBeginDocument{%
125 \@ifpackageloaded{hyperref}{%
126 \RequirePackage{cleveref}%
127 }{%
128 \PackageWarning{csthm}{%
129 The 'cleveref' option was set, but 'hyperref' is not loaded.
130 Skipping 'cleveref' loading.%
131 }%
132 }%
133 }%
134 \fi
135 % \end{macrocode}
136 %
137 % Define the basic theorem styles that will be used throughout the package.
138 %
139 % \begin{macrocode}
140 % Standard theorem style
141 \declaretheoremstyle[
142 spaceabove=\topsep,
143 spacebelow=\topsep,
144 headfont=\commonfont\ensuremath{\scriptstyle\blacktriangleright}~,
145 notefont=\commonfont,
146 bodyfont=\normalfont,
147 postheadspace=5pt,
148 numberwithin=section,
149 qed=\commonsymb,
150 headpunct={.}
151 ]{thmstyle}
152
153 % Definition style
154 \declaretheoremstyle[
155 spaceabove=\topsep,
156 spacebelow=\topsep,
157 headfont=\commonfont\ensuremath{\scriptstyle\blacksquare}~,
158 notefont=\commonfont,
159 bodyfont=\normalfont,
160 postheadspace=5pt,
161 numberwithin=section,
162 qed=\commonsymb,
163 headpunct={.}
164 ]{defstyle}
165
166 % Remark style
167 \declaretheoremstyle[
168 spaceabove=\topsep,
169 spacebelow=\topsep,
170 headfont=\commonfont\ensuremath{\scriptstyle\vartriangleright}~,
171 notefont=\commonfont,
172 bodyfont=\normalfont,
173 postheadspace=5pt,
174 numberwithin=section,
175 qed=\commonsymb,
176 headpunct={.}
177 ]{remarkstyle}
178
179 % Highlight style
180 \declaretheoremstyle[
181 spaceabove=\topsep,
182 spacebelow=\topsep,
183 headfont=\commonfont\ensuremath{\scriptstyle\square}~,
184 notefont=\commonfont,
185 bodyfont=\normalfont\sffamily,
186 postheadspace=5pt,
187 numberwithin=section,
188 qed=\commonsymb,
189 headpunct={.}
190 ]{hltstyle}
191
192 % Proof style
193 \declaretheoremstyle[
194 headfont=\commonfont,
195 notefont=\commonfont,
196 bodyfont=\normalfont,
197 postheadspace=5pt,
198 numbered=no,
199 headpunct={.},
200 qed=$\color{\accentcolor}\scriptstyle\blacktriangleleft$
201 ]{proofstyle}
202 % \end{macrocode}
203 %
204 % Now we'll declare all the theorem environments.
205 %
206 % \begin{macrocode}
207 % Mathematical Theorems (Numbered)
208 \declaretheorem[style=thmstyle,name=Theorem]{theorem}
209 \declaretheorem[style=thmstyle,sibling=theorem]{assumption}
210 \declaretheorem[style=thmstyle,sibling=theorem]{axiom}
211 \declaretheorem[style=thmstyle,sibling=theorem]{claim}
212 \declaretheorem[style=thmstyle,sibling=theorem]{conjecture}
213 \declaretheorem[style=thmstyle,sibling=theorem]{corollary}
214 \declaretheorem[style=thmstyle,sibling=theorem]{fact}
215 \declaretheorem[style=thmstyle,sibling=theorem]{hypothesis}
216 \declaretheorem[style=thmstyle,sibling=theorem]{lemma}
217 \declaretheorem[style=thmstyle,sibling=theorem]{property}
218 \declaretheorem[style=thmstyle,sibling=theorem]{proposition}
219
220 % Unnumbered Mathematical Environments
221 \declaretheorem[style=thmstyle,unnumbered,name=Theorem]{theorem*}
222 \declaretheorem[style=thmstyle,unnumbered,name=Assumption]{assumption*}
223 \declaretheorem[style=thmstyle,unnumbered,name=Axiom]{axiom*}
224 \declaretheorem[style=thmstyle,unnumbered,name=Claim]{claim*}
225 \declaretheorem[style=thmstyle,unnumbered,name=Conjecture]{conjecture*}
226 \declaretheorem[style=thmstyle,unnumbered,name=Corollary]{corollary*}
227 \declaretheorem[style=thmstyle,unnumbered,name=Fact]{fact*}
228 \declaretheorem[style=thmstyle,unnumbered,name=Hypothesis]{hypothesis*}
229 \declaretheorem[style=thmstyle,unnumbered,name=Lemma]{lemma*}
230 \declaretheorem[style=thmstyle,unnumbered,name=Property]{property*}
231 \declaretheorem[style=thmstyle,unnumbered,name=Proposition]{proposition*}
232
233 % Definitions and Protocols (Numbered)
234 \declaretheorem[style=defstyle,sibling=theorem]{definition}
235 \declaretheorem[style=defstyle,sibling=theorem]{notation}
236 \declaretheorem[style=defstyle,sibling=theorem]{problem}
237 \declaretheorem[style=defstyle,sibling=theorem]{protocol}
238
239 % Unnumbered Definitions and Protocols
240 \declaretheorem[style=defstyle,unnumbered,name=Definition]{definition*}
241 \declaretheorem[style=defstyle,unnumbered,name=Notation]{notation*}
242 \declaretheorem[style=defstyle,unnumbered,name=Problem]{problem*}
243 \declaretheorem[style=defstyle,unnumbered,name=Protocol]{protocol*}
244
245 % Remarks and Examples (Numbered)
246 \declaretheorem[style=remarkstyle,sibling=theorem]{example}
247 \declaretheorem[style=remarkstyle,sibling=theorem]{note}
248 \declaretheorem[style=remarkstyle,sibling=theorem]{remark}
249
250 % Unnumbered Remarks and Examples
251 \declaretheorem[style=remarkstyle,unnumbered,name=Example]{example*}
252 \declaretheorem[style=remarkstyle,unnumbered,name=Note]{note*}
253 \declaretheorem[style=remarkstyle,unnumbered,name=Remark]{remark*}
254
255 % Highlights and Important Elements (Numbered)
256 \declaretheorem[style=hltstyle,sibling=theorem]{exercise}
257 \declaretheorem[style=hltstyle,sibling=theorem]{highlight}
258 \declaretheorem[style=hltstyle,sibling=theorem]{important}
259 \declaretheorem[style=hltstyle,sibling=theorem]{keypoint}
260
261 % Unnumbered Highlights and Important Elements
262 \declaretheorem[style=hltstyle,unnumbered,name=Exercise]{exercise*}
263 \declaretheorem[style=hltstyle,unnumbered,name=Highlight]{highlight*}
264 \declaretheorem[style=hltstyle,unnumbered,name=Important]{important*}
265 \declaretheorem[style=hltstyle,unnumbered,name=Key Point]{keypoint*}
266 % \end{macrocode}
267 %
268 % Set up the proof environment and case list.
269 %
270 % \begin{macrocode}
271 % Remove and redefine proof environment
272 \let\proof\relax
273 \let\endproof\relax
274 \declaretheorem[style=proofstyle]{proof}
275
276 % Custom case list environment
277 \newlist{caseList}{enumerate}{1}
278 \setlist[caseList]{label=\textbf{Case~\arabic*:}, leftmargin=*}
279
280 \NewDocumentEnvironment{case}{O{}}{%
281 \begin{caseList}[#1]%
282 }{%
283 \end{caseList}%
284 }
285
286 % Redefine QED symbol
287 \renewcommand\qedsymbol{$\scriptstyle\color{\accentcolor}\blacksquare$}
288
289 % Utility commands
290 \providecommand{\csthmpkg}{\textsf{csthm}}
291 \providecommand{\email}[1]{\href{mailto:#1}{\texttt{#1}}}
292 %</package>
293 % \end{macrocode}
294 %
295 % \Finale