Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 % This is free and unencumbered software released into the public domain.
3 %
4 % Anyone is free to copy, modify, publish, use, compile, sell, or
5 % distribute this software, either in source code form or as a compiled
6 % binary, for any purpose, commercial or non-commercial, and by any
7 % means.
8 %
9 % In jurisdictions that recognize copyright laws, the author or authors
10 % of this software dedicate any and all copyright interest in the
11 % software to the public domain. We make this dedication for the benefit
12 % of the public at large and to the detriment of our heirs and
13 % successors. We intend this dedication to be an overt act of
14 % relinquishment in perpetuity of all present and future rights to this
15 % software under copyright law.
16 %
17 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 % IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 % OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 % ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 % OTHER DEALINGS IN THE SOFTWARE.
24 %
25 % For more information, please refer to <https://unlicense.org>
26 % \fi
27
28 % \iffalse
29 %<package>\NeedsTeXFormat{LaTeX2e}
30 %<package>\ProvidesPackage{atendofenv}[2022/02/24 v0.2 Prevent an infinite loop]
31 %<package>\RequirePackage{amsthm}
32 %<package>\RequirePackage{letltxmacro}
33 %<*driver>
34 \documentclass{ltxdoc}
35 \usepackage[T1]{fontenc}
36 \usepackage{mathpazo}
37 \usepackage[scale=0.85]{FiraMono}
38 \usepackage{FiraSans}
39 \usepackage[a4paper, margin=3cm]{geometry}
40 \usepackage{indentfirst}
41 \usepackage[hidelinks]{hyperref}
42 \usepackage{amssymb}
43 \usepackage{atendofenv}
44 \EnableCrossrefs
45 \CodelineIndex
46 \RecordChanges
47 \begin{document}
48 \DocInput{atendofenv.dtx}
49 \end{document}
50 %</driver>
51 % \fi
52 %
53 % \CheckSum{0}
54 %
55 % \CharacterTable
56 % {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
57 % 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
58 % Digits \0\1\2\3\4\5\6\7\8\9
59 % Exclamation \! Double quote \" Hash (number) \#
60 % Dollar \$ Percent \% Ampersand \&
61 % Acute accent \' Left paren \( Right paren \)
62 % Asterisk \* Plus \+ Comma \,
63 % Minus \- Point \. Solidus \/
64 % Colon \: Semicolon \; Less than \<
65 % Equals \= Greater than \> Question mark \?
66 % Commercial at \@ Left bracket \[ Backslash \\
67 % Right bracket \] Circumflex \^ Underscore \_
68 % Grave accent \` Left brace \{ Vertical bar \|
69 % Right brace \} Tilde \~}
70 %
71 %
72 % \GetFileInfo{atendofenv.sty}
73 %
74 % \title{At End of Env}
75 % \author{Fangyi Zhou}
76 % \maketitle
77 %
78 % \section{Motivation}
79 % The \texttt{amsthm} package conveniently provides environments for
80 % declaring theorems and friends.
81 % By default, the \texttt{proof} environment inserts a
82 % \href{https://en.wikipedia.org/wiki/Q.E.D.}{QED} symbol at the end of
83 % environment.
84 % It is sometimes also desirable to insert a similar symbol at the end of other
85 % environments, e.g.~at the end of a definition or a remark, which motivates
86 % this package.
87 %
88 % \section{Usage}
89 % Let us begin with defining a theorem environment with \texttt{amsthm}:
90 % \newtheorem{theorem}{Theorem}
91 % \begin{verbatim}
92 % \newtheorem{theorem}{Theorem}
93 % \end{verbatim}
94 % And we can create a theorem like this:
95 % \begin{verbatim}
96 % \begin{theorem}
97 % This is a long theorem that will be very long, and it will be helpful if I
98 % can add a symbol at the end of it to mark its end.
99 % \end{theorem}
100 % \end{verbatim}
101 % \begin{theorem}
102 % This is a long theorem that will be very long, and it will be helpful if I
103 % can add a symbol at the end of it to mark its end.
104 % \end{theorem}
105 % To do so, simply put after defining a theorem environment:
106 % \AtEndOfEnv{theorem}{$\triangleleft$}
107 % \begin{verbatim}
108 % \AtEndOfEnv{theorem}{$\triangleleft$}
109 % \end{verbatim}
110 % Now theorems look like this:
111 % \begin{theorem}
112 % This is a long theorem that will be very long, and it will be helpful if I
113 % can add a symbol at the end of it to mark its end.
114 % \end{theorem}
115 % You can also change the symbol later.
116 % \AtEndOfEnv{theorem}{$\lrcorner$}
117 % \begin{verbatim}
118 % \AtEndOfEnv{theorem}{$\lrcorner$}
119 % \end{verbatim}
120 % Now theorems look like this:
121 % \begin{theorem}
122 % This is a long theorem that will be very long, and it will be helpful if I
123 % can add a symbol at the end of it to mark its end.
124 % \end{theorem}
125 % \noindent
126 % \textbf{Q:} \emph{But, couldn't I change tweak the style of theorems when defining them?}
127 %
128 % \noindent
129 % \textbf{A:} Of course, but sometimes they are defined by a class file (e.g.~from
130 % publishers), and tweaking class files may be a sin in many situations.
131 %
132 % \section{Implementation}
133 % \begin{macrocode}
134 \newcommand{\AtEndOfEnv}[2]{
135 % \end{macrocode}
136 % We first check whether the environment is defined. If so, save the original
137 % macros (if not saved already); otherwise report an error.
138 % \changes{0.2}{2022/02/24}{Fix an infinite loop when trying to change the
139 % symbol for the same environment twice.}
140 % \begin{macrocode}
141 \ifcsname #1\endcsname
142 \ifcsname aeoe@old#1\endcsname\relax
143 \else
144 \expandafter\LetLtxMacro\csname aeoe@old#1\expandafter\endcsname\csname #1\endcsname
145 \fi
146 \else
147 \PackageError{atendofenv}{Environment #1 undefined}{Check the environment
148 name passed to AtEndOfEnv}
149 \fi
150 \ifcsname end#1\endcsname
151 \ifcsname aeoe@oldend#1\endcsname\relax
152 \else
153 \expandafter\LetLtxMacro\csname aeoe@oldend#1\expandafter\endcsname\csname end#1\endcsname
154 \fi
155 \else
156 \PackageError{atendofenv}{Environment #1 undefined}{Check the environment
157 name passed to AtEndOfEnv}
158 \fi
159 % \end{macrocode}
160 % Then we redefine the environment, and use the QED stack of \texttt{amsthm}
161 % to get a symbol at the end.
162 % \begin{macrocode}
163 \renewenvironment{#1}
164 {\pushQED{\qed}\renewcommand{\qedsymbol}{#2}\expandafter\csname aeoe@old#1\endcsname}
165 {\popQED\expandafter\csname aeoe@oldend#1\endcsname}
166 }
167 % \end{macrocode}
168 % \Finale