Debian Codegraph @

texmf-dist/doc/latex/cleveref-forward/demo/cleveref-forward-demo.tex

raw
1 \documentclass[
2 % use style = plain,
3 title in boldface,
4 % title in sffamily,
5 emphasize theorems,
6 simple name, % not suitable for French, German, etc.
7 name in link,
8 ]{einfart}
9 \usepackage{ProjLib}
10
11 \setmonofont[Scale=.9]{Iosevka}
12
13 \usepackage[crefthe]{cleveref-forward}
14 \usepackage{changepage,todonotes,marginnote}
15
16 %%================================
17 %% For typesetting code
18 %%================================
19 \usepackage{listings}
20 \usepackage{xcolor}
21 \usepackage{setspace}
22 \definecolor{code-main}{RGB}{70,130,180}
23 \definecolor{code-expl3}{RGB}{240,50,60}
24 \definecolor{code-option}{RGB}{40,110,20}
25 \definecolor{code-keys}{RGB}{100,130,150}
26 \definecolor{code-comment}{RGB}{20,120,80}
27 \definecolor{code-background}{gray}{0.99}
28 \lstset{
29 language = [LaTeX]TeX,
30 basicstyle = \ttfamily,
31 keywordstyle = \color{code-main},
32 commentstyle = \color{code-comment},
33 showstringspaces = false,
34 breaklines = true,
35 frame = lines,
36 backgroundcolor = \color{code-background},
37 basewidth = .5em,
38 escapeinside = {(*}{*)},
39 alsoletter = {_:},
40 % numbers = left,
41 % firstnumber = last,
42 numberstyle = \scriptsize\ttfamily,
43 stepnumber = 1,
44 numbersep = 5pt,
45 }
46 \newcommand{\meta}[1]{$\langle${\normalfont\itshape#1}$\rangle$}
47 \lstset{% LaTeX2 commands
48 classoffset = 0,
49 texcsstyle =* \color{code-main},
50 moretexcs =
51 {
52 ExplSyntaxOn,ExplSyntaxOff,
53 NewDocumentCommand,NewDocumentEnvironment,
54 cref,Cref,
55 crefthe,Crefthe,
56 cpageref,
57 cpagerefthe,
58 namecref,nameCref,
59 labelcref,labelCref,
60 restorelabel,
61 SetUsedOnMessageText,
62 SetUsedByMessageText,
63 SetUsedByAndOnMessageText,
64 SetForwardReferenceStyle,
65 SetForwardReferenceStyleInsideMath,
66 SetForwardReferenceStyleOutsideMath,
67 SetForwardReferenceRefForm,
68 SetForwardReferencePagerefForm,
69 todo,
70 marginnote,
71 }
72 }
73 \lstset{% LaTeX3 commands
74 classoffset = 1,
75 texcsstyle =* \color{code-expl3},
76 moretexcs =
77 {
78 tl_new:N,
79 tl_set:Nn,
80 cs_undefine:c,
81 }
82 }
83 \lstnewenvironment{code}{\setstretch{1.05}\LocallyStopLineNumbers}{\ResumeLineNumbers\vspace{-.3\baselineskip}\vspace{-.5\parskip}}
84 \lstnewenvironment{code*}{\setstretch{1.05}\lstset{numbers=left}\LocallyStopLineNumbers}{\ResumeLineNumbers\vspace{-.3\baselineskip}\vspace{-.5\parskip}}
85
86 \newcommand{\packageoption}[1]{\textcolor{code-option}{\texttt{#1}}}
87 \newcommand{\commandoption}[1]{\textcolor{code-keys}{\texttt{#1}}}
88
89 %%================================
90 %% tip
91 %%================================
92 \usepackage[many]{tcolorbox}
93 \newenvironment{tip}[1][Tip]
94 {%
95 \LocallyStopLineNumbers%
96 \begin{tcolorbox}[breakable,
97 enhanced,
98 width = \textwidth,
99 colback = paper, colbacktitle = paper,
100 colframe = gray!50, boxrule=0.2mm,
101 coltitle = black,
102 fonttitle = \sffamily,
103 attach boxed title to top left = {yshift=-\tcboxedtitleheight/2, xshift=.5cm},
104 boxed title style = {boxrule=0pt, colframe=paper},
105 before skip = 3mm,
106 after skip = 3mm,
107 top = 2.5mm,
108 bottom = 1.5mm,
109 title={\scshape\sffamily #1}]%
110 }
111 {%
112 \end{tcolorbox}%
113 \ResumeLineNumbers%
114 }
115
116
117 \title{\textsc{demonstration on the usage and configuration of}\\[.3\baselineskip]\fbox{\textsf{cleveref-forward}}}
118 \author{}
119 \date{\today[only-year-month]}
120
121 \begin{document}
122
123 \maketitle
124
125 \section{Demonstration with the default configuration}
126
127 \subsection{Theorem-like environments}
128
129 \begin{lemma}\label{lem:result}
130 Some preliminary result (see the equation \labelcref[used by]{eq:1}).
131 \end{lemma}
132
133 \begin{theorem}\label{thm:test}
134 Text.
135 \end{theorem}
136 \begin{proof}\restorelabel{thm:test} % Notice the use of \restorelabel here
137 Some proof that involves the \cref[used by]{lem:result} and the equations \labelcref[used by and on]{eq:Euler}, \labelcref[used by]{eq:1,eq:2} in the next section. Here, \lstinline|\restorelabel| makes sure that this \texttt{proof} environment is being recognized as the theorem itself.
138 \end{proof}
139
140 \subsection{Displayed equations}
141
142 By default, the forward referencing infomation is placed immediately after the equation.
143
144 \begin{equation}\label{eq:Euler}
145 \mathrm{e}^{\mathrm{i}\pi} + 1 = 0.
146 \end{equation}
147
148 However, with this method, for multilined equations with multiple references, only the last reference will be shown:
149 \begin{align}
150 1 &= 0 + 1 \label{eq:1}\\
151 2 &= 1 + 1 \label{eq:2}
152 \end{align}
153
154 This can be overcome if you are willing to place the text message in the margin, see the section on customization.
155
156 \subsection{Other types}
157
158 It can also be used for some other types, such as items in \texttt{enumerate} list, as long as \textsf{cleveref} is properly configured for that type.
159
160 \section{Specify a default option}
161
162 If you wish to apply the mode \commandoption{used on}, or \commandoption{used by}, or \commandoption{used by and on} to all \lstinline|\cref| (and \lstinline|\labelcref|, etc.), you can use the package option \packageoption{default=}\meta{mode}. Then you don't need to write it everywhere. And if you wish to manually change this \meta{mode} somewhere, you can still specify it as the command option; and if you don't want the message to display for some references, you may also use the option \commandoption{no use} (or \commandoption{not use}) on the corresponding \lstinline|\label| to disable the related messages.
163
164
165 \section{Customizations}
166
167 \begingroup
168
169 Here is how you change the appearing text:
170
171 \begin{code}
172 \SetUsedOnMessageText{Appears on~#1.}
173 \SetUsedByMessageText{Appears in~#1.}
174 \SetUsedByAndOnMessageText{Appears in~#1 on~#2.}
175 \end{code}
176
177 \SetUsedOnMessageText{Appears on~#1.}
178 \SetUsedByMessageText{Appears in~#1.}
179 \SetUsedByAndOnMessageText{Appears in~#1 on~#2.}
180
181 \bigskip
182 And here is an example of setting the message style with the package \textsf{todonotes}:
183
184 \begin{code}
185 \SetForwardReferenceStyle
186 {%
187 \todo[%
188 inline,
189 size=\scriptsize,
190 color=blue!40,
191 backgroundcolor=white,
192 textcolor=blue!50!cyan,
193 bordercolor=blue!50!cyan,
194 noprepend]{%
195 \textup{#1}%
196 }%
197 }
198 \SetForwardReferenceStyleOutsideMath
199 {%
200 \todo[%
201 inline,
202 size=\scriptsize,
203 caption={}, % <-- needed, otherwise there would be errors
204 color=blue!40,
205 backgroundcolor=white,
206 textcolor=blue!50!cyan,
207 bordercolor=blue!50!cyan,
208 noprepend]{%
209 \textup{#1}%
210 }%
211 }
212 \end{code}
213
214 \SetForwardReferenceStyle
215 {%
216 \todo[%
217 inline,
218 size=\scriptsize,
219 color=blue!40,
220 backgroundcolor=white,
221 textcolor=blue!50!cyan,
222 bordercolor=blue!50!cyan,
223 noprepend]{%
224 \textup{#1}%
225 }%
226 }
227 \SetForwardReferenceStyleOutsideMath
228 {%
229 \todo[%
230 inline,
231 size=\scriptsize,
232 caption={}, % <-- needed, otherwise there would be errors
233 color=blue!40,
234 backgroundcolor=white,
235 textcolor=blue!50!cyan,
236 bordercolor=blue!50!cyan,
237 noprepend]{%
238 \textup{#1}%
239 }%
240 }
241
242 \bigskip
243 We use the same example:
244
245 \begin{lemma}\label{lem:result'}
246 Some preliminary result (see the equation \labelcref[used by]{eq:1'}).
247 \end{lemma}
248
249 \begin{theorem}\label{thm:test'}
250 Text.
251 \end{theorem}
252 \begin{proof}\restorelabel{thm:test'} % Notice the use of \restorelabel here
253 Some proof that involves the \cref[used by]{lem:result'} and the equations \labelcref[used by and on]{eq:Euler'}, \labelcref[used by]{eq:1',eq:2'}.
254 \end{proof}
255
256 \begin{equation}\label{eq:Euler'}
257 \mathrm{e}^{\mathrm{i}\pi} + 1 = 0.
258 \end{equation}
259 \vspace{-\baselineskip}
260 \begin{align}
261 1 &= 0 + 1 \label{eq:1'}\\
262 2 &= 1 + 1 \label{eq:2'}
263 \end{align}
264
265 \bigskip
266 As you might have noticed, \lstinline|\SetForwardReferenceStyleOutsideMath| is for setting the style of those messages that appear outside the equations.
267
268 There is also a \lstinline|\SetForwardReferenceStyleInsideMath|, which triggers the message immediately at where you placed the label. This way it is only plausible to put the message inside the margin. For example, with the package \textsf{marginnote} loaded, you may configure:
269
270 \begin{code}
271 \SetForwardReferenceStyle
272 {%
273 \marginnote{\normalfont#1}%
274 }
275 \SetForwardReferenceStyleInsideMath
276 {%
277 \marginnote{\normalfont#1}%
278 }
279 \end{code}
280
281 \SetForwardReferenceStyle
282 {%
283 \marginnote{\normalfont#1}%
284 }
285 \SetForwardReferenceStyleInsideMath
286 {%
287 \marginnote{\normalfont#1}%
288 }
289
290 \bigskip
291 The result would be somewhat like the following (assuming that your document has margins set wide enough):
292
293 \vspace{-\baselineskip}
294 \setlength{\marginparwidth}{20em}
295 \setlength{\marginparsep}{-15em}
296 \begin{adjustwidth}{}{16em}
297 \begin{lemma}\label{lem:result''}
298 Some preliminary result (see the equation \labelcref[used by]{eq:1''}).
299 \end{lemma}
300
301 \begin{theorem}\label{thm:test''}
302 Text.
303 \end{theorem}
304 \begin{proof}\restorelabel{thm:test''} % Notice the use of \restorelabel here
305 Some proof that involves the \cref[used by]{lem:result''} and the equations \labelcref[used by and on]{eq:Euler''}, \labelcref[used by]{eq:1'',eq:2''}.
306 \end{proof}
307
308 \begin{equation}\label{eq:Euler''}
309 \mathrm{e}^{\mathrm{i}\pi} + 1 = 0.
310 \end{equation}
311 \begin{align}
312 1 &= 0 + 1 \label{eq:1''}\\
313 2 &= 1 + 1 \label{eq:2''}
314 \end{align}
315 \end{adjustwidth}
316
317 \bigskip
318 \begin{tip}[Attention]
319 Please pay attention to the usage of \lstinline|#1| and \lstinline|#2| in the configurations.
320 \end{tip}
321
322 \clearpage
323 By the way, here is the default setting for the style:
324
325 \begin{code}
326 \SetForwardReferenceStyle
327 {%
328 \emph{#1} \\[.3\baselineskip]%
329 }
330 \SetForwardReferenceStyleOutsideMath
331 {%
332 \begin{flushright}%
333 \emph{#1}%
334 \end{flushright}%
335 \vspace{.15\baselineskip}%
336 }
337 \end{code}
338
339 \endgroup
340
341 \SetForwardReferenceStyle
342 {%
343 \marginnote{\normalfont#1}%
344 }
345 \SetForwardReferenceStyleInsideMath
346 {%
347 \marginnote{\normalfont#1}%
348 }
349
350 %% You can safely ignore the code between \ExplSyntaxOn and \ExplSyntaxOff
351 %% They are just for resetting the theorem referencing style for the rest of the document
352 \ExplSyntaxOn
353 \input{create-theorem-preset-names-cleveref} % simple-name mode is not suitable for French, German, etc.
354 \exp_args:No \SetTheorem { \c_projlib_theorem_supported_clist, theorem-with-name } % remove the text style in the references
355 {
356 name style = {
357 , crefname style = { }
358 , Crefname style = { }
359 , numbering style = { }
360 }
361 }
362 \ExplSyntaxOff
363
364
365 \section{Besides writing in English}
366
367 When writing in some European languages, it is possible to specify the definite article and/or declension in the optional argument of \lstinline|\cref| to ensure that the grammar is correct, provided that you have enabled the package option \packageoption{crefthe}.
368
369 \subsection{Example in French}
370
371 \UseLanguage{French}
372
373 \vspace{-1.5\baselineskip}
374 \setlength{\marginparwidth}{24em}
375 \setlength{\marginparsep}{-18em}
376 \begin{adjustwidth}{}{20em}
377 \begin{lemma}\label{lem:result_fr}
378 Quelques résultats préliminaires (voir l'équation \labelcref[used by]{eq:1_fr}).
379 \end{lemma}
380
381 \begin{theorem}\label{thm:test_fr}
382 Texte.
383 \end{theorem}
384 \begin{proof}\restorelabel{thm:test_fr}
385 % Notice the use of \cref[de,...]
386 Quelques lignes de preuves résultant \cref[de, used by]{lem:result_fr} et des équations \labelcref[used by and on]{eq:Euler_fr}, \labelcref[used by]{eq:1_fr,eq:2_fr}.
387 \end{proof}
388
389 \begin{equation}\label{eq:Euler_fr}
390 \mathrm{e}^{\mathrm{i}\pi} + 1 = 0.
391 \end{equation}
392 \begin{align}
393 1 &= 0 + 1 \label{eq:1_fr}\\
394 2 &= 1 + 1 \label{eq:2_fr}
395 \end{align}
396 \end{adjustwidth}
397
398 \subsection{Example in German}
399
400 \UseLanguage{German}
401
402 % \SetUsedOnMessageText{Erscheint auf~#1.}
403 % \SetUsedByMessageText{Erscheint #1.}
404 % \SetUsedByAndOnMessageText{Erscheint #1 auf~#2.}
405 % \SetForwardReferenceRefForm{\crefthe[in,dat.]}
406 % \SetForwardReferencePagerefForm{\cpagerefthe[noun]}
407
408 \vspace{-1.5\baselineskip}
409 \setlength{\marginparwidth}{24em}
410 \setlength{\marginparsep}{-18em}
411 \begin{adjustwidth}{}{20em}
412 \begin{lemma}\label{lem:result_de}
413 Einige vorläufige Ergebnisse (siehe Gleichung \labelcref[used by]{eq:1_de}).
414 \end{lemma}
415
416 \begin{theorem}\label{thm:test_de}
417 Text.
418 \end{theorem}
419 \begin{proof}\restorelabel{thm:test_de}
420 % Notice the use of \cref[die, akk.,...]
421 Einige Beweise, \cref[die, akk., used by]{lem:result_de} und die Gleichungen \labelcref[used by and on]{eq:Euler_de}, \labelcref[used by]{eq:1_de,eq:2_de}.
422 \end{proof}
423
424 \begin{equation}\label{eq:Euler_de}
425 \mathrm{e}^{\mathrm{i}\pi} + 1 = 0.
426 \end{equation}
427 \begin{align}
428 1 &= 0 + 1 \label{eq:1_de}\\
429 2 &= 1 + 1 \label{eq:2_de}
430 \end{align}
431 \end{adjustwidth}
432
433 \subsection{Example in Italian}
434
435 \UseLanguage{Italian}
436
437 \vspace{-1.5\baselineskip}
438 \setlength{\marginparwidth}{24em}
439 \setlength{\marginparsep}{-18em}
440 \begin{adjustwidth}{}{20em}
441 \begin{lemma}\label{lem:result_it}
442 Alcuni risultati preliminari (vedi l'equazione \labelcref[used by]{eq:1_it}).
443 \end{lemma}
444
445 \begin{theorem}\label{thm:test_it}
446 Testo.
447 \end{theorem}
448 \begin{proof}\restorelabel{thm:test_it}
449 % Notice the use of \cref[da,...]
450 Alcune linee di prova derivanti \cref[da, used by]{lem:result_it} e dalle equazioni \labelcref[used by and on]{eq:Euler_it}, \labelcref[used by]{eq:1_it,eq:2_it}.
451 \end{proof}
452
453 \begin{equation}\label{eq:Euler_it}
454 \mathrm{e}^{\mathrm{i}\pi} + 1 = 0.
455 \end{equation}
456 \begin{align}
457 1 &= 0 + 1 \label{eq:1_it}\\
458 2 &= 1 + 1 \label{eq:2_it}
459 \end{align}
460 \end{adjustwidth}
461
462 \subsection{Example in Spanish}
463
464 \UseLanguage{Spanish}
465
466 \vspace{-1.5\baselineskip}
467 \setlength{\marginparwidth}{24em}
468 \setlength{\marginparsep}{-18em}
469 \begin{adjustwidth}{}{20em}
470 \begin{lemma}\label{lem:result_es}
471 Algunos resultados preliminares (véase la ecuación \labelcref[used by]{eq:1_es}).
472 \end{lemma}
473
474 \begin{theorem}\label{thm:test_es}
475 Texto.
476 \end{theorem}
477 \begin{proof}\restorelabel{thm:test_es}
478 % Notice the use of \cref[de,...]
479 Algunas líneas de demostración resultantes \cref[de, used by]{lem:result_es} y las ecuaciones \labelcref[used by and on]{eq:Euler_es}, \labelcref[used by]{eq:1_es,eq:2_es}.
480 \end{proof}
481
482 \begin{equation}\label{eq:Euler_es}
483 \mathrm{e}^{\mathrm{i}\pi} + 1 = 0.
484 \end{equation}
485 \begin{align}
486 1 &= 0 + 1 \label{eq:1_es}\\
487 2 &= 1 + 1 \label{eq:2_es}
488 \end{align}
489 \end{adjustwidth}
490
491 \UseLanguage{English}
492
493 \subsection{Regarding the customization for languages with declensions}
494
495 If you wish to change the content of the messages in such cases, you might need to be careful about the definite article and declension involved. For example, in German, if you wish to change the text to \textquote{Erscheint in ... auf ...} (\emph{Appears in ... on ...}), you need to write:
496 \begin{code}
497 \SetUsedOnMessageText{Erscheint auf~#1.}
498 \SetUsedByMessageText{Erscheint #1.}
499 \SetUsedByAndOnMessageText{Erscheint #1 auf~#2.}
500 \SetForwardReferenceRefForm{\crefthe[in,(*\commandoption{dat.}*)]}
501 \SetForwardReferencePagerefForm{\cpagerefthe[(*\commandoption{noun}*)]}
502 \end{code}
503 which set the \lstinline|\cref| command to use the definite article \textquote{in} and the declension \textquote{Dativ} (via the command option \commandoption{dat.}), and hide the definite article when using \lstinline|\cpageref| (via the command option \commandoption{noun}). For more detailed usage of these commands, please refer to the documentation of the package \textsf{crefthe}.
504
505
506 \end{document}