summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/verbatimbox/verbatimbox.sty
blob: a646c22b537a477429c2e58b8fc91c76dfaebf0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
\ProvidesPackage{verbatimbox}
        [2013/04/15 v2.01]
%
% 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.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Steven B. Segletes.
%
% verbatimbox.sty is based on boxedverbatim environment found
% in moreverb.sty.
%
% It adds the verbbox environment, the verbfilebox command,
% and theverbbox command.
%
% 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
\NeedsTeXFormat{LaTeX2e}
\@ifundefined{verbatim@processline}{\RequirePackage{verbatim}}{}

\global\newsavebox{\savedverbbox}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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
%
\newenvironment{verbbox}[1][]{%
  \def\verbatim@processline{%
    {\setbox0=\hbox{\the\verbatim@line}%
    \hsize=\wd0 \the\verbatim@line\par}}%
  \@minipagetrue%
  \@tempswatrue%
  \setbox0=\vbox\bgroup #1 \verbatim
}
{%
  \endverbatim
  \unskip\setbox0=\lastbox %
  \egroup
  \global\sbox{\savedverbbox}{\box0}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The verbfilebox command is like the verbbox environment, but takes
% a file as input, rather than text typed into an environment.
% The optional argument allows the user to modify properties of the text
% such as fontsize
% Example: \verbfilebox[\scriptsize]{myfile}
\newcommand\verbfilebox[2][]{%
  \def\verbatim@processline{%
    {\setbox0=\hbox{\the\verbatim@line}%
    \hsize=\wd0 \the\verbatim@line\par}}%
  \@minipagetrue%
  \@tempswatrue%
  \setbox0=\vbox\bgroup #1 \verbatiminput{#2}
  \unskip\setbox0=\lastbox %
  \egroup
  \global\sbox{\savedverbbox}{\box0}
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\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}}
  \else%
    \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.
%
\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