Debian Codegraph @

texmf-dist/doc/latex/crefthe/crefthe-doc.tex

raw
1 %! TEX program = xelatex
2 \documentclass[classical]{einfart}
3
4 \linenumbers
5
6 \usepackage{ProjLib}
7
8 \setmonofont[Scale=.9]{Iosevka}
9
10 %%================================
11 %% For typesetting code
12 %%================================
13 \usepackage{listings}
14 \usepackage{xcolor}
15 \usepackage{setspace}
16 \definecolor{code-main}{RGB}{70,130,180}
17 \definecolor{code-expl3}{RGB}{240,50,60}
18 \definecolor{code-option}{RGB}{40,110,20}
19 \definecolor{code-keys}{RGB}{100,130,150}
20 \definecolor{code-comment}{RGB}{20,120,80}
21 \definecolor{code-background}{gray}{0.99}
22 \lstset{
23 language = [LaTeX]TeX,
24 basicstyle = \ttfamily,
25 keywordstyle = \color{code-main},
26 commentstyle = \color{code-comment},
27 showstringspaces = false,
28 breaklines = true,
29 frame = lines,
30 backgroundcolor = \color{code-background},
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 cref,crefname,
47 Cref,Crefname,
48 namecref,namecrefs,
49 nameCref,nameCrefs,
50 cpageref,Cpageref,
51 crefformat,
52 crefthe,crefthename,
53 Crefthe,Crefthename,
54 crefthevariantname,Crefthevariantname,
55 setcrefname,setCrefname,
56 namecrefthe,namecrefsthe,
57 nameCrefthe,nameCrefsthe,
58 cpagerefthe,Cpagerefthe,
59 crefthemark,
60 crefthepatchname,
61 selectlanguage,
62 }
63 }
64 \lstset{% LaTeX3 commands
65 classoffset = 1,
66 texcsstyle =* \color{code-expl3},
67 moretexcs =
68 {
69 }
70 }
71 \lstnewenvironment{code}{\setstretch{1.05}\LocallyStopLineNumbers}{\ResumeLineNumbers\vspace{-.3\baselineskip}\vspace{-.5\parskip}}
72 \lstnewenvironment{code*}{\setstretch{1.05}\lstset{numbers=left}\LocallyStopLineNumbers}{\ResumeLineNumbers\vspace{-.3\baselineskip}\vspace{-.5\parskip}}
73
74 \newcommand{\packageoption}[1]{\textcolor{code-option}{\texttt{#1}}}
75 \newcommand{\commandoption}[1]{\textcolor{code-keys}{\texttt{#1}}}
76
77 %%================================
78 %% tip
79 %%================================
80 \usepackage[many]{tcolorbox}
81 \newenvironment{tip}[1][Tip]
82 {%
83 \LocallyStopLineNumbers%
84 \begin{tcolorbox}[breakable,
85 enhanced,
86 width = \textwidth,
87 colback = paper, colbacktitle = paper,
88 colframe = gray!50, boxrule=0.2mm,
89 coltitle = black,
90 fonttitle = \sffamily,
91 attach boxed title to top left = {yshift=-\tcboxedtitleheight/2, xshift=.5cm},
92 boxed title style = {boxrule=0pt, colframe=paper},
93 before skip = 3mm,
94 after skip = 3mm,
95 top = 2.5mm,
96 bottom = 1.5mm,
97 title={\scshape\sffamily #1}]%
98 }
99 {%
100 \end{tcolorbox}%
101 \ResumeLineNumbers%
102 }
103
104 %%================================
105 %% demo
106 %%================================
107 \newenvironment{demo}
108 {%
109 \LocallyStopLineNumbers%
110 \begin{tcolorbox}[enhanced jigsaw,pad at break*=1mm,breakable,
111 left=2.5mm,right=3mm,top=0.5mm,bottom=0mm,
112 colback=gray!5!paper,boxrule=0pt,frame hidden,
113 borderline west={1.2mm}{0mm}{gray!55!paper},arc=.7mm]%
114 }
115 {%
116 \end{tcolorbox}%
117 \ResumeLineNumbers%
118 }
119
120
121 \newcommand{\crefthepackage}{\textsf{crefthe}}
122
123 \begin{document}
124
125 \def\PackageVersion{2024/02/25}
126 \def\PackageSubVersion{}
127
128 \title{\crefthepackage{}\\\smallskip\itshape Cross referencing with proper definite articles and declensions}
129 \author{Jinwen XU}
130 \thanks{Corresponding to: \texttt{\crefthepackage{} \PackageVersion\PackageSubVersion}.}
131 \date{\TheDate{\PackageVersion}[only-year-month], in Paris}
132
133 \maketitle
134
135 \begin{abstract}
136 \raggedleft
137 The package \crefthepackage{} provides a command \lstinline|\crefthe| parallel to \textsf{cleveref}'s \lstinline|\cref| for handling definite articles and declensions properly (especially for the phenomenon of article contractions in some European languages, such as French and German).
138 \end{abstract}
139
140 \section{The motivation}
141
142 By default, with \textsf{cleveref}'s \lstinline|\cref| to reference theorem-like environments, the names do not contain definite articles. While this might be acceptable for English, it is certainly not good enough for languages such as French, German, Italian, Portuguese, Spanish, etc. --- in these cases there shall be grammatical errors and would give you a strong feeling that it is machine-generated.
143
144 However, even if we manually add the definite articles to the names, there would still be other problems. As an example, if we define the French names to be:
145
146 \begin{code}
147 \crefname{theorem}{le théorème}{les théorèmes}
148 \crefname{proposition}{la proposition}{les propositions}
149 \end{code}
150
151 then when one writes (which means ``\emph{We can deduce this from ...}'')
152
153 \begin{code}
154 On peut le déduire de \cref{thm1,thm2,prop3}.
155 \end{code}
156
157 the result would be:
158
159 \begin{demo}
160 On peut le déduire \textbf{de les} théorèmes 1 et 2 et \textbf{la} proposition 3.
161 \end{demo}
162
163 which is wrong, as the correct result should be:
164
165 \begin{demo}
166 On peut le déduire \textbf{des} théorèmes 1 et 2 et \textbf{de la} proposition 3.
167 \end{demo}
168
169 \lstinline|\cref| cannot handle such cases automatically --- that is when \lstinline|\crefthe| comes into play.
170
171
172 \section{The usage}
173
174 \subsection[How to load it]{How to load it\,?}
175
176 Simply load the package with:
177
178 \begin{code}
179 \usepackage{crefthe}
180 \end{code}
181
182 \begin{tip}
183 \begin{itemize}
184 \item Since \crefthepackage{} uses \textsf{cleveref} internally, it should usually be placed at the last of your preamble, and notably, after \textsf{varioref} and \textsf{hyperref}.
185 \item To handle article contractions correctly, \lstinline|\crefthe| shall detect the current language, thus you need to use packages such as \textsf{babel} or \textsf{polyglossia} to set your languages, and use commands like \lstinline|\selectlanguage| to select them appropriately.
186 \end{itemize}
187 \end{tip}
188
189 \subsection[How to use it]{How to use it\,?}
190
191 Before everything, you need to define the names, which can be done with \lstinline|\crefthename|. Its syntax is similar to \lstinline|\crefname|, but now you can specify the definite articles, for example:
192
193 \begin{code}
194 \crefthename{theorem}[le]{théorème}[les]{théorèmes}
195 \end{code}
196
197 \begin{tip}
198 The \lstinline|\crefthename|s should be placed in your preamble, otherwise the \lstinline|\cref| formats will not be set. These names can, however, be reset within the document body.
199 \end{tip}
200
201 Then you can use the command \lstinline|\crefthe| as follows:
202 \begin{itemize}[label=,leftmargin=1.25em,itemindent=-1.25em]
203 \item \lstinline|\crefthe[|\meta{prep}\lstinline|]{|\meta{labels}\lstinline|}|
204 \begin{itemize}
205 \item This will pass the preposition \meta{prep} to the definite articles that follows. Its behavior depends on the current language (for example, in Spanish, \meta{prep} is passed only to the first definite article, while in French it is passed to everyone).
206 \end{itemize}
207 \item \lstinline|\crefthe-[|\meta{prep}\lstinline|]{|\meta{labels}\lstinline|}| and \lstinline|\crefthe+[|\meta{prep}\lstinline|]{|\meta{labels}\lstinline|}|
208 \begin{itemize}
209 \item In case the automatic version does not meet your needs, here are two manual ones. The \verb|-| version passes the preposition \meta{prep} only to the first definite article, while the \verb|+| version passes \meta{prep} to every definite article.
210 \end{itemize}
211 \end{itemize}
212
213 \begin{tip}
214 \begin{itemize}
215 \item There is also a stared version \lstinline|\crefthe*| for generating the same referencing text without creating hyperlinks.
216 \item The name-only relatives are also available: \lstinline|\namecrefthe| and \lstinline|\namecrefsthe|.
217 \item \lstinline|\cpagerefthe| and \lstinline|\Cpagerefthe| are provided as well.
218 \end{itemize}
219 \end{tip}
220
221 % However, before using it, you should first define the \lstinline|\crefname|s carefully. The definite article in \lstinline|\crefname|s needs to be marked manually using \lstinline|\crefthemark|, for example:
222
223 % \begin{code}
224 % \crefname{theorem}{\crefthemark{le} théorème}
225 % {\crefthemark{les} théorèmes}
226 % \end{code}
227
228
229 \enlargethispage*{\baselineskip}
230 \section{Example}
231
232 Let us come back to the example at the beginning, now you can do this:
233
234 \begin{code}
235 \crefthename{theorem}[le]{théorème}[les]{théorèmes}
236 \crefthename{proposition}[la]{proposition}[les]{propositions}
237 \end{code}
238
239 And the sentence shall be written as:
240
241 \begin{code}
242 On peut le déduire \crefthe[de]{thm1,thm2,prop3}.
243 \end{code}
244
245 which would result in (provided that you have done \lstinline|\selectlanguage{french}|):
246
247 \begin{demo}
248 On peut le déduire \textbf{des} théorèmes 1 et 2 et \textbf{de la} proposition 3.
249 \end{demo}
250
251 Voilà !
252
253 \section{For language with declensions}
254
255 In German, there are four declensions: nominative (\texttt{Nominativ}), genitive (\texttt{Genitiv}), dative (\texttt{Dativ}) and accusative (\texttt{Akkusativ}), making the previously presented mechanism insufficient. For such situation, we introduce the command \lstinline|\crefthevariantname| to specify the referencing name for the correspond environment. Below is an example of usage:
256
257 \begin{code}
258 \crefthevariantname{theorem}
259 {
260 {Satz}{Sätze}
261 , Nominativ = [der]{Satz}[die]{Sätze}
262 , Genitiv = [des]{Satzes}[der]{Sätze}
263 , Dativ = [dem]{Satz}[den]{Sätzen}
264 , Akkusativ = [den]{Satz}[die]{Sätze}
265 }
266 \end{code}
267
268 \begin{tip}
269 \begin{itemize}
270 \item The first line in the configuration is the default set of names when no variant is specified. It is recommended, though not required.
271 \item There is also an equivalent but shorter name \lstinline|\setcrefname| for this command.
272 \end{itemize}
273 \end{tip}
274
275 After this, you may refer to a theorem via
276
277 \begin{code}
278 \crefthe[(*\meta{prep}*),(*\commandoption{variant}*)=(*\meta{declension}*)]{(*\meta{label}*)}
279 \end{code}
280
281 You may also use the shortcuts (\texttt{nom.}, \texttt{gen.}, \texttt{dat.} and \texttt{akk.}), such as:
282
283 \begin{code}
284 \crefthe[(*\meta{prep}*),(*\commandoption{Nom}*)]{(*\meta{label}*)} \crefthe[(*\meta{prep}*),(*\commandoption{Nom.}*)]{(*\meta{label}*)}
285 \crefthe[(*\meta{prep}*),(*\commandoption{nom}*)]{(*\meta{label}*)} \crefthe[(*\meta{prep}*),(*\commandoption{nom.}*)]{(*\meta{label}*)}
286 \end{code}
287
288 These four are all equivalent and you may choose one to use according to your preference.
289
290 Article contractions are by default enabled for German, but if you don't want this, you may use the package option \packageoption{disable german article contractions}.
291
292 \section{Using abbreviation form}
293
294 There is another usage of \lstinline|\crefthevariantname| (or equivalently, \lstinline|\setcrefname|): setting the abbreviation form. This allows you to use both the full form and the abbreviation form within the same document. For example, you may set
295
296 \begin{code}
297 \setcrefname{theorem}
298 {
299 {theorem}{theorems}
300 , abbr. = {th.}{ths.}
301 }
302 \end{code}
303
304 Then, when referencing, you can use the command option \commandoption{abbr.} to enable abbreviation:
305
306 \begin{code}
307 \crefthe[(*\commandoption{abbr.}*)]{(*\meta{label}*)}
308 \end{code}
309
310 \begin{tip}[Attention]
311 Please note that \commandoption{abbr.} has more priority than the option(s) for specifying declensions. This means that when \commandoption{abbr.} is enabled, the declensions are simply ignored.
312 \end{tip}
313
314 \section{Regarding the upper and lower cases}
315
316 As with \textsf{cleveref}, these commands have corresponding uppercased version: \lstinline|\Crefthename|, \lstinline|\Crefthe|, \lstinline|\nameCrefthe|, \lstinline|\nameCrefsthe| and \lstinline|\Cpagerefthe|, similar to \lstinline|\Crefname|, \lstinline|\Cref|, \lstinline|\nameCref|, \lstinline|\nameCrefs| and \lstinline|\Cpageref|, reserved for using at the beginning of a sentence. Their usage is essentially the same as the corresponding lowercase version.
317
318 For languages with declensions, such as German, there is also a \lstinline|\Crefthevariantname| (or equivalently, \lstinline|\setCrefname|), corresponding to the above \lstinline|\crefthevariantname|.
319
320 \lstinline|\Crefthe| (and the name-only relatives) can handle case changing automatically: for example, with \lstinline|\Crefthe[À]{thm1,thm2,prop3}|, you will get something like
321
322 \begin{demo}
323 \textbf{Aux} théorèmes 1 et 2 et \textbf{à la} proposition 3
324 \end{demo}
325
326 Of course, you would have to define the \lstinline|\Crefthename|s separately, for example as:
327
328 \begin{code}
329 \Crefthename{theorem}[Le]{théorème}[Les]{théorèmes}
330 \Crefthename{proposition}[La]{proposition}[Les]{propositions}
331 \end{code}
332
333 \enlargethispage*{\baselineskip}
334 \section{On the coordination of gender and number}
335
336 In many languages, adjectives and verbs need to be properly inflected for the gender and singular or plural of the noun. Take French as example, you may see the following expressions:
337 \begin{itemize}
338 \item La proposition précédent\textbf{e}/suivant\textbf{e}... (The previous/next proposition...)
339 \item La proposition est illustré\textbf{e} par... (The proposition is illustrated by...)
340 \end{itemize}
341 Thus if you later decide to change this proposition (feminine) into a theorem (masculine), you would have to modify the adjectives and verbs accordingly. Similar things happens in many other languages, and it is not quite realistic to fully automate such modifications.
342
343 The name-only relatives \lstinline|\namecrefthe|, \lstinline|\nameCrefthe| etc. are designed for this purpose. They do not automatically solve these kinds of problems, but you may later search for the \meta{label} of the environment that changes, and modify the surrounding context manually --- in other words, these commands serve as recorders: if you write the word like \textquote{theorem} or \textquote{proposition} directly in the text, then later it would be unclear which part of your text needs to be update when the environment itself changes.
344
345 There is another case. For example, if you wish to say \textquote{ce théorème} (\textquote{this theorem}), the pre-defined set of names that contains definite articles would be somewhat redundant. In such situation, you may use the command option \commandoption{noun} to show only the noun:
346
347 \begin{code}
348 \namecref[(*\commandoption{noun}*)]{(*\meta{label}*)}
349 \end{code}
350
351 But then of course you shall need to write the word \textquote{Ce/Cet/Cette} (these are all different forms of \textquote{This} in French) by yourself --- and if you later decide to change the type of the environment to which this \meta{label} refers, don't forget to change this word accordingly.
352
353 \section{For writing multi-language documents}
354
355 To place hyperlinks at the correct place, \lstinline|\crefthename| touches the corresponding format macro \lstinline|\crefformat| internally, which makes the format language-dependent. If you are writing multi-language documents, you may consider putting \lstinline|\crefthename| inside your language configuration so as to reset it each time you select a new language.
356
357 \section{Dealing with existed \texttt{cref} / \texttt{Cref} names}
358
359 For those preset names defined with \lstinline|\crefname|\,/\,\lstinline|\Crefname|, such as the ones for \texttt{chapter}, \texttt{section} and \texttt{subsection}, etc., the optional argument of \lstinline|\crefthe|\,/\,\lstinline|\Crefthe| shall be useless: names defined with \lstinline|\crefthename|\,/\,\lstinline|\Crefthename| have a \lstinline|\crefthemark| marking the definite articles, which also deals with the given preposition ; without \lstinline|\crefthemark|, the preposition is simply ignored.
360
361 \lstinline|\crefthepatchname{|\meta{counters}\lstinline|}| is provided for this purpose. With this, an empty mark shall be added before the existed singular and plural names. However, it is still recommended to simply redefine the names with \lstinline|\crefthename|\,/\,\lstinline|\Crefthename|, especially in multilingual documents.
362
363 % For multilingual documents, you may need to add this to your language configuration so as to reapply it each time you select a new language.
364
365
366 \section{The relationship with \textsf{cleveref}}
367
368 \crefthepackage{} loads \textsf{cleveref} automatically and passes related options to it. All its commands, used without optional arguments, degenerate to those in \textsf{cleveref}. For example, \lstinline|\crefthe{...}|%
369 will produce the same result as \lstinline|\cref{...}|, and \lstinline|\crefthename| shall behave the same as \lstinline|\crefname| if the definite articles are not specified. That said, you may safely use the command \lstinline|\crefthe| everywhere in your document without causing extra trouble.
370
371 With the package option \packageoption{overwrite}, user commands in \textsf{cleveref} will be replaced by those offered here, thus you can simply write \lstinline|\cref| for \lstinline|\crefthe| --- and similarly with \lstinline|\Cref|, \lstinline|\crefname| and \lstinline|\Crefname|, etc.
372
373
374 \clearpage
375
376
377 \section{Acknowledgement}
378
379 There are so many people I wish to express my gratitude to during the development of this package, including:
380
381 \begin{itemize}
382 \item Patrick Bideault, without whose advice and careful explanation, this package would probably never have been born. Merci !
383 \item Enrico Gregorio, Phelype Oleinik and Joseph Wright (in alphabetical order). They made valuable suggestions in the early development of this package and even edited some of the code themselves.
384 \item Jonathan P. Spratte, without whose help the German support would probably take much longer to complete.
385 \end{itemize}
386
387
388 \bigskip
389 \section{Known issues}
390 \begin{itemize}
391 \item \crefthepackage{} currently works for French, German, Italian, Portuguese (European and Brazilian) and Spanish --- certainly more languages would be added to this list in the future.
392 % \item For now, you cannot specify the masculine/masculine/... of words. This means, for instance, that you cannot make the suffix adjective automatically adopted to the word when using \lstinline|\namecref| --- as an example, if you wish to say \textquote{la proposition suivante} (in French), you would have to write the feminine adjective manually. The situation should be improved with the introduction of a new key-value configuration system, which is currently on the todo-list.
393 % Meanwhile, you may consider the package \textsf{zref-clever}, which has a much more powerful and sophisticated interface for configuring cross referencing.
394 \item The names of theorem-like environments are not provided here, you need to define them by yourself. However, users are encouraged to use the \ProjLib{} toolkit (more specifically, the internal package \textsf{create-theorem}), which already handles everything for you.
395 \end{itemize}
396
397 \medskip
398 If you run into any issues or have ideas for improvement, feel free to discuss on:
399 \begin{center}
400 \url{https://github.com/Jinwen-XU/crefthe/issues}
401 \end{center}
402 or email me via \href{mailto:[email protected]}{\texttt{[email protected]}}.
403
404
405 \end{document}