From 9e911023afe015ce7f305faa22f558745289096a Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Wed, 20 Mar 2013 21:39:32 +0000 Subject: numberedblock (20mar13) git-svn-id: svn://tug.org/texlive/trunk@29447 c570f23f-e606-0410-a88d-b1316a301751 --- .../tex/latex/numberedblock/numberedblock.sty | 102 +++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 Master/texmf-dist/tex/latex/numberedblock/numberedblock.sty (limited to 'Master/texmf-dist/tex/latex/numberedblock/numberedblock.sty') diff --git a/Master/texmf-dist/tex/latex/numberedblock/numberedblock.sty b/Master/texmf-dist/tex/latex/numberedblock/numberedblock.sty new file mode 100644 index 00000000000..b093da67942 --- /dev/null +++ b/Master/texmf-dist/tex/latex/numberedblock/numberedblock.sty @@ -0,0 +1,102 @@ +\ProvidesPackage {numberedblock} [2007/03/16 v1.01] +% +% by Steven B. Segletes, for the public domain. +% +% numberedblock provides several routines +% intended to print out a block of code with a unique, +% sequentially indexed label. The code block is printed to the left, +% with the block label printed centered vertically on the code block, +% horizontally right-justified. Each line of code is not numbered... +% rather, the block of code gets a single label. +% +% There are three parameters with which the user may freely alter: +% 1) maxblocklabelsize is a length set aside for the code-block labels. +% If it is too small, the label will run off the right margin; too large +% and it limits the width of the code block itself. However, by setting +% this parameter to a negative value, it will force the label to be +% offset into the right margin, which may be a desirable feature. +% 2) blockindent is a length defining the left-side indent to be used +% for the code block to be printed. +% 3) blocklabel is the command that actually formats the block label to +% the desired appearance. Currently, italicized numbers are used within +% non-italicized square brackets to comprise the block label. +% +% There is a command-line version called numblock, which cannot +% handle verbatim input. And there is an environment called numVblock +% which handles cases invloving verbatim input +% +% An example of how to use numberedblock is given below. The +% double-backslash is used for linebreaks in the code. Tildes need to +% be used for hard spaces under two conditions: when the code contains +% multiple sequential spaces; and if a space follows a period (which +% would otherwise invoke end-of-sentence spacing considerations). In +% addition, special LaTeX characters need to be quoted in the +% appropriate manner of LaTeX. +% +% \numblock{Line 1 of code\\Line 2 of code\\Line 3...} +% +% In contrast, the numVblock environment is a verbatim environment: +% +% \begin{numVblock}{ +% program test +% implicit none +% integer a, x +% a = 0 +% x = 1 +% 10 a = a + x +% if (a .eq. 100) stop +% goto 10 +% end +% \end{numVblock} +% +% The font used for the code block itself is the ttfamily (typewriter) +% of fixed-width characters. The counter named blocknum is used to +% index the code block sequence. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\NeedsTeXFormat{LaTeX2e} +\@ifundefined{verbatim@processline}{\RequirePackage{verbatim}}{} +\usepackage{verbatimbox} + +\newsavebox{\@savedverbbox} +\newlength\maxblocklabelsize +\newlength\blockindent + \setlength\maxblocklabelsize{-0.4in} + \setlength\blockindent{0.2in} + \newcommand\blocklabel[1]{[\textit{\arabic{#1}}]} +\newcounter{blocknum} +\setcounter{blocknum}{0} +\newlength\codeblockwidth +\newlength\parindentsave +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\def\numVblock{% + \sbox\@savedverbbox{\usebox{\savedverbbox}} + \verbbox +} +\def\endnumVblock{ + \endverbbox + \numblock{\theverbbox[t]} + \global\sbox{\savedverbbox}{\usebox{\@savedverbbox}} +} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\newcommand\numblock[1]{ + \setlength\codeblockwidth{\textwidth} + \addtolength\codeblockwidth{-\maxblocklabelsize} + \addtolength\codeblockwidth{-\blockindent} + \setlength\parindentsave{\parindent} + \parindent 0in + \addtocounter{blocknum}{1} + \vspace{\abovecaptionskip} + \begin{tabular}{@{\hspace{\blockindent}} l @{} r @{}} + {\tt + \begin{tabular*}{\codeblockwidth}{@{} l @{}} + #1 + \end{tabular*}% + } + & \makebox[\maxblocklabelsize]{\hfill\blocklabel{blocknum}}\\ + \end{tabular} + \vspace{\belowcaptionskip} + \setlength{\parindent}{\parindentsave} +} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\endinput -- cgit v1.2.3