Home My Page Projects Code Snippets Project Openings diderot
 Summary Activity Tracker Tasks SCM

# SCM Repository

[diderot] Annotation of /branches/pure-cfg/doc/report/code.sty
 [diderot] / branches / pure-cfg / doc / report / code.sty

# Annotation of /branches/pure-cfg/doc/report/code.sty

Revision 477 - (view) (download) (as text)

 1 : jhr 97 % code.sty: -*- latex -*- 2 : % Latex macros for a "weak" verbatim mode. 3 : % -- like verbatim, except \, {, and } have their usual meanings. 4 : 5 : % Environments: code, tightcode, codeaux, codebox, centercode 6 : % Commands: \dcd, \cddollar, \cdmath, \cd, \codeallowbreaks, \codeskip, \^ 7 : % Already defined in LaTeX, but of some relevance: \#, \$, \%, \&, \_, \{, \} 8 : 9 : % Changelog at the end of the file. 10 : 11 : % These commands give you an environment, code, that is like verbatim 12 : % except that you can still insert commands in the middle of the environment: 13 : % \begin{code} 14 : % for(x=1; x] option, then the following newline will 219 : % be read *after* ^M is bound to \cr, so we're cool. If there isn't 220 : % an option given (i.e., default to [c]), then the @\ifnextchar will 221 : % gobble up the newline as it gobbles whitespace. So we insert the 222 : % \cr explicitly. Isn't TeX fun? 223 : \def\codebox{\leavevmode\@ifnextchar[{\@codebox}{\@codebox[c]\cr}} %] 224 : 225 : \def\@codebox[#1]% 226 : {\hbox\bgroup$\if #1t\vtop \else \if#1b\vbox \else \vcenter \fi\fi\bgroup% 227 : \tabskip\z@\setupdisplaycode\cd@obeycr% just before cd@obey 228 : \halign\bgroup##\hfil\span} 229 : 230 : \def\endcodebox{\crcr\egroup\egroup\m@th$\egroup} 231 : 232 : % Center the box on the page: 233 : \newenvironment{centercode}% 234 : {\begin{center}\begin{codebox}[c]}% 235 : {\end{codebox}\end{center}} 236 : 237 : 238 : %% code, codeaux, tightcode 239 : %%============================================================================= 240 : %% Code environment as described above. Lines are kept on one page. 241 : %% This actually works by setting a huge penalty for breaking 242 : %% between lines of code. Code is indented same as other displayed paras. 243 : %% Note: to increase left margin, use \begin{codeaux}{\leftmargin=1in}. 244 : 245 : % To allow pagebreaks, say \codeallowbreaks immediately inside the env. 246 : % You can allow breaks at specific lines with a \pagebreak form. 247 : 248 : %% N.B.: The \global\@ignoretrue command must be performed just inside 249 : %% the *last* \end{...} before the following text. If not, you will 250 : %% get an extra space on the following line. Blech. 251 : 252 : %% This environment takes two arguments. 253 : %% The second, required argument is the \list parameters to override the 254 : %% \@listi... defaults. 255 : %% - Usefully set by clients: \topsep \leftmargin 256 : %% - Possible, but less useful: \partopsep 257 : %% The first, optional argument is the extra \parskip glue that you get around 258 : %% \list environments. It defaults to the value of \parskip. 259 : \newenvironment{codeaux}[2][\parskip]{% 260 : \bgroup% 261 : \setlength{\parskip}{#1}% 262 : \begin{list}{}{% 263 : \setlength{\partopsep}{0pt}% 264 : \setlength{\topsep}{0pt}% 265 : \setlength{\parsep}{0pt}% 266 : \setlength{\itemsep}{0pt}% 267 : \setlength{\listparindent}{0pt}% 268 : \setlength{\leftmargin}{\codeindent}% 269 : #2% 270 : }% 271 : \item[]\setupdisplaycode\cd@obeylines% 272 : }{% 273 : \end{list}\leavevmode\egroup\ignorespaces\global\@ignoretrue% 274 : } 275 : 276 : %% Code env is codeaux with the default margin and spacing \list params: 277 : \newenvironment{code}{\begin{codeaux}{}}{\end{codeaux}} 278 : 279 : %% Like code, but with no extra vertical space above and below. 280 : \newenvironment{tightcode}{\begin{codeaux}[0pt]{}}{\end{codeaux}} 281 : 282 : 283 : % Reasonable separation between lines of code 284 : \newcommand{\codeskip}{\penalty0\vspace{2ex}} 285 : 286 : 287 : % \cd is used to build a code environment in the middle of text. 288 : % Note: only difference from display code is that cr's are taken 289 : % as unbreakable spaces instead of linebreaks. 290 : 291 : \def\cd{\leavevmode\begingroup\ifmmode\let\startcode=\startmcode\else% 292 : \let\startcode\starttcode\fi% 293 : \setupcode\cd@obeycrsp\startcode} 294 : 295 : \def\cdm{\leavevmode\begingroup\ifmmode\let\startcode=\startmcode\else% 296 : \let\startcode\starttcode\fi% 297 : \setupcode\cd@obeycrsp\cd@mathspecial\startcode} 298 : 299 : \def\starttcode#1{#1\endgroup} 300 : %\def\startmcode#1{\hbox{#1}\endgroup} %% changed hbox to mbox --- JHR 301 : \def\startmcode#1{\mbox{#1}\endgroup} 302 : 303 : 304 : % Restore$&#^_~% to their normal catcodes 305 : % Define \^ to give the ^ char. 306 : % \dcd points to this guy inside a code env. 307 : \def\cd@dcd{\catcode\$=3\catcode\&=4\catcode\#=6\catcode\^=7% 308 : \catcode\_=8\catcode\~=13\catcode\%=14\def\^{\char\^}} 309 : 310 : % Selectively enable$, and $^_ as special. 311 : % \cd@mathspecial also defines \^ give the ^ char. 312 : % \cddollar and \cdmath point to these guys inside a code env. 313 : \def\cd@dollarspecial{\catcode\$=3} 314 : \def\cd@mathspecial{\catcode\$=3\catcode\^=7\catcode\_=8% 315 : \def\^{\char\^}} 316 : 317 : 318 : % Change log: 319 : % Started off as some macros found in C. Rich's library. 320 : % Olin 1/90: 321 : % Removed \makeatletter, \makeatother's -- they shouldn't be there, 322 : % because style option files are read with makeatletter. The terminal 323 : % makeatother screwed things up for the following style options. 324 : % Olin 3/91: 325 : % Rewritten. 326 : % - Changed things so blank lines don't get compressed out (the \leavevmove 327 : % in \cd@cr and \cd@crwb). 328 : % - Changed names to somewhat less horrible choices. 329 : % - Added lots of doc, so casual hackers can more easily mess with all this. 330 : % - Removed '"@ from the set of hacked chars, since they are already 331 : % non-special. 332 : % - Removed the bigcode env, which effect can be had with the \codeallowbreaks 333 : % command. 334 : % - Removed the \@noligs command, since it's already defined in latex.tex. 335 : % - Win big with the new \dcd, \cddollar, and \cdmath commands. 336 : % - Now, *only* the chars \{} are special inside the code env. If you need 337 : % more, use the \dcd command inside a group. 338 : % - \cd now works inside math mode. (But if you use it in a superscript, 339 : % it still comes out full size. You must explicitly put a \scriptsize\tt 340 : % inside the \cd:$x^{\cd{\scriptsize\tt...}}\$. A \leavevmode was added 341 : % so that if you begin a paragraph with a \cd{...}, TeX realises you 342 : % are starting a paragraph. 343 : % - Added the codebox env. Tricky bit involving the first line hacked 344 : % with help from David Long. 345 : % 346 : % JHR 8/19/91: 347 : % - Added \setupsmallcode to use in multi-line code displays (code, codeaux and 348 : % codebox environments). 349 : % 350 : % JHR 8/31/91: 351 : % - changed size of small code to \small (from \footnotesize). Also added 352 : % code to set the baselinestretch to 1 in smallcode. 353 : % 354 : % JHR 9/12/91: 355 : % - added \codeindent (set to \parindent) 356 : % 357 : % JHR 11/19/91 358 : % - added \cdm{} command for supporting math mode in \cd{} 359 : % 360 : % Olin 8/94 361 : % Changed the font commands for LaTeX2e. 362 : % 363 : % JHR 5/25/95 364 : % Merged Olin's LaTeX2e changes into JHR's version 365 : % 366 : % JHR 9/16/98 367 : % Use LaTeX2e features to make the code a bit cleaner. 368 : % Added \codeindent length, which controls indentation. 369 : % Added \codefontfamily, \codedisplaysize and \codesize 370 : % commands to control the font family and sizes used in 371 : % code.

 root@smlnj-gforge.cs.uchicago.edu ViewVC Help Powered by ViewVC 1.0.0