-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtthesis-example.sty
193 lines (177 loc) · 6.4 KB
/
rtthesis-example.sty
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
\ProvidesPackage{rtthesis-example}[2010/02/18 The example environment of the rtthesis class]
% Same dependency on rtthesis-captions as found in rtthesis-theorems.sty.
\@ifpackageloaded{rtthesis-captions}{}{% If not loaded...
\PackageError{rtthesis-example}{%
The package rtthesis-captions must be loaded\MessageBreak
before rtthesis-example. Since\MessageBreak
rtthesis-example cannot guess which\MessageBreak
character encoding you prefer, it won't\MessageBreak
load rtthesis-captions for you, so you have\MessageBreak
to do it yourself%
}{%
The package rtthesis-captions must be loaded\MessageBreak
before rtthesis-example. Since\MessageBreak
rtthesis-example cannot guess which\MessageBreak
character encoding you prefer, it won't\MessageBreak
load rtthesis-captions for you, so you have\MessageBreak
to do it yourself%
}
}
% Use same counter for theorem-like environments?
\newif\ifrtex@shareTheoremCounter
\DeclareOption{sharecounter}{\rtex@shareTheoremCountertrue}
\DeclareOption{nosharecounter}{\rtex@shareTheoremCounterfalse}
\ExecuteOptions{nosharecounter}
% Use parskip.sty and adjust sectioning commands?
\newif\ifrtex@parskip
\newif\ifrtex@parskipDefault
\rtex@parskipDefaulttrue
\DeclareOption{noparskip}{\rtex@parskipfalse\rtex@parskipDefaultfalse}
\DeclareOption{parskip}{\rtex@parskiptrue\rtex@parskipDefaultfalse}
\@ifpackageloaded{parskip}{%
\rtex@parskiptrue
}{% In case KpFonts was not loaded:
\rtex@parskipfalse
\AtBeginDocument{%
\ifrtex@parskipDefault
\@ifpackageloaded{parskip}{%
\PackageWarningNoLine{rtthesis-example}{%
The default setting regarding `parskip' or\MessageBreak
`noparskip' is `noparskip' since package\MessageBreak
parskip was loaded after \MessageBreak
rtthesis-example. This is probably not\MessageBreak
what you want. Avoid this warning by\MessageBreak
explicitly passing one of the options\MessageBreak
`parskip' or `noparskip', or change the\MessageBreak
package loading order
}}{}%
\fi
}
}
% When should counters be reset?
% Use same counter for theorem-like environments?
\newif\ifrtex@resetchapter
\DeclareOption{reset=chapter}{\rtex@resetchaptertrue}
\DeclareOption{reset=section}{\rtex@resetchapterfalse}
\@ifundefined{thechapter}{%
\ExecuteOptions{reset=section}}{%
\ExecuteOptions{reset=chapter}}
\ProcessOptions\relax
\RequirePackage{needspace}
\DeclareRobustCommand*{\listofexamples}{%
\section*{\listexamplename}%
\@starttoc{xmp}%
}
\newcommand*{\l@example}{\l@figure}%
\ifrtex@resetchapter
\newcounter{Example}[chapter]%
\renewcommand*{\theExample}{\thechapter.\arabic{Example}}%
\else
\newcounter{Example}[section]%
\renewcommand*{\theExample}{\arabic{Example}}%
\fi
\newlength{\exampleLineWidth}
\setlength{\exampleLineWidth}{.6pt}
\newlength{\exampleTopBotInnerMargin}
\setlength{\exampleTopBotInnerMargin}{2ex}
\newlength{\exampleTopBotOuterMargin}
\setlength{\exampleTopBotOuterMargin}{1em plus 1ex minus 1ex}
\newenvironment{example}[1][]{%
\ifrtex@shareTheoremCounter
\refstepcounter{theorem}%
\else
\refstepcounter{Example}%
\fi
\sbox{\@tempboxa}{\ignorespaces#1\unskip}%
\ifdim \wd\@tempboxa>\z@%
\sbox{\@tempboxa}{%
\textbf{%
\ifrtex@shareTheoremCounter
\thinspace\thetheorem\enspace\ignorespaces\examplename\unskip:~#1\thinspace%
\else
\thinspace\ignorespaces\examplename\unskip~\theExample:~#1\thinspace%
\fi
}}%
\else%
\sbox{\@tempboxa}{\textbf{%
\ifrtex@shareTheoremCounter
\thinspace\thetheorem\enspace\ignorespaces\examplename\thinspace
\else
\thinspace\ignorespaces\examplename~\theExample\thinspace
\fi
}}%
\fi%
\ifrtex@shareTheoremCounter
\addcontentsline{xmp}{example}{\protect\numberline{\thetheorem}#1}%
\else
\addcontentsline{xmp}{example}{\protect\numberline{\theExample}#1}%
\fi
\@example%
}%
{\@endexample}
\newenvironment{example*}[1][]{% Stared version w/o numbering
\sbox{\@tempboxa}{\ignorespaces#1\unskip}%
\ifdim \wd\@tempboxa>\z@%
\sbox{\@tempboxa}{\textbf{%
\thinspace\ignorespaces\examplename:~#1\thinspace}}%
\else%
\sbox{\@tempboxa}{\textbf{%
\thinspace\examplename\thinspace}}%
\fi%
\@example%
}%
{\@endexample}
\newlength{\rt@examplerulepos}
\newcommand*\@example{% Start of example environmets
\setlength{\@tempskipa}{\linewidth}%
\addtolength{\@tempskipa}{-\wd\@tempboxa}%
\addtolength{\@tempskipa}{-1em}%
\par% Enforce vmode
\addtolength{\exampleTopBotOuterMargin}{-\parskip}% Change temporarily to compensate for parskip
\addvspace{\exampleTopBotOuterMargin}%
\addtolength{\exampleTopBotOuterMargin}{\parskip}%
\pagebreak[2]%
\Needspace*{5\baselineskip}% 5 could seem a bit too much, but 4 has failed to solve the page breaking problem on a few occasions.
\noindent
\rlap{%
\hspace*{-\exampleLineWidth}\hspace*{-.5em}%
\rule[\exampleLineWidth]{\exampleLineWidth}{1ex}%
\rule[1ex]{2em}{\exampleLineWidth}%
\raisebox{.6ex}{\box\@tempboxa}%
\rule[1ex]{\@tempskipa}{\exampleLineWidth}%
\rule[\exampleLineWidth]{\exampleLineWidth}{1ex}}%
\settoheight{\rt@examplerulepos}{X}%
\addtolength{\rt@examplerulepos}{-\baselineskip}%
\addtolength{\rt@examplerulepos}{-1ex}%
\addtolength{\rt@examplerulepos}{\exampleTopBotInnerMargin}%
\nopagebreak[4]\\[\rt@examplerulepos]%
\begingroup\@afterindentfalse\nopagebreak[4]\ignorespaces%
}
\newcommand*\@endexample{% End of example environments
\unskip% This one matters, but only in rare occasions!
\endgroup
\ifvmode
\nopagebreak[4]\vspace{-\baselineskip}\vspace{-\parskip}%
\fi
\ifhmode
\\[-\baselineskip]%
\fi
\noindent
\setlength{\rt@examplerulepos}{-\exampleTopBotInnerMargin}%
\addtolength{\rt@examplerulepos}{-\exampleLineWidth}%
\nopagebreak[4]%
\begin{picture}(0,0)
\put(0,0){\rlap{%
\hspace*{-\exampleLineWidth}\hspace*{-.5em}%
\rule[\rt@examplerulepos]{\exampleLineWidth}{1ex}%
\addtolength{\linewidth}{1em}% Make a rule that is \linewidth+1em long by temporarily changing \linewidth.
\rule[\rt@examplerulepos]{\linewidth}{\exampleLineWidth}%
\addtolength{\linewidth}{-1em}%
\rule[\rt@examplerulepos]{\exampleLineWidth}{1ex}%
}}
\end{picture}%
\vspace{-\rt@examplerulepos}%
\vspace{-\parskip}\par\addvspace{\exampleTopBotOuterMargin}
\pagebreak[2]%
\ignorespacesafterend%
}