Created
April 28, 2011 18:14
-
-
Save t0yv0/946918 to your computer and use it in GitHub Desktop.
LaTeX command for typesetting pretty-printed code blocks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % ``\Listing{...}'' command typesets its argument as a code block - | |
| % with monospace font and whitespace preserved. It is an | |
| % environment-like command accepting multiple paragraphs. | |
| \def\Listing{\bigskip\begingroup% | |
| \setlength{\parskip}{0pc}\addtolength{\parindent}{1pc}% | |
| \tt\scriptsize\obeylines\obeyspaces\PreserveWhitespace\ListingBody} | |
| % ``\ListingBody'' is an auxillary command need to make Listing work. | |
| % It inserts the argument and closes the group opened by Listing. | |
| \long\def\ListingBody#1{#1\endgroup\smallskip} | |
| % \PreserveWhitespace makes leading spaces appear as-is. To make | |
| % leading spaces appear, we have to set space to be an active | |
| % character that exands to a non-breakable space. The command for | |
| % this is ``\let =\ ``, but unfortunately lifting this command to a | |
| % macro does not quite work because space is not active during the | |
| % definition of the macro - it needs to be made active using | |
| % ``\catcode''. Therefore we define our macro in a little block of | |
| % code where space is made active: | |
| \begingroup | |
| \catcode32=\active | |
| \gdef\PreserveWhitespace{\catcode32=\active\let =\ } | |
| \endgroup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment