summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/verbatimbox
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-04-25 22:32:41 +0000
committerKarl Berry <karl@freefriends.org>2013-04-25 22:32:41 +0000
commit92907645c9411e22438b1985c91326a88337ba03 (patch)
tree75c5c2a3c347347e9dbf349017ae0b431a5eb782 /Master/texmf-dist/tex/latex/verbatimbox
parent7961bdb11ded0df109c55b8dcf8418ee3c5b1239 (diff)
verbatimbox (25apr13)
git-svn-id: svn://tug.org/texlive/trunk@30104 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/verbatimbox')
-rw-r--r--Master/texmf-dist/tex/latex/verbatimbox/verbatimbox.sty176
1 files changed, 120 insertions, 56 deletions
diff --git a/Master/texmf-dist/tex/latex/verbatimbox/verbatimbox.sty b/Master/texmf-dist/tex/latex/verbatimbox/verbatimbox.sty
index a646c22b537..e237b3798e0 100644
--- a/Master/texmf-dist/tex/latex/verbatimbox/verbatimbox.sty
+++ b/Master/texmf-dist/tex/latex/verbatimbox/verbatimbox.sty
@@ -1,5 +1,8 @@
\ProvidesPackage{verbatimbox}
- [2013/04/15 v2.01]
+ [2013/04/24 v3.0
+Routines for placing verbatim text into boxes, useful in places where
+the verbatim environment is inaccessible. Secondarily, for adding
+vertical buffer around an object.]
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
@@ -16,51 +19,37 @@
% verbatimbox.sty is based on boxedverbatim environment found
% in moreverb.sty.
%
-% It adds the verbbox environment, the verbfilebox command,
-% and theverbbox command.
+% An enabling routine, \addvbuffer[]{} shares some functional
+% similarities to \raisebox, but it is not the same.
%
-% The verbbox environment is just like boxedverbatim, except:
-%
-% 1) verbbox has no framed place around it; and
-% 2) the verbatim box is not output,
-% but saved in the global box named \savedverbbox.
-%
-% The verbfilebox command, rather than taking the typed input, takes
-% the contents of a file and puts it into a verbatim environment
-% inside of a saved box which is not immediately printed.
-%
-% The command \theverbbox will output the verbatim box most recently
-% created within the verbbox environment (that is, \savedverbbox).
-% The [t] option to \theverbbox is made for outputting a verbbox
-% in a tabular environment. Without the [t], insufficient vertical
-% space is allocated above the box.
-%
-% This routine allows the verbatim environment to be stuffed into a
-% LaTeX box, which can then be embedded in other LaTeX constructs.
-%
-% This routine is useful, because there are many LaTeX environments
-% in which a verbatim environment cannot be simply opened, but
-% in which a box can be simply placed (e.g., tabular).
-%
-% An enabling routine \addvbuffer{}, is available for general
-% use. It adds vertical buffer space above and below the argument
-% of the command. The vertical space added above the original box
-% is the length \boxtopsep; below the box, it is \boxbottomsep. It
-% shares some functional similarities to \raisebox, but it is not the
-% same.
-%
-% 2.01 Added LPPL License info to package
+% 2.01 -Added LPPL License info to package
+% 3.0 -Added myverbbox environment
+% -Corrected problem when no optional arguments are passed to
+% verbbox environment
+% -Added optional arguments to \addvbuffer
+% -Fixed \verbfilebox so that it restored \verbatim@processline
+% -Produced real documentation
\NeedsTeXFormat{LaTeX2e}
\@ifundefined{verbatim@processline}{\RequirePackage{verbatim}}{}
+\usepackage{stringstrings}
+
+% Following 3 lines thanks to Prof. Enrico Gregorio, from:
+% http://tex.stackexchange.com/questions/42318/
+% removing-a-backslash-from-a-character-sequence
+\begingroup\lccode`\|=`\\
+\lowercase{\endgroup\def\removebs#1{\if#1|\else#1\fi}}
+\newcommand{\@macro@name}[1]{\expandafter\removebs\string#1}
+%
\global\newsavebox{\savedverbbox}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\newcounter{VerbboxLineNo}
+%%%%%ORIGINAL FORM%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The verbbox environment is based on
% the boxedverbatim environment found in moreverb.sty
% The optional argument allows the user to modify properties of the text
-% such as fontsize
+% such as fontsize
%
-\newenvironment{verbbox}[1][]{%
+\newenvironment{origverbbox}[1][]{%
\def\verbatim@processline{%
{\setbox0=\hbox{\the\verbatim@line}%
\hsize=\wd0 \the\verbatim@line\par}}%
@@ -74,6 +63,68 @@
\egroup
\global\sbox{\savedverbbox}{\box0}
}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% David Carlisle provided the \verbbox@inner approach to avoid
+% problem when no optional argument is provided to verbbox environment:
+% http://tex.stackexchange.com/questions/109030/optional-arguments-in
+% -verbatim-environments
+\newcommand\verbbox@inner[1][]{{\nfss@catcodes\scantokens{\gdef\@tmp{#1}}}}
+\def\@tmp{}
+
+\newenvironment{verbbox}{%
+ \setcounter{VerbboxLineNo}{-1}%
+% FOR SOME REASON, USING \my@par INSTEAD OF \par PREVENTS EXTRA SPACE
+% ABOVE verbbox WHEN USING OPTIONAL ARGUMENTS
+ \let\my@par\par%
+ \def\verbatim@processline{%
+% FIRST \@tmp APPLIES OPTIONAL ARGUMENT TO EACH VERBATIM LINE
+% SECOND \@tmp MAKES SURE ANY PRINTED MATTER OF OPTIONAL ARGUMENT
+% IS ACCOUNTED FOR IN VERBATIM BOX WIDTH
+ {\addtocounter{VerbboxLineNo}{1}%
+ \@tmp\setbox0=\hbox{\@tmp\the\verbatim@line}%
+ \hsize=\wd0 \the\verbatim@line\my@par}}%
+ \@minipagetrue%
+ \@tempswatrue%
+ \setbox0=\vbox\bgroup \verbatim\verbbox@inner%
+}
+{%
+ \endverbatim%
+ \unskip\setbox0=\lastbox %
+ \egroup%
+ \global\sbox{\savedverbbox}{\box0}%
+ \global\def\@tmp{}%
+}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% The myverbbox environment is altered from verbbox environment
+% The optional argument allows the user to modify properties of
+% the text such as fontsize
+% The mandatory argument is a command which is formed so as to
+% regurgitate the boxed content created within the environment
+%
+\newenvironment{myverbbox}[2][]{%
+ \setcounter{VerbboxLineNo}{0}%
+ \def\verbatim@processline{%
+% THE FIRST #1 ACCOUNTS FOR NON-PRINTING COMMANDS; THE SECOND #1 IS FOR
+% PRINTED OPTIONAL MATERIAL
+ {\addtocounter{VerbboxLineNo}{1}%
+ #1\setbox0=\hbox{#1\the\verbatim@line}%
+ \hsize=\wd0 \the\verbatim@line\par}}%
+ \@minipagetrue%
+ \@tempswatrue%
+ \global\edef\sv@name{\@macro@name{#2}}%
+ \@ifundefined{\sv@name content}{%
+ \expandafter\newsavebox\expandafter{\csname\sv@name content\endcsname}%
+ }%
+ \expandafter\global\expandafter\edef\csname\sv@name\endcsname{\usebox{%
+ \csname\sv@name content\endcsname}}%
+ \setbox0=\vbox\bgroup \verbatim
+}
+{%
+ \endverbatim%
+ \unskip\setbox0=\lastbox %
+ \egroup%
+ \global\sbox{\csname\sv@name content\endcsname}{\box0}%
+}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The verbfilebox command is like the verbbox environment, but takes
@@ -81,51 +132,64 @@
% The optional argument allows the user to modify properties of the text
% such as fontsize
% Example: \verbfilebox[\scriptsize]{myfile}
+
+\let\sv@verbatim@processline\verbatim@processline
+
\newcommand\verbfilebox[2][]{%
+ \setcounter{VerbboxLineNo}{0}%
\def\verbatim@processline{%
- {\setbox0=\hbox{\the\verbatim@line}%
+ {\addtocounter{VerbboxLineNo}{1}%
+ #1\setbox0=\hbox{#1\the\verbatim@line}%
\hsize=\wd0 \the\verbatim@line\par}}%
\@minipagetrue%
\@tempswatrue%
- \setbox0=\vbox\bgroup #1 \verbatiminput{#2}
+ \setbox0=\vbox\bgroup \verbatiminput{#2}
\unskip\setbox0=\lastbox %
\egroup
\global\sbox{\savedverbbox}{\box0}
+ \let\verbatim@processline\sv@verbatim@processline
}
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\theverbbox[1][x]{%
\if #1t%
% The t option is for outputting the savedverbbox inside a tabular
% environment (else insufficent vertical space above box)
- \boxtopsep = 3pt
- \boxbottomsep = 0pt
- \addvbuffer{\usebox{\savedverbbox}}
+ \addvbuffer[\the\boxtopsep~\the\boxbottomsep]{\usebox{\savedverbbox}}%
\else%
- \usebox{\savedverbbox}
+ \usebox{\savedverbbox}%
\fi%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \addvbuffer is based on \fbox,
% but without a frame. Empty buffer space
% is added above and below the object, making a new box.
-% Above the box is added \boxtopsep (initially 3pt) vertical space.
-% Below the box is added \boxbottomsep (initially 0pt) vertical space.
-% This routine is called when a savedverbbox is output in a tabular
-% environment.
+% An optional argument can specify the buffer spaces or, if no
+% optional argument is specified:
+% above the box is added \boxtopsep (initially 3pt) vertical space;
+% below the box is added \boxbottomsep (initially 0pt) vertical space.
%
\newdimen\boxtopsep
\newdimen\boxbottomsep
\newdimen\ps@tempdima
\newbox\ps@tempboxa
-\boxtopsep = 3pt
-\boxbottomsep = 0pt
-\long\def\addvbuffer#1{\leavevmode\setbox\ps@tempboxa\hbox{#1}\ps@tempdima
- 0pt \advance\ps@tempdima \dp\ps@tempboxa \hbox{\lower \ps@tempdima\hbox
- {\vbox{\hbox{\vbox{\vskip\boxtopsep \box\ps@tempboxa \vskip
- \boxbottomsep}}}}}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\endinput
+\setlength\boxtopsep{3pt}
+\setlength\boxbottomsep{0pt}
+\long\def\add@vbuffer#1{\leavevmode\setbox\ps@tempboxa\hbox{#1}\ps@tempdima
+ 0pt \advance\ps@tempdima \dp\ps@tempboxa \hbox{\lower\ps@tempdima\hbox
+ {\vbox{\hbox{\vbox{\vskip\boxtop@sep \box\ps@tempboxa \vskip
+ \boxbottom@sep}}}}}}
+\global\newlength\boxtop@sep
+\global\newlength\boxbottom@sep
+\newcommand\addvbuffer[2][{\the\boxtopsep} \the\boxbottomsep]{%
+ \getargs{#1}%
+ \setlength\boxtop@sep{\argi}%
+ \if1\narg\setlength\boxbottom@sep{\argi}\else%
+ \setlength\boxbottom@sep{\argii}\fi%
+ \add@vbuffer{#2}%
+}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\endinput