PageRenderTime 272ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/Master/texmf-dist/doc/latex/underoverlap/packagedoc.cls

https://bitbucket.org/preining/tex-live
Visual Basic for Applications | 315 lines | 270 code | 45 blank | 0 comment | 4 complexity | 691cee794034ef7c2a2113c110cadbd1 MD5 | raw file
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. % %
  3. % Copyright (C) 2012 by Michiel Helvensteijn - www.mhelvens.net %
  4. % %
  5. % This work may be distributed and/or modified under the %
  6. % conditions of the LaTeX Project Public License, either %
  7. % version 1.3 of this license or (at your option) any later %
  8. % version. The latest version of this license is in %
  9. % http://www.latex-project.org/lppl.txt %
  10. % and version 1.3 or later is part of all distributions of %
  11. % LaTeX version 2005/12/01 or later. %
  12. % %
  13. % This work has the LPPL maintenance status `author-maintained'. %
  14. % %
  15. % The Current Maintainer of this work is Michiel Helvensteijn. %
  16. % %
  17. % This work consists of the file packagedoc.cls. %
  18. % %
  19. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  20. \let\packagename\jobname
  21. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  22. % Document Class %
  23. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  24. \LoadClassWithOptions{ltxdoc}
  25. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  26. % Importing The Relevant Package %
  27. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  28. \RequirePackage{\packagename}
  29. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  30. % Importing Other Packages %
  31. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  32. \RequirePackage[hyphens]{url}
  33. \RequirePackage{etoolbox}
  34. \RequirePackage[xcolor]{mdframed}
  35. \RequirePackage{marginnote}
  36. \RequirePackage{listings}
  37. \RequirePackage{textcomp}
  38. \RequirePackage[pdftex,colorlinks=true]{hyperref}
  39. \RequirePackage{dry}
  40. \RequirePackage{needspace}
  41. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  42. % Documentation Options %
  43. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  44. \EnableCrossrefs
  45. \CodelineIndex
  46. \RecordChanges
  47. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  48. % File Info %
  49. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  50. \GetFileInfo{\packagename.sty}
  51. \title{The \textsf{\packagename} package\thanks{%
  52. This document corresponds to \textsf{\packagename}~\fileversion,
  53. dated \filedate.%
  54. }}
  55. \author{
  56. Michiel Helvensteijn\\
  57. \href{mailto:mhelvens+latex@gmail.com}{mhelvens+latex@gmail.com}
  58. }
  59. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  60. % Development Info %
  61. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  62. \newmdenv[
  63. leftline = false,
  64. rightline = false
  65. ]{bannerframe}
  66. \apptocmd{\maketitle}{
  67. \begin{bannerframe}
  68. \small
  69. \begin{center}
  70. Development of this package is organized at
  71. \href{http://latex-\packagename.googlecode.com}
  72. {latex-\packagename.googlecode.com}.\\
  73. I am happy to receive feedback there!
  74. \end{center}
  75. \end{bannerframe}
  76. }{}{}
  77. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  78. % Example Environment Setup %
  79. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  80. %%% Extra keywords for LaTeX
  81. %
  82. \newcommand{\moretexcs}[1]{
  83. \lstdefinelanguage{latex}{
  84. language=[LaTeX]tex,
  85. alsoletter={\[,\],\$},
  86. moretexcs={ExplSyntaxOn,ExplSyntaxOff,lstinputlisting,detokenize,[,],#1},
  87. keywords={\$}
  88. }
  89. }
  90. %%% Code formatting
  91. %
  92. \lstdefinestyle{examplecode}{%
  93. language=latex,%
  94. basicstyle=\ttfamily\small,%
  95. texcsstyle=*\bfseries,%
  96. keywordstyle=*\bfseries,%
  97. upquote=true%
  98. }
  99. %%% Setting up example code block
  100. %
  101. \definecolor{examplecodelinecolor}{rgb}{0,0,0}
  102. \definecolor{examplecodebackgroundcolor}{rgb}{.9,.9,.9}
  103. \newmdenv[
  104. linecolor = examplecodelinecolor,
  105. backgroundcolor = examplecodebackgroundcolor,
  106. skipabove = 0px,
  107. skipbelow = 0px,
  108. innertopmargin = -3px,
  109. innerrightmargin = 4px,
  110. innerbottommargin = -3px,
  111. innerleftmargin = 4px
  112. ]{examplecodeframe}
  113. %%% Defining example output block
  114. %
  115. \definecolor{exampleoutputbackgroundcolor}{rgb}{1,1,1}
  116. \newmdenv[
  117. linecolor = examplecodelinecolor,
  118. backgroundcolor = exampleoutputbackgroundcolor,
  119. skipabove = 0px,
  120. skipbelow = 0px,
  121. innertopmargin = 4px,
  122. innerrightmargin = 4px,
  123. innerbottommargin = 4px,
  124. innerleftmargin = 4px,
  125. nobreak = true
  126. ]{exampleoutputframe}
  127. %%% Macros for counting lines in file, adapted from
  128. %%% http://andreas.scherbaum.la/blog/archives/
  129. %%% 670-Read-number-lines-in-a-file-in-LaTeX.html
  130. %
  131. \RequirePackage{ifthen}
  132. \newboolean{packagedoc@restfile}
  133. \newcommand*{\packagedoc@fileline}{}
  134. \newread\packagedoc@file
  135. \newcommand*{\packagedoc@readnextline}[1]{%
  136. \ifthenelse{\boolean{packagedoc@restfile}}{%
  137. \read#1 to \packagedoc@fileline%
  138. \ifeof#1\setboolean{packagedoc@restfile}{false}%
  139. \else\fi%
  140. }{}%
  141. }
  142. \newcommand*{\countlinesinfile}[2]{%
  143. \setboolean{packagedoc@restfile}{true}%
  144. \setcounter{packagedoc@linecount}{0}%
  145. \openin\packagedoc@file=#1%
  146. \whiledo{\boolean{packagedoc@restfile}}{%
  147. \packagedoc@readnextline{\packagedoc@file}%
  148. \ifthenelse{\boolean{packagedoc@restfile}}{%
  149. \stepcounter{packagedoc@linecount}%
  150. }{}%
  151. }%
  152. \closein\packagedoc@file%
  153. \edef#2{\thepackagedoc@linecount}%
  154. }
  155. \newcounter{packagedoc@linecount}
  156. \newlength{\packagedoc@spacetoreserve}
  157. %%% DRYer without output
  158. %
  159. \NewDRYer{latex-example}{%
  160. \addvspace{6px}%
  161. {%
  162. \ttfamily\small%
  163. \countlinesinfile{#1}{\countedlines}%
  164. \setlength{\packagedoc@spacetoreserve}{\countedlines\baselineskip}%
  165. \addtolength{\packagedoc@spacetoreserve}{-4px}%
  166. \needspace{\packagedoc@spacetoreserve}%
  167. }%
  168. \begin{examplecodeframe}%
  169. \renewcommand{\ttdefault}{pcr}%
  170. \lstinputlisting[style=examplecode]{#1}%
  171. \end{examplecodeframe}%
  172. #2%
  173. \addvspace{6px}%
  174. }
  175. %%% DRYer WITH output but WITHOUT side-effects
  176. %
  177. \NewDRYer{latex-example-show}{%
  178. \addvspace{6px}%
  179. {%
  180. \ttfamily\small%
  181. \countlinesinfile{#1}{\countedlines}%
  182. \setlength{\packagedoc@spacetoreserve}{\countedlines\baselineskip}%
  183. \addtolength{\packagedoc@spacetoreserve}{\baselineskip}%
  184. \needspace{\packagedoc@spacetoreserve}%
  185. }%
  186. \begin{examplecodeframe}%
  187. \renewcommand{\ttdefault}{pcr}%
  188. \lstinputlisting[style=examplecode]{#1}%
  189. \end{examplecodeframe}\vspace{-4px}%
  190. \begin{exampleoutputframe}%
  191. #2%
  192. \end{exampleoutputframe}%
  193. \addvspace{6px}%
  194. }
  195. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  196. % Implementation Code Box Setup %
  197. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  198. %%% Saving old implementation code block font
  199. %
  200. \AtBeginDocument{\let\old@macro@font\macro@font}
  201. %%% Setup for 'interesting' implementation code blocks
  202. %
  203. \definecolor{interestingcodebackgroundcolor}{rgb}{.9,.9,.9}
  204. \definecolor{interestingcodelinecolor}{rgb}{0,0,0}
  205. \mdfdefinestyle{interestingcode}{
  206. linecolor = interestingcodelinecolor,
  207. backgroundcolor = interestingcodebackgroundcolor
  208. }
  209. \newcommand*{\interesting}{%
  210. \def\codestyle{interestingcode}%
  211. \def\codeskipabove{5px}%
  212. \let\macro@font\old@macro@font%
  213. }
  214. %%% Setup for 'UNinteresting' implementation code blocks
  215. %
  216. \definecolor{uninterestingcodebackgroundcolor}{rgb}{.97,.97,.97}
  217. \definecolor{uninterestingcodelinecolor}{rgb}{.5,.5,.5}
  218. \definecolor{uninterestingcodecolor}{rgb}{.4,.4,.4}
  219. \mdfdefinestyle{uninterestingcode}{
  220. linecolor = uninterestingcodelinecolor,
  221. backgroundcolor = uninterestingcodebackgroundcolor,
  222. }
  223. \newcommand*{\uninteresting}{%
  224. \def\codestyle{uninterestingcode}%
  225. \def\codeskipabove{-5px}%
  226. \def\macro@font{\color{uninterestingcodecolor}\old@macro@font}%
  227. }
  228. %%% Actually surround 'macrocode' with the frame
  229. %
  230. \surroundwithmdframed[
  231. style = \codestyle,
  232. skipabove = \codeskipabove,
  233. skipbelow = 5px,
  234. splittopskip = 10px,
  235. splitbottomskip = 4px,
  236. innertopmargin = 4px,
  237. innerrightmargin = 4px,
  238. innerbottommargin = 4px,
  239. innerleftmargin = 4px
  240. ]{macrocode}
  241. %%% Start out with 'interesting' code status and
  242. %%% always go back to it after one code block
  243. %
  244. \interesting
  245. \AfterEndEnvironment{macrocode}{\interesting}
  246. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  247. % Argument Specifiers and such %
  248. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  249. \newcommand*{\movarg}[1]{[ \texttt{#1} ]}
  250. \newcommand*{\momarg}[1]{[ \meta{#1} ]}
  251. \newcommand{\describemacro}[2]{%
  252. \needspace{3\baselineskip}%
  253. \noindent\\\DescribeMacro{#1} #2\\%
  254. }
  255. \newcommand{\describemetamacro}[2]{%
  256. \needspace{3\baselineskip}%
  257. \noindent\\\marginnote{\meta{#1}} #2\\%
  258. }
  259. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  260. % Automatic Implementation Docs %
  261. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  262. \AtEndDocument{
  263. \pagebreak
  264. \section{Implementation}
  265. \StopEventually {\PrintChanges}
  266. We now show and explain the entire implementation from \texttt{\packagename.sty}.
  267. \DocInput{\packagename.sty}
  268. \Finale
  269. \PrintIndex
  270. }