summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/atendofenv/atendofenv.dtx
blob: f01d321214fd24972bad8432898dd797028734a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
% \iffalse meta-comment
% This is free and unencumbered software released into the public domain.
%
% Anyone is free to copy, modify, publish, use, compile, sell, or
% distribute this software, either in source code form or as a compiled
% binary, for any purpose, commercial or non-commercial, and by any
% means.
%
% In jurisdictions that recognize copyright laws, the author or authors
% of this software dedicate any and all copyright interest in the
% software to the public domain. We make this dedication for the benefit
% of the public at large and to the detriment of our heirs and
% successors. We intend this dedication to be an overt act of
% relinquishment in perpetuity of all present and future rights to this
% software under copyright law.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
% IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
% OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
% ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
% OTHER DEALINGS IN THE SOFTWARE.
%
% For more information, please refer to <https://unlicense.org>
% \fi

% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{atendofenv}[2022/02/24 v0.2 Prevent an infinite loop]
%<package>\RequirePackage{amsthm}
%<package>\RequirePackage{letltxmacro}
%<*driver>
\documentclass{ltxdoc}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\usepackage[scale=0.85]{FiraMono}
\usepackage{FiraSans}
\usepackage[a4paper, margin=3cm]{geometry}
\usepackage{indentfirst}
\usepackage[hidelinks]{hyperref}
\usepackage{amssymb}
\usepackage{atendofenv}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{atendofenv.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{0}
%
% \CharacterTable
%  {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
%   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
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \GetFileInfo{atendofenv.sty}
%
% \title{At End of Env}
% \author{Fangyi Zhou}
% \maketitle
%
% \section{Motivation}
% The \texttt{amsthm} package conveniently provides environments for
% declaring theorems and friends.
% By default, the \texttt{proof} environment inserts a
% \href{https://en.wikipedia.org/wiki/Q.E.D.}{QED} symbol at the end of
% environment.
% It is sometimes also desirable to insert a similar symbol at the end of other
% environments, e.g.~at the end of a definition or a remark, which motivates
% this package.
%
% \section{Usage}
% Let us begin with defining a theorem environment with \texttt{amsthm}:
% \newtheorem{theorem}{Theorem}
% \begin{verbatim}
% \newtheorem{theorem}{Theorem}
% \end{verbatim}
% And we can create a theorem like this:
% \begin{verbatim}
% \begin{theorem}
%   This is a long theorem that will be very long, and it will be helpful if I
%   can add a symbol at the end of it to mark its end.
% \end{theorem}
% \end{verbatim}
% \begin{theorem}
%   This is a long theorem that will be very long, and it will be helpful if I
%   can add a symbol at the end of it to mark its end.
% \end{theorem}
% To do so, simply put after defining a theorem environment:
% \AtEndOfEnv{theorem}{$\triangleleft$}
% \begin{verbatim}
% \AtEndOfEnv{theorem}{$\triangleleft$}
% \end{verbatim}
% Now theorems look like this:
% \begin{theorem}
%   This is a long theorem that will be very long, and it will be helpful if I
%   can add a symbol at the end of it to mark its end.
% \end{theorem}
% You can also change the symbol later.
% \AtEndOfEnv{theorem}{$\lrcorner$}
% \begin{verbatim}
% \AtEndOfEnv{theorem}{$\lrcorner$}
% \end{verbatim}
% Now theorems look like this:
% \begin{theorem}
%   This is a long theorem that will be very long, and it will be helpful if I
%   can add a symbol at the end of it to mark its end.
% \end{theorem}
% \noindent
% \textbf{Q:} \emph{But, couldn't I change tweak the style of theorems when defining them?}
%
% \noindent
% \textbf{A:} Of course, but sometimes they are defined by a class file (e.g.~from
% publishers), and tweaking class files may be a sin in many situations.
%
% \section{Implementation}
%    \begin{macrocode}
\newcommand{\AtEndOfEnv}[2]{
%    \end{macrocode}
% We first check whether the environment is defined. If so, save the original
% macros (if not saved already); otherwise report an error.
% \changes{0.2}{2022/02/24}{Fix an infinite loop when trying to change the
% symbol for the same environment twice.}
%    \begin{macrocode}
  \ifcsname #1\endcsname
    \ifcsname aeoe@old#1\endcsname\relax
    \else
    \expandafter\LetLtxMacro\csname aeoe@old#1\expandafter\endcsname\csname #1\endcsname
    \fi
  \else
    \PackageError{atendofenv}{Environment #1 undefined}{Check the environment
    name passed to AtEndOfEnv}
  \fi
  \ifcsname end#1\endcsname
    \ifcsname aeoe@oldend#1\endcsname\relax
    \else
    \expandafter\LetLtxMacro\csname aeoe@oldend#1\expandafter\endcsname\csname end#1\endcsname
    \fi
  \else
    \PackageError{atendofenv}{Environment #1 undefined}{Check the environment
    name passed to AtEndOfEnv}
  \fi
%    \end{macrocode}
% Then we redefine the environment, and use the QED stack of \texttt{amsthm}
% to get a symbol at the end.
%    \begin{macrocode}
  \renewenvironment{#1}
  {\pushQED{\qed}\renewcommand{\qedsymbol}{#2}\expandafter\csname aeoe@old#1\endcsname}
  {\popQED\expandafter\csname aeoe@oldend#1\endcsname}
}
%    \end{macrocode}
% \Finale