Debian Codegraph @

texmf-dist/doc/latex/create-theorem/create-theorem-doc.tex

raw
1 %! TEX program = xelatex
2 \documentclass[classical]{einfart}
3
4 \usepackage{ProjLib}
5
6 \setmonofont[Scale=.9]{Iosevka}
7
8 %%================================
9 %% For typesetting code
10 %%================================
11 \usepackage{listings}
12 \usepackage{xcolor}
13 \usepackage{setspace}
14 \definecolor{code-main}{RGB}{70,130,180}
15 \definecolor{code-expl3}{RGB}{240,50,60}
16 \definecolor{code-option}{RGB}{40,110,20}
17 \definecolor{code-keys}{RGB}{100,130,150}
18 \definecolor{code-comment}{RGB}{20,120,80}
19 \definecolor{code-background}{gray}{0.99}
20 \lstset{
21 language = [LaTeX]TeX,
22 basicstyle = \ttfamily,
23 keywordstyle = \color{code-main},
24 commentstyle = \color{code-comment},
25 showstringspaces = false,
26 breaklines = true,
27 frame = lines,
28 backgroundcolor = \color{code-background},
29 % flexiblecolumns = true,
30 % columns = fixed,
31 basewidth=.5em,
32 escapeinside = {(*}{*)},
33 alsoletter = {_,:},
34 % numbers = left,
35 % firstnumber = last,
36 numberstyle = \scriptsize\ttfamily,
37 stepnumber = 1,
38 numbersep = 5pt,
39 }
40 \newcommand{\meta}[1]{$\langle${\normalfont\itshape#1}$\rangle$}
41 \lstset{% LaTeX2 commands
42 classoffset = 0,
43 texcsstyle =* \color{code-main},
44 moretexcs =
45 {
46 ExplSyntaxOn,ExplSyntaxOff,
47 NewDocumentCommand,NewDocumentEnvironment,
48 cref,crefname,
49 Cref,Crefname,
50 crefformat,
51 crefthe,crefthename,
52 Crefthe,Crefthename,
53 crefthevariantname,Crefthevariantname,
54 crefthemark,
55 selectlanguage,
56 languagename,
57 theoremstyle,
58 proofname,
59 NameTheorem,
60 NameTheorems,
61 CreateTheorem,
62 SetTheorem,
63 SetTheoremBinding,
64 }
65 }
66 \lstset{% LaTeX3 commands
67 classoffset = 1,
68 texcsstyle =* \color{code-expl3},
69 moretexcs =
70 {
71 tl_new:N,
72 tl_set:Nn,
73 cs_undefine:c,
74 }
75 }
76 \lstnewenvironment{code}{\setstretch{1.05}\LocallyStopLineNumbers}{\ResumeLineNumbers\vspace{-.3\baselineskip}\vspace{-.5\parskip}}
77 \lstnewenvironment{code*}{\setstretch{1.05}\lstset{numbers=left}\LocallyStopLineNumbers}{\ResumeLineNumbers\vspace{-.3\baselineskip}\vspace{-.5\parskip}}
78
79 \newcommand{\packageoption}[1]{\textcolor{code-option}{\texttt{#1}}}
80 \newcommand{\commandoption}[1]{\textcolor{code-keys}{\texttt{#1}}}
81
82 %%================================
83 %% tip
84 %%================================
85 \usepackage[many]{tcolorbox}
86 \newenvironment{tip}[1][Tip]
87 {%
88 \LocallyStopLineNumbers%
89 \begin{tcolorbox}[breakable,
90 enhanced,
91 width = \textwidth,
92 colback = paper, colbacktitle = paper,
93 colframe = gray!50, boxrule=0.2mm,
94 coltitle = black,
95 fonttitle = \sffamily,
96 attach boxed title to top left = {yshift=-\tcboxedtitleheight/2, xshift=.5cm},
97 boxed title style = {boxrule=0pt, colframe=paper},
98 before skip = 3mm,
99 after skip = 3mm,
100 top = 2.5mm,
101 bottom = 1.5mm,
102 title={\scshape\sffamily #1}]%
103 }
104 {%
105 \end{tcolorbox}%
106 \ResumeLineNumbers%
107 }
108
109
110 \newcommand{\createtheorempackage}{\textsf{create-theorem}}
111
112 \begin{document}
113
114 \def\PackageVersion{2025/10/21}
115 \def\PackageSubVersion{}
116
117 \title{\createtheorempackage{}\\\smallskip\itshape Initializing and configuring theorem-like environments, with multilingual support}
118 \author{Jinwen XU}
119 \thanks{Corresponding to: \texttt{\createtheorempackage{} \PackageVersion\PackageSubVersion}}
120 \date{\TheDate{\PackageVersion}[only-year-month], in Melbourne}
121
122 \maketitle
123
124 \begin{abstract}
125 \raggedleft
126 The package \createtheorempackage{} provides commands for naming, initializing and configuring theorem-like environments. All of these commands have key-value based interface and \\are especially useful in multi-language documents, allowing the easy declaration of \\theorem-like environments that can automatically adapt to the language settings.
127 \end{abstract}
128
129 \vspace{-.5\baselineskip}
130
131 % \section*{Before everything}
132
133 % Make sure that the package \textsf{crefthe} is correctly installed. If you are using TeX Live 2022 or newer, or the newest version of MikTeX, then nothing needs to be worried.
134
135 \section{How to load it}
136
137 First, you need a \textbf{backend} to provide the command \lstinline|\newtheorem| with its usual behaviour, such as \textcolor{red}{\textsf{amsthm}} or \textcolor{red}{\textsf{ntheorem}}. After that, you can simply load the current package with:
138
139 \begin{code}
140 \usepackage[(*\meta{options}*)]{create-theorem}
141 \end{code}
142
143 \begin{tip}[Attention]
144 Since \createtheorempackage{} uses \textsf{cleveref} internally, it should usually be placed \textcolor{red}{near the end of preamble} --- notably, it must be loaded \textcolor{red}{after} the packages \textsf{varioref} and \textsf{hyperref}.
145 \end{tip}
146
147 \medskip
148 It has the following options:
149 \begin{itemize}[label=,leftmargin=1.25em,itemindent=-1.25em]
150 % \item \packageoption{draft} or \packageoption{fast}
151 % \begin{itemize}
152 % \item Fast mode. The functionality will be appropriately reduced to get faster compilation speed, recommended to use during the writing stage.
153 % \end{itemize}
154 \item \packageoption{name as context}
155 \begin{itemize}
156 \item When referencing, the resulted names shall correspond to the current context of your text. For example, the names shall be displayed in English when you are referencing a theorem-like environment in an English context, no matter in which linguistic context the target environment appeared.
157 \item This is the default behavior.
158 \item Synonymous names: \packageoption{name-as-context} \,$|$\, \packageoption{nameascontext} \,$|$\, \packageoption{regionalref}
159 \end{itemize}
160 \item \packageoption{name as is}
161 \begin{itemize}
162 \item When referencing, the resulted names shall correspond to the contexts in which the target environments appeared. For example, if the target environment is written in an English context, then its name shall always be displayed in English when referencing, regardless of the current linguistic context.
163 \item Synonymous names: \packageoption{name-as-is} \,$|$\, \packageoption{nameasis} \,$|$\, \packageoption{originalref}
164 \end{itemize}
165 \item \packageoption{name in link}
166 \begin{itemize}
167 \item Include the names in the hyperlinks when referencing.
168 \item Synonymous names: \packageoption{name-in-link} \,$|$\, \packageoption{nameinlink}
169 \end{itemize}
170 \item \packageoption{no preset names}
171 \begin{itemize}
172 \item Disable the preset names. Use this option if you want to define you own name set.
173 \item Synonymous names: \packageoption{no-preset-names} \,$|$\, \packageoption{nopresetnames}
174 \end{itemize}
175 \end{itemize}
176
177 \clearpage
178
179 \section{How to use it}
180
181 \subsection[Naming theorem-like environments]{Naming theorem-like environments with \texttt{\textcolor{code-main}{\textbackslash NameTheorem}}}
182
183 The syntax of \lstinline|\NameTheorem| is as follows:
184 \begin{code}
185 \NameTheorem{(*\meta{name of environment}*)}{(*\meta{key-value configuration}*)}
186 \end{code}
187
188 Supported keys are:
189 \vspace{-.2\baselineskip}
190 \begin{itemize}[label=,leftmargin=1.25em,itemindent=-1.25em]
191 \item \commandoption{heading}\lstinline| = |\meta{configuration}
192 \begin{itemize}
193 \item The heading of the environment, where \meta{configuration} can be:
194 \begin{itemize}
195 \item a single string in monolingual documents: \commandoption{heading}\lstinline| = |\meta{string};
196 \item a key-value name list in multilingual documents:
197 \begin{code}
198 (*\commandoption{heading}*) = {
199 (*\meta{language name}*) = (*\meta{string}*)
200 }
201 \end{code}
202 \end{itemize}
203 \end{itemize}
204 \item \commandoption{heading style}\lstinline| = |\meta{style}
205 \begin{itemize}
206 \item The style of the heading, you can specify the font, text style, color, etc.
207 \item Synonymous names: \commandoption{heading-style} \,$|$\, \commandoption{headingstyle}
208 \end{itemize}
209 \item \commandoption{crefname}\lstinline| = |\meta{configuration}
210 \begin{itemize}
211 \item The name for \lstinline|\cref| the environment, where \meta{configuration} can be:
212 \begin{itemize}
213 \item a single string in monolingual documents: \commandoption{crefname}\lstinline| = {name}{names}|;
214 \item a key-value name list in multilingual documents:
215 \begin{code}
216 (*\commandoption{crefname}*) = {
217 (*\meta{language name}*) = {(*\meta{singular name}*)}{(*\meta{plural name}*)}
218 }
219 \end{code}
220 \end{itemize}
221 \item Also supports the syntax of \lstinline|\crefthename|, thus you can assign names of the form:
222 \begin{code}
223 [(*\meta{singular definite article}*)]{(*\meta{singular name}*)}[(*\meta{plural definite article}*)]{(*\meta{plural name}*)}
224 \end{code}
225 This would be useful for languages like French, Italian, Spanish, etc.
226 \item Also supports the syntax of \lstinline|\crefthevariantname|, thus you can assign different set of names for different variants/declensions (the first line in the configuration is the default name set, which is used in case no variants is specified when referencing):
227 \begin{code}
228 (*\commandoption{crefname}*) = {
229 (*\meta{language name}*) = { [...]{...}[...]{...}
230 , (*\meta{variant 1}*) = [...]{...}[...]{...}
231 , (*\meta{variant 2}*) = [...]{...}[...]{...}
232 ...
233 }
234 }
235 \end{code}
236 This would be useful for languages like German, Russian, etc.
237 \end{itemize}
238 \item \commandoption{crefname style}\lstinline| = |\meta{style}
239 \begin{itemize}
240 \item The style of \textquote{crefname} when referencing, you may specify the font, text style, color, etc.
241 \item Synonymous names: \commandoption{crefname-style} \,$|$\, \commandoption{crefnamestyle}
242 \end{itemize}
243 \item \commandoption{Crefname}\lstinline| = |\meta{configuration}
244 \begin{itemize}
245 \item The name for \lstinline|\Cref| the environment, its syntax is the same as that of \commandoption{crefname}.
246 \item Also supports the syntax of \lstinline|\Crefthename| and \lstinline|\Crefthevariantname|.
247 \end{itemize}
248 \item \commandoption{Crefname style}\lstinline| = |\meta{style}
249 \begin{itemize}
250 \item The style of \textquote{Crefname} when referencing, you may specify the font, text style, color, etc.
251 \item Synonymous names: \commandoption{Crefname-style} \,$|$\, \commandoption{Crefnamestyle}
252 \end{itemize}
253 \item \commandoption{numbering style}\lstinline| = |\meta{style}
254 \begin{itemize}
255 \item The style of numbering in the reference, you can specify the font, text style, color, etc.
256 \item Synonymous names: \commandoption{numbering-style} \,$|$\, \commandoption{numberingstyle}
257 \end{itemize}
258 \item \commandoption{use name}\lstinline| = |\meta{list of existed environment(s) separated with semicolon \textquote{ ; }}
259 \begin{itemize}
260 \item Use the name(s) and style(s) of the given environment(s). If there are multiple ones specified, the result would be a string combining the names, separated with \textquote{\texttt{-}}.
261 \item The definite articles (if exist) are chosen to be that of the last given environment.
262 \item Synonymous names: \commandoption{combined} \,$|$\, \commandoption{use-name} \,$|$\, \commandoption{usename}
263 \end{itemize}
264 \end{itemize}
265
266 \vspace{-.3\baselineskip}
267 \begin{tip}
268 You can also define the names within \lstinline|\CreateTheorem| while initializing the theorem-like environments. \lstinline|\NameTheorem| is especially useful for package or class authors who wish to preset suitable names (with styles) in their packages or classes.
269 \end{tip}
270
271
272 \subsection[Initializing theorem-like environments]{Initializing theorem-like environments with \texttt{\textcolor{code-main}{\textbackslash CreateTheorem}}}
273
274 The syntax of \lstinline|\CreateTheorem| is as follows:
275 \begin{code}
276 \CreateTheorem{(*\meta{list of the name of environments}*)}{(*\meta{key-value configuration}*)}
277 \end{code}
278
279 \begin{tip}[Attention]
280 When the \meta{key-value configuration} is empty, don't forget to include the second pair of curly brackets, for example, \lstinline|\CreateTheorem{theorem}{}|.
281 \end{tip}
282
283 Supported keys are:
284 \vspace{-.2\baselineskip}
285 \begin{itemize}[label=,leftmargin=1.25em,itemindent=-1.25em]
286 \item \commandoption{name}\lstinline| = |\meta{configuration} \quad or \quad \commandoption{name style}\lstinline| = |\meta{configuration}
287 \begin{itemize}
288 \item Setting the names. Same as \lstinline|\NameTheorem{|\meta{name of environment}\lstinline|}{|\meta{configuration}\lstinline|}|.
289 \item Synonymous names: \commandoption{name-style} \,$|$\, \commandoption{namestyle}
290 \end{itemize}
291 \item \commandoption{use name}\lstinline| = |\meta{list of existed environment(s) separated with semicolon \textquote{ ; }}
292 \begin{itemize}
293 \item Using existed name(s). Same as in \lstinline|\NameTheorem|.
294 \item Synonymous names: \commandoption{combined} \,$|$\, \commandoption{use-name} \,$|$\, \commandoption{usename}
295 \end{itemize}
296 \item \commandoption{style}\lstinline| = |\meta{theorem style}
297 \begin{itemize}
298 \item Specifying the \lstinline|\theoremstyle| for the current environment.
299 \item Synonymous names: \commandoption{apply style} \,$|$\, \commandoption{apply-style} \,$|$\, \commandoption{applystyle}
300 \end{itemize}
301 \item \commandoption{qed} or \commandoption{qed}\lstinline| = |\meta{Q.E.D. symbol}
302 \begin{itemize}
303 \item Specifying the Q.E.D. symbol for the current environment.
304 \item Note that the Q.E.D. symbol has already been put in math mode. If you want regular text such as \textquote{Q.E.D.}, you need to write \commandoption{qed}\lstinline| = \mathrm{Q.E.D.}|.
305 \item If you are using \textsf{ntheorem} as the backend, then you need to load it with option \packageoption{thmmarks}.
306 \item Synonymous names: \commandoption{qed symbol} \,$|$\, \commandoption{qed-symbol} \,$|$\, \commandoption{qedsymbol}
307 \end{itemize}
308 \pagebreak
309 \item \commandoption{parent counter}\lstinline| = |\meta{parent counter}
310 \begin{itemize}
311 \item Specifying the \meta{parent counter} for the current environment, \emph{i.e.}, numbering will restart whenever that sectional level is encountered.
312 \item Synonymous names: \commandoption{parent-counter} \,$|$\, \commandoption{parentcounter} \,$|$\, \\\phantom{Synonymous names: }\commandoption{number within} \,$|$\, \commandoption{number-within} \,$|$\, \commandoption{numberwithin}
313 \end{itemize}
314 \item \commandoption{shared counter}\lstinline| = |\meta{shared counter}
315 \begin{itemize}
316 \item Specifying the \meta{shared counter} for the current environment, \emph{i.e.}, numbering will progress sequentially for all theorem-like environments using this counter.
317 \item Synonymous names: \commandoption{shared-counter} \,$|$\, \commandoption{sharedcounter} \,$|$\, \\\phantom{Synonymous names: }\commandoption{number like} \,$|$\, \commandoption{number-like} \,$|$\, \commandoption{numberlike}
318 \end{itemize}
319 \item \commandoption{numberless}
320 \begin{itemize}
321 \item Defining the current environment to be unnumbered.
322 \end{itemize}
323 \item \commandoption{create starred version}
324 \begin{itemize}
325 \item Defining a corresponding starred (unnumbered) version of the current environment.
326 \item It must be placed \emph{before} \commandoption{qed} if you want the starred version to have a Q.E.D symbol.
327 \item Synonymous names: \commandoption{create-starred-version} \,$|$\, \commandoption{createstarredversion} \,$|$\, \\\phantom{Synonymous names: }\commandoption{create numberless version} \,$|$\, \commandoption{create-numberless-version}~\,$|$\\\phantom{Synonymous names: }\commandoption{createnumberlessversion}
328 \end{itemize}
329 \item \commandoption{copy existed}\lstinline| = |\meta{existed environment}
330 \begin{itemize}
331 \item Defining the current environment to be the same as \meta{existed environment}.
332 \item This key is usually useful in the following two situations:
333 \begin{enumerate}
334 \item To use a more concise name. For example, with \lstinline|\CreateTheorem{thm}{|\commandoption{copy \\existed} \lstinline|= theorem}|, one can then use the name \texttt{thm} to write theorems.
335 \item To remove the numbering of some environments. For example, one can remove the numbering of the \texttt{remark} environment with \lstinline|\CreateTheorem{remark}{|\commandoption{copy existed} \lstinline|= remark*}|.
336 \end{enumerate}
337 \item Synonymous names: \commandoption{copy-existed} \,$|$\, \commandoption{copyexisted}
338 \end{itemize}
339 \end{itemize}
340
341 \begin{tip}
342 The names for the following environments (and their plural forms) have been preset: \texttt{application}, \texttt{assertion}, \texttt{assumption}, \texttt{axiom}, \texttt{claim}, \texttt{commentary}, \texttt{conclusion}, \texttt{conjecture}, \texttt{construction}, \texttt{convention}, \texttt{corollary}, \texttt{definition}, \texttt{example}, \texttt{exercise}, \texttt{fact}, \texttt{hypothesis}, \texttt{lemma}, \texttt{motivation}, \texttt{notation}, \texttt{observation}, \texttt{postulate}, \texttt{problem}, \texttt{property}, \texttt{proposition}, \texttt{question}, \texttt{recall}, \texttt{remark} and \texttt{theorem}. If you are fine with the preset names, then there is no need to specify the key \textquote{\commandoption{name}} while creating them, otherwise you shall have to use the package option \textquote{\packageoption{no preset names}} to disable the presets and then define your own ones.
343 \end{tip}
344
345 \medskip
346
347 Please note that, for the sake of generality, the environment \meta{env} and its starred relative \meta{env}\texttt{*} do \emph{not} share the same set of names when they are separately defined. However, with proper usage of \commandoption{create starred version} and \commandoption{copy existed}, you should already be able to produce all of the following combinations that shares the same set of names: 1$)$ numbered \meta{env}, numbered \meta{env}\texttt{*} ; 2$)$ numbered \meta{env}, unnumbered \meta{env}\texttt{*} ; 3$)$ unnumbered \meta{env}, numbered \meta{env}\texttt{*} ; and 4$)$ unnumbered \meta{env}, unnumbered \meta{env}\texttt{*}. I left it as an easy exercise for you ;-)
348 The answer can be found in section \labelcref{subsec:numbering}.
349
350 \medskip
351 \subsection[Configuring theorem-like environments]{Configuring theorem-like environments with \texttt{\textcolor{code-main}{\textbackslash SetTheorem}}}
352
353 The previous two commands are especially useful for package or class writers, while this one is more for the users. If you are not satisfied with preset name styles or numbering settings, then even after initializing the environments, you can still further configure them by means of \lstinline|\SetTheorem|, the syntax of which is as follows:
354
355 \begin{code}
356 \SetTheorem{(*\meta{list of the name of environments}*)}{(*\meta{key-value configuration}*)}
357 \end{code}
358
359 % \begin{tip}
360 % \lstinline|\SetTheorem| should only be used in the preamble of your document.
361 % \end{tip}
362
363 Supported keys are:
364 \vspace{-.2\baselineskip}
365 \begin{itemize}[label=,leftmargin=1.25em,itemindent=-1.25em]
366 \item \commandoption{name}\lstinline| = |\meta{configuration} and \commandoption{name style}\lstinline| = |\meta{configuration}
367 \begin{itemize}
368 \item Same as \lstinline|\NameTheorem{|\meta{name of environment}\lstinline|}{|\meta{configuration}\lstinline|}|.
369 \item Note that this configuration can overwrite those already specified in \lstinline|\NameTheorem|.
370 \item Synonymous names: \commandoption{name-style} \,$|$\, \commandoption{namestyle}
371 \end{itemize}
372 \item \commandoption{qed}\lstinline| = |\meta{Q.E.D. symbol}
373 \begin{itemize}
374 \item Specifying the Q.E.D. symbol for the current environment.
375 \item Note that this configuration only works if you have already enabled the Q.E.D. symbol during the creating phase of the corresponding environment.
376 \item Synonymous names: \commandoption{qed symbol} \,$|$\, \commandoption{qed-symbol} \,$|$\, \commandoption{qedsymbol}
377 \end{itemize}
378 \item \commandoption{parent counter}\lstinline| = |\meta{parent counter}
379 \begin{itemize}
380 \item Specifying the \meta{parent counter} for the current environment, \emph{i.e.}, numbering will restart whenever that sectional level is encountered.
381 \item Note that this configuration can overwrite those already specified in \lstinline|\CreateTheorem|.
382 \item Synonymous names: \commandoption{parent-counter} \,$|$\, \commandoption{parentcounter} \,$|$\, \\\phantom{Synonymous names: }\commandoption{number within} \,$|$\, \commandoption{number-within} \,$|$\, \commandoption{numberwithin}
383 \end{itemize}
384 \item \commandoption{shared counter}\lstinline| = |\meta{shared counter}
385 \begin{itemize}
386 \item Specifying the \meta{shared counter} for the current environment, \emph{i.e.}, numbering will progress sequentially for all theorem-like environments using this counter.
387 \item Note that this configuration can overwrite those already specified in \lstinline|\CreateTheorem|.
388 \item Synonymous names: \commandoption{shared-counter} \,$|$\, \commandoption{sharedcounter} \,$|$\, \\\phantom{Synonymous names: }\commandoption{number like} \,$|$\, \commandoption{number-like} \,$|$\, \commandoption{numberlike}
389 \end{itemize}
390 \end{itemize}
391
392 \medskip
393 In some cases, you may define an internal environment (for example, a generic version) first and then use it to define the final environment. You may wish to hide the internal names from the users so that they can use \lstinline|\SetTheorem| with the name of the final environments. This can be done with the following command:
394 \begin{code}
395 \SetTheoremBinding{(*\meta{list of the name of environments}*)}{(*\meta{the environment to bind with}*)}
396 \end{code}
397
398
399 \medskip
400 \subsection[Setting the names in external language configuration files]{Setting the names in external language configuration files with \texttt{\textcolor{code-main}{\textbackslash NameTheorems}}}
401
402 The command \lstinline|\NameTheorem| introduced earlier is for defining the names of a given environment for each language, which is more natural to use within a real-life document. However, for package/class authors wishing to maintain their language configuration files, it would be more convenient to use the following \lstinline|\NameTheorems|, which assigns the names for a given language all at once, made it possible to preset the names inside external files.
403
404 \enlargethispage*{\baselineskip}
405 The syntax of \lstinline|\NameTheorems| is as follows (please note that the \meta{language name} here should be consistent with \lstinline|\languagename|):
406 \begin{code}
407 \NameTheorems{(*\meta{language name}*)}{(*\meta{key-value configuration}*)}
408 \end{code}
409
410 Supported keys are (notice that you \emph{cannot} set the styles via \lstinline|\NameTheorems|):
411 \vspace{-.2\baselineskip}
412 \begin{itemize}[label=,leftmargin=1.25em,itemindent=-1.25em]
413 \item \commandoption{heading}\lstinline| = |\meta{configuration}
414 \begin{itemize}
415 \item The headings of the environments, where \meta{configuration} is a key-value name list:
416 \begin{code}
417 (*\commandoption{heading}*) = {
418 (*\meta{name of environment}*) = (*\meta{string}*)
419 }
420 \end{code}
421 \end{itemize}
422 \item \commandoption{crefname}\lstinline| = |\meta{configuration}
423 \begin{itemize}
424 \item The names for \lstinline|\cref| the environments, where \meta{configuration} is a key-value name list:
425 \begin{code}
426 (*\commandoption{crefname}*) = {
427 (*\meta{name of environment}*) = {(*\meta{singular name}*)}{(*\meta{plural name}*)}
428 }
429 \end{code}
430 \item Also supports the syntax of \lstinline|\crefthename| and \lstinline|\crefthevariantname|.\\
431 Please refer to the description of \lstinline|\NameTheorem| for more details.
432 \end{itemize}
433 \item \commandoption{Crefname}\lstinline| = |\meta{configuration}
434 \begin{itemize}
435 \item The names for \lstinline|\Cref| the environments, its syntax is the same as that of \commandoption{crefname}.
436 \item Also supports the syntax of \lstinline|\Crefthename| and \lstinline|\Crefthevariantname|.\\
437 Please refer to the description of \lstinline|\NameTheorem| for more details.
438 \end{itemize}
439 \end{itemize}
440
441
442 \bigskip
443 \begin{center}
444 \itshape
445 If you're feeling confused, don't worry. Let's now take a look at some examples.
446 \end{center}
447
448
449 \section{Examples}
450
451 \subsection{The environment {\normalfont\texttt{idea}}}
452
453 First, let's getting familiar with these two commands by creating the environment {\normalfont\texttt{idea}}.
454
455 \begin{code}
456 \NameTheorem{idea}
457 {
458 (*\commandoption{heading}*) = Idea,
459 (*\commandoption{crefname}*) = {idea}{ideas},
460 (*\commandoption{Crefname}*) = {Idea}{Ideas},
461 }
462 \CreateTheorem{idea}{ (*\commandoption{parent counter}*) = section }
463 \end{code}
464
465 or to do it in one turn:
466
467 \begin{code}
468 \CreateTheorem{idea}
469 {
470 (*\commandoption{name}*) = {
471 (*\commandoption{heading}*) = Idea,
472 (*\commandoption{crefname}*) = {idea}{ideas},
473 (*\commandoption{Crefname}*) = {Idea}{Ideas},
474 },
475 (*\commandoption{parent counter}*) = section,
476 }
477 \end{code}
478
479 \smallskip
480 This is not exciting at all. Now, let's say we are writing a trilingual note in English, French and German. (I shall omit the \lstinline|\NameTheorem| version and do it all at once in \lstinline|\CreateTheorem|.)
481
482 \begin{code}
483 \CreateTheorem{idea}
484 {
485 (*\commandoption{name}*) = {
486 (*\commandoption{heading}*) = { english = Idea,
487 french = Idée,
488 ngerman = Idee, },
489 (*\commandoption{crefname}*) = { english = {idea}{ideas},
490 french = [l']{idée}[les]{idées},
491 ngerman = { {Idee}{Idee}
492 , Nominativ = [die]{Idee}[die]{Ideen}
493 , Genitiv = [der]{Idee}[der]{Ideen}
494 , Dativ = [der]{Idee}[den]{Ideen}
495 , Akkusativ = [die]{Idee}[die]{Ideen}
496 } },
497 (*\commandoption{Crefname}*) = { english = {Idea}{Ideas},
498 french = [L']{idée}[Les]{idées},
499 ngerman = { {Idee}{Idee}
500 , Nominativ = [Die]{Idee}[Die]{Ideen}
501 , Genitiv = [Der]{Idee}[Der]{Ideen}
502 , Dativ = [Der]{Idee}[Den]{Ideen}
503 , Akkusativ = [Die]{Idee}[Die]{Ideen}
504 } },
505 },
506 (*\commandoption{parent counter}*) = section,
507 }
508 \end{code}
509
510 With this, if you use \lstinline|\selectlanguage{french}|, the {\normalfont\texttt{idea}} environment shall be automatically displayed as \textquote{Idée}. And if you \lstinline|\crefthe| it, the definite article and the name would show up properly just as expected.
511
512 The same happens for German with \lstinline|\selectlanguage{ngerman}|, and when referencing an {\normalfont\texttt{idea}} environment, you may specify the declension as \lstinline|\crefthe[|\meta{prep}\lstinline|,declension=Nominativ]|\lstinline|{|\meta{label}\lstinline|}|, or more simply, with a shortcut such as \lstinline|\crefthe[|\meta{prep}\lstinline|,nom.]{|\meta{label}\lstinline|}|.
513
514 \begin{tip}
515 For more datailed usage of the referencing command \lstinline|\crefthe|, please refer to the documentation of the package \textsf{crefthe}.
516 \end{tip}
517
518 \bigskip
519 Next we shall deal with the problem of numbering. Let's continue to use this environment {\normalfont\texttt{idea}} for demonstration --- suppose that we have already set the names with \lstinline|\NameTheorem|.
520
521
522 \medskip
523 \subsection{Let's play with numbering}
524 \label{subsec:numbering}
525
526 Remember the exercise I left you in the previous section? Let's do it together now.
527
528 \subsubsection{Numbered {\normalfont\texttt{idea}} and numbered {\normalfont\texttt{idea*}}}
529
530 This is easy, \commandoption{copy existed} suffices:
531
532 \begin{code}
533 \CreateTheorem{idea}{(*\commandoption{parent counter}*) = section}
534 \CreateTheorem{idea*}{(*\commandoption{copy existed}*) = idea}
535 \end{code}
536
537 \subsubsection{Numbered {\normalfont\texttt{idea}} and unnumbered {\normalfont\texttt{idea*}}}
538
539 This is the most common situation, \commandoption{create starred version} will do.
540
541 \begin{code}
542 \CreateTheorem{idea}
543 {
544 (*\commandoption{parent counter}*) = section,
545 (*\commandoption{create starred version}*),
546 }
547 \end{code}
548
549 \begin{tip}[Attention]
550 Please note that you cannot use \lstinline|\CreateTheorem{idea*}{|\commandoption{numberless}\lstinline|}| here, since we don't have the names defined for {\normalfont\texttt{idea*}}.
551 \end{tip}
552
553 \subsubsection{Unnumbered {\normalfont\texttt{idea}} and numbered {\normalfont\texttt{idea*}}}
554
555 This is a bit tricky: by default we can only create numbered {\normalfont\texttt{idea}} or unnumbered {\normalfont\texttt{idea*}}, and the question is how to switch them. We shall need an intermediary for this purpose.
556
557 \begin{code}
558 \CreateTheorem{idea}{(*\commandoption{create starred version}*)}
559 \CreateTheorem{idea-temp}{(*\commandoption{copy existed}*) = idea*}
560 \CreateTheorem{idea*}{(*\commandoption{copy existed}*) = idea}
561 \CreateTheorem{idea}{(*\commandoption{copy existed}*) = idea-temp}
562 \end{code}
563
564 \subsubsection{Unnumbered {\normalfont\texttt{idea}} and unnumbered {\normalfont\texttt{idea*}}}
565
566 This is essentially the combination of the first two cases --- we need to create {\normalfont\texttt{idea*}} first and then copy it to {\normalfont\texttt{idea}}:
567
568 \begin{code}
569 \CreateTheorem{idea}{(*\commandoption{create starred version}*)}
570 \CreateTheorem{idea}{(*\commandoption{copy existed}*) = idea*}
571 \end{code}
572
573 \medskip
574 In each case, the two environments {\normalfont\texttt{idea}} and {\normalfont\texttt{idea*}} share the same set of names.
575
576 \begin{tip}[Attention]
577 The sole purpose of this section is to demonstrate the feature of this package --- some combinations are not recommended to use in the actual documents.
578 \end{tip}
579
580
581 \subsection{The \emph{proofless} version --- theorems with a Q.E.D. symbol}
582
583 Sometimes you may encounter a theorem without a proof, in which case you might want a Q.E.D. symbol when the theorem is finished. This can be easily achieved via:
584
585 \begin{code}
586 \CreateTheorem { theorem } { (*\commandoption{create starred version}*) }
587 \CreateTheorem { theorem+ } { (*\commandoption{copy existed}*) = theorem, (*\commandoption{qed}*) }
588 \CreateTheorem { theorem+* } { (*\commandoption{copy existed}*) = theorem*, (*\commandoption{qed}*) }
589 \end{code}
590
591 The code above defines two new environments \lstinline|theorem+| and \lstinline|theorem+*| in addition to \lstinline|theorem| and \lstinline|theorem*|. The \lstinline|+| version behaves exactly the same as the usual version, except that it has a Q.E.D. symbol.
592
593 \subsection{Redefine the {\normalfont\texttt{proof}} environment}
594
595 If you wish to have a {\normalfont\texttt{proof}} environment with a custom theorem style, or to have a numbered version {\normalfont\texttt{proof*}} of it, the following code could be helpful:
596
597 \begin{code}
598 \ExplSyntaxOn
599
600 \newcounter { proof }
601 \tl_new:N \l_mymodule_name_of_proof_tl
602 \CreateTheorem { proof_inner }
603 {
604 (*\commandoption{name}*) = { (*\commandoption{heading}*) = { \l_mymodule_name_of_proof_tl } },
605 (*\commandoption{create-starred-version}*),
606 (*\commandoption{style}*) = remark,
607 (*\commandoption{qed}*),
608 (*\commandoption{shared-counter}*) = proof,
609 }
610
611 \cs_undefine:c { proof }
612 \cs_undefine:c { endproof }
613 \NewDocumentEnvironment { proof } { O{\proofname} }
614 {
615 \tl_set:Nn \l_mymodule_name_of_proof_tl { #1 }
616 \begin { proof_inner* }
617 }
618 {
619 \end { proof_inner* }
620 }
621 \NewDocumentEnvironment { proof* } { O{\proofname} }
622 {
623 \tl_set:Nn \l_mymodule_name_of_proof_tl { #1 }
624 \begin { proof_inner }
625 }
626 {
627 \end { proof_inner }
628 }
629
630 \SetTheoremBinding { proof } { proof_inner* }
631 \SetTheoremBinding { proof* } { proof_inner }
632
633 \ExplSyntaxOff
634 \end{code}
635
636 It defines an environment \lstinline|proof_inner| (with its starred variant) with theorem style \lstinline|remark| to mimic the default style (you are welcome to use your own style here), and with the name to be a variable which is latter used to define the actual environments \lstinline|proof| and \lstinline|proof*|. These two environments are defined in such a way that \lstinline|proof| is the usual unnumbered version and \lstinline|proof*| is the numbered version. The \lstinline|\SetTheoremBinding| lines are to ensure that user can directly write \lstinline|\SetTheorem{proof}| instead of \lstinline|\SetTheorem{proof_inner*}|.
637
638 \begin{tip}[Attention]
639 The code above requires \textsf{amsthm}. If you are using \textsf{ntheorem} as the backend, then you need to load it with option \packageoption{amsthm}, and remove the \lstinline|\newcounter| line.
640 \end{tip}
641
642 \medskip
643 \subsection{Advanced topic: setting the names in an external file}
644
645 A typical configuration looks like this:
646
647 \begin{code}
648 \NameTheorems { english }
649 {
650 , (*\commandoption{heading}*) = {
651 , theorem = Theorem
652 , proposition = Proposition
653 ...
654 }
655 , (*\commandoption{crefname}*) = {
656 , theorem = {theorem}{theorems}
657 , proposition = {proposition}{propositions}
658 ...
659 }
660 , (*\commandoption{Crefname}*) = {
661 , theorem = {Theorem}{Theorems}
662 , proposition = {Proposition}{Propositions}
663 ...
664 }
665 }
666 \end{code}
667
668 Here is an example for French:
669
670 \begin{code}
671 \NameTheorems { french }
672 {
673 , (*\commandoption{heading}*) = {
674 , theorem = Théorème
675 , proposition = Proposition
676 , example = Exemple
677 ...
678 }
679 , (*\commandoption{crefname}*) = {
680 , theorem = [le]{théorème}[les]{théorèmes}
681 , proposition = [la]{proposition}[les]{propositions}
682 , example = [l']{exemple}[les]{exemples}
683 ...
684 }
685 , (*\commandoption{Crefname}*) = {
686 , theorem = [Le]{théorème}[Les]{théorèmes}
687 , proposition = [La]{proposition}[Les]{propositions}
688 , example = [L']{exemple}[Les]{exemples}
689 ...
690 }
691 }
692 \end{code}
693
694 And an example for German:
695
696 \begin{code}
697 \NameTheorems { ngerman }
698 {
699 , (*\commandoption{heading}*) = {
700 , theorem = Satz
701 ...
702 }
703 , (*\commandoption{crefname}*) = {
704 , theorem = { {Satz}{Sätze}
705 , Nominativ = [der]{Satz}[die]{Sätze}
706 , Genitiv = [des]{Satzes}[der]{Sätze}
707 , Dativ = [dem]{Satz}[den]{Sätzen}
708 , Akkusativ = [den]{Satz}[die]{Sätze}
709 }
710 ...
711 }
712 , (*\commandoption{Crefname}*) = {
713 , theorem = { {Satz}{Sätze}
714 , Nominativ = [Der]{Satz}[Die]{Sätze}
715 , Genitiv = [Des]{Satzes}[Der]{Sätze}
716 , Dativ = [Dem]{Satz}[Den]{Sätzen}
717 , Akkusativ = [Den]{Satz}[Die]{Sätze}
718 }
719 ...
720 }
721 }
722 \end{code}
723
724 \medskip
725 The configuration using \lstinline|\NameTheorems| is compatible with that using \lstinline|\NameTheorem| and there is no need to worry about duplicated definitions --- new settings will automatically overwrite the old ones.
726
727
728 \clearpage
729 \section{Known issues}
730
731 \begin{itemize}
732 \item \createtheorempackage{} modifies some undocumented internal macros of \textsf{cleveref}, so the behavior might not be stable if \textsf{cleveref} gets updated one day.
733 \item The current naming mechanism for theorems essentially follows the syntax of \textsf{cleveref}. The configuration may look somewhat redundant. In a future version, a new mechanism is planed to be introduced, which would be similar to the method used by \textsf{zref-clever}.
734 \item It is current not possible to temporarily change the referencing type when referencing, which makes it difficult to reference a \textquote{\texttt{namedtheorem}}, or if you have both the singular and plural form of an environment, say \textquote{\texttt{example}} and \textquote{\texttt{examples}}, they would be referred to as two separate types.
735 \item The counter aliasing function is still not perfect, (sometimes) causing incorrect ordering in the result of \lstinline|\cref|.
736 \item There might be inaccuracies in the translation of those preset names.
737 \end{itemize}
738
739 \medskip
740 If you run into any issues or have ideas for improvement, feel free to discuss on:
741 \begin{center}
742 \url{https://github.com/Jinwen-XU/create-theorem/issues}
743 \end{center}
744 or email me via \href{mailto:[email protected]}{\texttt{[email protected]}}.
745
746 \end{document}