rtthesis-theorems.sty 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. \ProvidesPackage{rtthesis-theorems}[2010/02/18 Theorem-like environments for the rtthesis class]
  2. \@ifpackageloaded{rtthesis-captions}{}{% If not loaded...
  3. \PackageError{rtthesis-theorems}{%
  4. The package rtthesis-captions must be loaded\MessageBreak
  5. before rtthesis-theorems. Since\MessageBreak
  6. rtthesis-theorems cannot guess which\MessageBreak
  7. character encoding you prefer, it won't\MessageBreak
  8. load rtthesis-captions for you, so you have\MessageBreak
  9. to do it yourself%
  10. }{%
  11. The package rtthesis-captions must be loaded\MessageBreak
  12. before rtthesis-theorems. Since\MessageBreak
  13. rtthesis-theorems cannot guess which\MessageBreak
  14. character encoding you prefer, it won't\MessageBreak
  15. load rtthesis-captions for you, so you have\MessageBreak
  16. to do it yourself%
  17. }
  18. }
  19. % Use same counter for theorem-like environments?
  20. \newif\ifrtthm@shareTheoremCounter
  21. \DeclareOption{sharecounter}{\rtthm@shareTheoremCountertrue}
  22. \DeclareOption{nosharecounter}{\rtthm@shareTheoremCounterfalse}
  23. \ExecuteOptions{nosharecounter}
  24. % Put breaks after theorem (and similar) labels?
  25. \newif\ifrtthm@break
  26. \DeclareOption{break}{\rtthm@breaktrue}
  27. \DeclareOption{nobreak}{\rtthm@breakfalse}
  28. \ExecuteOptions{nobreak}
  29. % Choice of definition style
  30. \newif\ifrt@definitionNotTheorem
  31. \newif\ifrt@definitionMarks
  32. \DeclareOption{definition=theorem}{\rt@definitionNotTheoremfalse}
  33. \DeclareOption{definition=naked}{\rt@definitionNotTheoremtrue\rt@definitionMarksfalse}
  34. \DeclareOption{definition=marks}{\rt@definitionNotTheoremtrue\rt@definitionMarkstrue}
  35. \ExecuteOptions{definition=naked}
  36. % Should we use italics or slanted text in theorems?
  37. \newif\ifrtthm@slanted
  38. \DeclareOption{slanted}{\rtthm@slantedtrue}
  39. \DeclareOption{italics}{\rtthm@slantedfalse}
  40. \ExecuteOptions{italics}
  41. % Use parskip.sty and adjust sectioning commands?
  42. \newif\ifrtthm@parskipDefault
  43. \rtthm@parskipDefaulttrue
  44. \newif\ifrtthm@parskip
  45. \DeclareOption{noparskip}{\rtthm@parskipfalse\rtthm@parskipDefaultfalse}
  46. \DeclareOption{parskip}{\rtthm@parskiptrue\rtthm@parskipDefaultfalse}
  47. \@ifpackageloaded{parskip}{%
  48. \rtthm@parskiptrue
  49. }{% In case KpFonts was not loaded:
  50. \rtthm@parskipfalse
  51. \AtBeginDocument{%
  52. \ifrtthm@parskipDefault
  53. \@ifpackageloaded{parskip}{%
  54. \PackageWarningNoLine{rtthesis-theorems}{%
  55. The default setting regarding `parskip' or\MessageBreak
  56. `noparskip' is `noparskip' since package\MessageBreak
  57. parskip was loaded after \MessageBreak
  58. rtthesis-theorems. This is probably not\MessageBreak
  59. what you want. Avoid this warning by\MessageBreak
  60. explicitly passing one of the options\MessageBreak
  61. `parskip' or `noparskip', or change the\MessageBreak
  62. package loading order
  63. }}{}%
  64. \fi
  65. }
  66. }
  67. % When should counters be reset?
  68. % Use same counter for theorem-like environments?
  69. \DeclareOption{reset=chapter}{\def\rtthm@reset{chapter}}
  70. \DeclareOption{reset=section}{\def\rtthm@reset{section}}
  71. \@ifundefined{thechapter}{%
  72. \ExecuteOptions{reset=section}}{%
  73. \ExecuteOptions{reset=chapter}}
  74. \ProcessOptions\relax
  75. \RequirePackage{amsthm}
  76. \ifrtthm@slanted
  77. % It's dangerous to use the italic shape, since italic small caps seem hard to find.
  78. \let\theoremshape\slshape
  79. \else
  80. \let\theoremshape\itshape
  81. \fi
  82. \newlength{\rt@theoremtopskip}
  83. \ifrtthm@parskip
  84. \setlength{\rt@theoremtopskip}{1.5\parskip plus 1.5pt}
  85. \else
  86. \setlength{\rt@theoremtopskip}{0.5em plus 1.5pt}
  87. \fi
  88. % In case the user adjusts this length, and later decides not to use marks, we define the following length no matter whether marks are used or not.
  89. \newlength{\rt@definitionlinewidth}
  90. \setlength{\rt@definitionlinewidth}{0.3pt}
  91. \ifrt@definitionMarks
  92. \newcommand{\rt@definitionBeginMark}{%
  93. \begin{picture}(0,0)
  94. \settoheight{\unitlength}{(D)}
  95. \linethickness{\rt@definitionlinewidth}
  96. \put(-0.3,1.3){\line(0,-1){0.5}}
  97. \put(-0.3,1.3){\line(1,0){4}}
  98. \end{picture}%
  99. }
  100. \newcommand{\rt@definitionEndMark}{%
  101. \unskip
  102. % Whether we are in vmode here seems to depend on whether we are using parskip...
  103. \ifrtthm@parskip
  104. \ifvmode
  105. \nopagebreak\vspace{-\baselineskip}%
  106. \fi
  107. \fi
  108. \ifhmode
  109. \nopagebreak\\[-1\baselineskip]%
  110. \fi
  111. \nopagebreak\hspace*{\linewidth}%
  112. \begin{picture}(0,0)
  113. \settoheight{\unitlength}{(D)}
  114. \linethickness{\rt@definitionlinewidth}
  115. \put(0.3,-0.3){\line(0,1){0.5}}
  116. \put(0.3,-0.3){\line(-1,0){4}}
  117. \end{picture}%
  118. }
  119. \newcommand{\rt@topmarkskip}{%
  120. \settoheight{\unitlength}{(D)}%
  121. \ifhmode
  122. \par\vspace{-\rt@theoremtopskip}\vspace{0.3\unitlength}%
  123. \else
  124. \setlength{\unitlength}{0.3\unitlength}%
  125. \addtolength{\unitlength}{\parskip}
  126. \addvspace{\unitlength}%
  127. \fi
  128. }
  129. \newcommand{\rt@botmarkskip}{%
  130. \settoheight{\unitlength}{(D)}%
  131. \setlength{\unitlength}{0.3\unitlength}%
  132. \addtolength{\unitlength}{\parskip}
  133. \addvspace{\unitlength}%
  134. %%% The following line does more than just cancelling the \addtolength{\unitlength}{\parskip} above.
  135. \rt@unparskip% Next thing that happens will probably be a \par, but we don't want that extra \parskip.
  136. %
  137. %%% By leaving TeX in hmode, it might be possible to continue the paragraph right after the environment...
  138. %%% but how exactly should this be done?!
  139. %%% One should probably redefine \par temporarily so that it produces the correct after-theorem space and then
  140. %%% resets itself to the usual \par. This would work as long as a \par is actually the first thing that follows
  141. %%% the environment. However, if the user really continues to add stuff in hmode, then this must be detected so that
  142. %%% we can reset \par to its usual meaning before the user leaves hmode. The important question seems to be:
  143. %%% How can we detect that the user is adding stuff in hmode before we reach the next \par?
  144. }
  145. \else
  146. \newcommand{\rt@definitionBeginMark}{\relax}
  147. \newcommand{\rt@definitionEndMark}{\relax}
  148. \newcommand{\rt@topmarkskip}{%
  149. \ifhmode
  150. \par\vspace{-\rt@theoremtopskip}%
  151. \fi
  152. }
  153. \newcommand{\rt@botmarkskip}{%
  154. \rt@unparskip
  155. %
  156. %%% By leaving TeX in hmode, it might be possible to continue the paragraph right after the environment...
  157. %%% See comments above.
  158. }
  159. \fi
  160. \ifrtthm@shareTheoremCounter
  161. \newtheoremstyle{break}{\rt@theoremtopskip}{\rt@theoremtopskip}{\theoremshape}{}{\bfseries}{}
  162. {\newline}{\thmname{#1}~\thmnumber{#2}\thmnote{~(#3)}}
  163. \newtheoremstyle{nobreak}{\rt@theoremtopskip}{\rt@theoremtopskip}{\theoremshape}{}{\bfseries}{.}
  164. {.75em}{\thmname{#1}~\thmnumber{#2}\thmnote{~(#3)}}
  165. \newtheoremstyle{definition}{\rt@theoremtopskip}{\rt@theoremtopskip}{\normalfont}{}{\bfseries}{.}
  166. {.75em}{\rt@definitionBeginMark\thmname{#1}~\thmnumber{#2}\thmnote{~(#3)}}
  167. \newtheoremstyle{remark}{\rt@theoremtopskip}{\rt@theoremtopskip}{\normalfont\small}{}{\slshape}{.}
  168. {.75em}{\rt@definitionBeginMark\thmname{#1}~\thmnumber{#2}\thmnote{~(#3)}}
  169. \else
  170. \newtheoremstyle{break}{\rt@theoremtopskip}{\rt@theoremtopskip}{\theoremshape}{}{\bfseries}{}
  171. {\newline}{\thmname{#1}~\thmnumber{#2}\thmnote{~(#3)}}
  172. \newtheoremstyle{nobreak}{\rt@theoremtopskip}{\rt@theoremtopskip}{\theoremshape}{}{\bfseries}{.}
  173. {.75em}{\thmname{#1}~\thmnumber{#2}\thmnote{~(#3)}}
  174. \newtheoremstyle{definition}{\rt@theoremtopskip}{\rt@theoremtopskip}{\normalfont}{}{\bfseries}{.}
  175. {.75em}{\rt@definitionBeginMark\thmname{#1}~\thmnumber{#2}\thmnote{~(#3)}}
  176. \newtheoremstyle{remark}{\rt@theoremtopskip}{\rt@theoremtopskip}{\normalfont\small}{}{\slshape}{.}
  177. {.75em}{\rt@definitionBeginMark\thmname{#1}~\thmnumber{#2}\thmnote{~(#3)}}
  178. \fi
  179. \ifrtthm@break
  180. \theoremstyle{break}
  181. \else
  182. \theoremstyle{nobreak}
  183. \fi
  184. \ifrtthm@shareTheoremCounter
  185. \newtheorem{theorem}{\theoremname}[\rtthm@reset]
  186. \newtheorem{lemma}[theorem]{\lemmaname}
  187. \newtheorem{corollary}[theorem]{\corollaryname}
  188. \newtheorem{proposition}[theorem]{\propositionname}
  189. \else
  190. \newtheorem{theorem}{\theoremname}[\rtthm@reset]
  191. \newtheorem{lemma}{\lemmaname}[\rtthm@reset]
  192. \newtheorem{corollary}{\corollaryname}[\rtthm@reset]
  193. \newtheorem{proposition}{\propositionname}[\rtthm@reset]
  194. \fi
  195. \ifrt@definitionNotTheorem
  196. \theoremstyle{definition}% Change theorem style unless the user prefers to use the break/nobreak style also for definitions.
  197. \fi
  198. \ifrtthm@shareTheoremCounter
  199. \newtheorem{rt@definition}[theorem]{\definitionname}
  200. \newtheorem{rt@assumption}[theorem]{\assumptionname}
  201. \else
  202. \newtheorem{rt@definition}{\definitionname}[\rtthm@reset]
  203. \newtheorem{rt@assumption}{\assumptionname}[\rtthm@reset]
  204. \fi
  205. \renewcommand*{\thert@assumption}{A\arabic{rt@assumption}}
  206. \newenvironment{definition}{\rt@topmarkskip\begin{rt@definition}}{\rt@definitionEndMark\end{rt@definition}\rt@botmarkskip}
  207. \newenvironment{assumption}{\rt@topmarkskip\begin{rt@assumption}}{\rt@definitionEndMark\end{rt@assumption}\rt@botmarkskip}
  208. \theoremstyle{remark}
  209. \ifrtthm@shareTheoremCounter
  210. \newtheorem{rt@remark}[theorem]{\remarkname}
  211. \else
  212. \newtheorem{rt@remark}{\remarkname}[\rtthm@reset]
  213. \fi
  214. \newenvironment{remark}{\rt@topmarkskip\begin{rt@remark}}{\rt@definitionEndMark\end{rt@remark}\rt@botmarkskip}
  215. \renewenvironment{proof}[1][\proofname]{\par
  216. \pushQED{\qed}%
  217. \normalfont \topsep6\p@\@plus6\p@\relax
  218. \trivlist
  219. \item[\hskip\labelsep\bfseries#1\@addpunct{:}]\ignorespaces
  220. }{%
  221. \popQED\endtrivlist\@endpefalse
  222. }
  223. \ifrtthm@parskip
  224. \newcommand{\rt@unparskip}{%
  225. \vspace{-\parskip}% It's hard to know which is best of \addvspace and \vspace here...
  226. }
  227. %%% Adjust space before proof environment
  228. \let\ams@proof\proof
  229. \let\ams@endproof\endproof
  230. \renewenvironment{proof}{\rt@unparskip\ams@proof}{\ams@endproof}
  231. \else
  232. \newcommand{\rt@unparskip}{\relax}
  233. \fi