summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/numberedblock
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/numberedblock
Initial commit
Diffstat (limited to 'macros/latex/contrib/numberedblock')
-rw-r--r--macros/latex/contrib/numberedblock/README13
-rw-r--r--macros/latex/contrib/numberedblock/numberedblock.sty126
-rw-r--r--macros/latex/contrib/numberedblock/testnumberedblock.pdfbin0 -> 75098 bytes
-rw-r--r--macros/latex/contrib/numberedblock/testnumberedblock.tex66
4 files changed, 205 insertions, 0 deletions
diff --git a/macros/latex/contrib/numberedblock/README b/macros/latex/contrib/numberedblock/README
new file mode 100644
index 0000000000..32533fb5b5
--- /dev/null
+++ b/macros/latex/contrib/numberedblock/README
@@ -0,0 +1,13 @@
+The style file numberedblock has been created for the report writer's
+convenience.
+
+Do you need to include various small inline blocks of code in your
+documents? It can be a pain to refer to them if they are not labeled.
+This style package allows you to include and sequentially label
+code-block snippets in your document, so that they can be subsequently
+refered to in an unambiguous fashion.
+
+Sorry I don't have a separate documentation file, but it's very simply
+documented in the style file itself, and the testnumberedblock example.
+
+ -Steven Segletes
diff --git a/macros/latex/contrib/numberedblock/numberedblock.sty b/macros/latex/contrib/numberedblock/numberedblock.sty
new file mode 100644
index 0000000000..1c2cf01cd9
--- /dev/null
+++ b/macros/latex/contrib/numberedblock/numberedblock.sty
@@ -0,0 +1,126 @@
+\ProvidesPackage {numberedblock} [2014/02/24 v1.10]
+%
+% by Steven B. Segletes
+%
+% This work may be distributed and/or modified under the
+% conditions of the LaTeX Project Public License, either version 1.3
+% of this license or (at your option) any later version.
+% The latest version of this license is in
+% http://www.latex-project.org/lppl.txt
+% and version 1.3c or later is part of all distributions of LaTeX
+% version 2005/12/01 or later.
+%
+% 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...\nblabel{mylabel}}
+%
+% A label may set to the code block with \nblabel{}.
+%
+% In contrast, the numVblock environment is a verbatim environment.
+% A label may be passed to numVblock through an optional argument, via
+% \nbVlabel{}.
+%
+% \begin{numVblock}[\nbVlabel{mylabel}]
+% 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.
+%
+% V1.1 - Added the hyperref-compatible capability to label and
+% reference numbered blocks.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\NeedsTeXFormat{LaTeX2e}
+\@ifundefined{verbatim@processline}{\RequirePackage{verbatim}}{}
+\usepackage{verbatimbox}
+
+%%%%% LABELING CAPABILITY
+% See: http://tex.stackexchange.com/questions/160466/
+% how-can-one-refer-to-a-part-of-an-equation
+\AtBeginDocument{\let\nb@label\label}
+\newcounter{nb@counter}
+\newcommand{\nblabel}[1]{\def\@currentlabel{\theblocknum}\nb@label{#1}}
+\newcommand{\nbVlabel}[1]{\setcounter{nb@counter}{\theblocknum}\stepcounter{nb@counter}%
+ \def\@currentlabel{\thenb@counter}\nb@label{#1}}
+%%%%%
+
+\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
diff --git a/macros/latex/contrib/numberedblock/testnumberedblock.pdf b/macros/latex/contrib/numberedblock/testnumberedblock.pdf
new file mode 100644
index 0000000000..2a4066df62
--- /dev/null
+++ b/macros/latex/contrib/numberedblock/testnumberedblock.pdf
Binary files differ
diff --git a/macros/latex/contrib/numberedblock/testnumberedblock.tex b/macros/latex/contrib/numberedblock/testnumberedblock.tex
new file mode 100644
index 0000000000..0e66a6a262
--- /dev/null
+++ b/macros/latex/contrib/numberedblock/testnumberedblock.tex
@@ -0,0 +1,66 @@
+\documentclass[10pt]{article}
+\usepackage{numberedblock}
+\textheight 7.7in
+\begin{document}
+%DEFAULTS:
+%\setlength\maxblocklabelsize{-.4in}
+%\setlength\blockindent{0.2in}
+%\renewcommand\blocklabel[1]{[\textit{\arabic{#1}}]}
+
+This is a test of the \textsf{numberedblock} style packcage, which is
+specially designed to produce sequentially numbered BLOCKS of code (note
+the individual code lines are not numbered, but the whole block gets a
+single number, for later reference (much in the same way that equations
+can get numbered in a document). While specialized for numbering code
+blocks, the commands can actually number other items, as well, in fact
+anything that fits in a \LaTeX{} box.
+
+If the code block contains no special characters
+(or is already a box), one can simply use the
+command form, called \verb,\numblock,. It cannot handle verbatim text,
+but must use standard \LaTeX{} escape sequences (for line breaks,
+contiguous spaces, special characters, etc.). It puts the output in a
+tt font, which is the same as used in the verbatim environment:
+
+\numblock{This text is the\\argument to the command\\where double
+slashes have been\\used for line breaks\nblabel{nb:A}}
+
+Most useful, however, there is also the \verb,numVblock, environment,
+which handles verbatim text, as seen in the next example:
+
+\begin{numVblock}[\nbVlabel{nb:B}]
+This is a labeled numVblock
+environment, which (<--see contiguous spaces here)
+succeeds in
+incorporating verbatim text like
+@##$%*$%$()||}{?><\\\
+\end{numVblock}
+
+As envisioned the \verb,numVblock, environment would be ideally suited
+for displaying small code blocks as part of documentation, and I can
+{\bfseries (NEW!!)} even reference
+the numbered blocks~\ref{nb:A} and \ref{nb:B}. The code can
+contain contiguous spaces and special characters:
+
+\begin{numVblock}
+ program test
+ implicit none
+ integer a, x
+c$$$$$$$$$$$$$$$$$$$$$$$$$
+ a = 0
+ x = 1
+ 10 a = a + x
+ if (a .eq. 100) stop
+ goto 10
+ end
+\end{numVblock}
+
+Below, I test the \verb,\numblock, command with the argument as a
+box, rather than as formatted text.
+
+\numblock{\fbox{Testing, 1,2,3 testing a box}}
+
+Don't forget, there are settable parameters to define the block
+left-indent, the format of the label, and (if needed) the labels' max
+width/placement.
+\end{document}