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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
\def\pkgname{minibox}
\RequirePackage{filecontents}
\begin{filecontents*}{README.txt}
___________________
The minibox package
v0.2a
A small package to provide a convenient input syntax for
boxes that don't break their text over lines automatically,
but do allow manual lines breaks, and that shrink to
the natural width of the maximum line width.
\minibox{Some\\ broken\\ text}
\minibox[c]{Centred\\ broken\\ text}
\minibox[c,t]{Centred\\ aligned\\ top}
Will Robertson
Copyright 2009, 2013
\end{filecontents*}
%%%%%%%%%1%%%%%%%%%2%%%%%%%%%3%%%%%%%%%4%%%%%%%%%5%%%%%%%%%6%%%%%%%%%7%%%%%%%%%
\begin{filecontents*}{minibox.sty}
% \begin{macrocode}
\RequirePackage{expl3}
\ProvidesExplPackage
{minibox}
{2013/06/21}
{0.2a}
{Another type of box.}
% \end{macrocode}
%
% \begin{macrocode}
\bool_new:N \l_minibox_frame_bool
\keys_define:nn {minibox}
{
frame .choice: ,
frame / true .code:n = { \bool_set_true:N \l_minibox_frame_bool } ,
frame / false .code:n = { \bool_set_false:N \l_minibox_frame_bool } ,
frame .default:n = { true } ,
l .code:n = { \tl_set:Nn \l_minibox_tabular_preamble_tl {l} } ,
c .code:n = { \tl_set:Nn \l_minibox_tabular_preamble_tl {c} } ,
r .code:n = { \tl_set:Nn \l_minibox_tabular_preamble_tl {r} } ,
t .code:n = { \tl_set:Nn \l_minibox_tabular_valign_tl {t} } ,
m .code:n = { \tl_set:Nn \l_minibox_tabular_valign_tl {c} } ,
b .code:n = { \tl_set:Nn \l_minibox_tabular_valign_tl {b} } ,
rule .dim_set:N = \l_minibox_rule_dim ,
pad .dim_set:N = \l_minibox_pad_dim ,
}
% \end{macrocode}
%
% \begin{macrocode}
\cs_new:Npn \miniboxsetup #1 { \keys_set:nn {minibox} {#1} }
\miniboxsetup {l,m,rule=\fboxrule,pad=\fboxsep}
% \end{macrocode}
%
% \begin{macrocode}
\newcommand\minibox[2][]
{
\group_begin:
\keys_set:nn {minibox} {#1}
\bool_if:NTF \l_minibox_frame_bool
{
\setlength\fboxrule{\l_minibox_rule_dim}
\setlength\fboxsep{\l_minibox_pad_dim}
\fbox
}
{ \use:n }
{
\use:x
{
\exp_not:N \begin{tabular}
[\l_minibox_tabular_valign_tl]
{ @{} \l_minibox_tabular_preamble_tl @{} }
\exp_not:n {#2}
\exp_not:N \end{tabular}
}
}
\group_end:
}
% \end{macrocode}
\end{filecontents*}
%%%%%%%%%1%%%%%%%%%2%%%%%%%%%3%%%%%%%%%4%%%%%%%%%5%%%%%%%%%6%%%%%%%%%7%%%%%%%%%
% Conditionally compile the documentation & generate the .ins file:
\providecommand\pstoolCompile{Y}
\if\pstoolCompile N
\expandafter\endinput
\fi
\begin{filecontents*}{\pkgname.ins}
%&latex
\def\pstoolCompile{N}
\input minibox.tex
\csname@@end\endcsname
\end{filecontents*}
\makeatletter
\documentclass{ltxdoc}
\usepackage[rm,medium]{titlesec}
\usepackage{xcolor,booktabs}
\usepackage[colorlinks,linktocpage]{hyperref}
\usepackage{tocloft,varwidth,array}
\setcounter{tocdepth}{1}
\def\tocwidthA{0.45}
\def\tocwidthB{0.45}
\def\cftpartfont{\scshape}
\def\cftsecfont{\small}
\cftbeforesecskip=0pt
\def\cftpartleader{}
\def\cftpartafterpnum{\cftparfillskip}
\def\cftsecleader{}
\def\cftsecafterpnum{\cftparfillskip}
\let\pkg\textsf
\def\pkgopt#1{\texttt{[#1]}}
\def\PDF{\textsc{pdf}}
\def\PS{\textsc{ps}}
\def\DVI{\textsc{dvi}}
\def\EPS{\textsc{eps}}
\usepackage{\pkgname}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{lmodern}
\linespread{1.1}
\frenchspacing
\GetFileInfo{\pkgname.sty}
\begin{document}
\title{The \pkg{\pkgname} package}
\author{Will Robertson\\\texttt{wspr81@gmail.com}}
\date{\fileversion\qquad\filedate}
\maketitle
\section{Introduction}
It's sometimes useful to be able to stack text over lines
in a small box; this is similar to paragraph text broken over lines, but
for small amounts of text when automatic line breaking is not required.
In other words, I'm looking for an \cmd\mbox\ that allows manual line breaks.
\begin{center}
\fbox{\vbox{\hbox{abcd}\hbox{efg}\hbox{h}}}
\end{center}
This sort of thing is a little awkward in plain \TeX\ and \LaTeX.
\begin{center}
|\vbox{\hbox{abcd}\hbox{efg}\hbox{h}}|\par
\end{center}
\section{The command \cs{minibox}}
This package defines the \cmd\minibox\DescribeMacro{\minibox}\ command
to write this more conveniently separately lines with \verb"\\".
Various options are allowed to control the alignment and whether to frame the box, shown in Table~\ref{opt}.
\begin{table}
\centering
\begin{tabular}{rl}
\toprule
\texttt{frame(=true)} & Has a frame \\
\texttt{frame=false} & Has not a frame (default) \\
\texttt{rule=}\meta{dim} & Thickness of the rule (default \the\fboxrule) \\
\texttt{pad=}\meta{dim} & Space on the inside of the frame (default \the\fboxsep) \\
\midrule
\texttt{l} & Left-aligned text (default) \\
\texttt{c} & Centred text \\
\texttt{r} & Right-aligned text \\
\midrule
\texttt{b} & Align the box with the bottom line \\
\texttt{m} & Vertically centre the box (default) \\
\texttt{t} & Align the box with the top line \\
\bottomrule
\end{tabular}
\caption{Optional arguments for the \cs{minibox} command.}
\label{opt}
\end{table}
\subsection{Horizontal alignment of the text}
Here's an example adjusting the horizontal alignment.
\miniboxsetup{frame}
\begin{center}
\verb|\def\x{abcd\\efg\\h}|
\def\x{abcd\\efg\\h}
\begin{tabular}{ccc}
\verb"\minibox{\x}" &
\verb"\minibox[c]{\x}" &
\verb"\minibox[r]{\x}" \\
\minibox{\x} &
\minibox[c]{\x} &
\minibox[r]{\x}
\end{tabular}
\end{center}
\subsection{Vertical alignment of the box}
Here's an example adjusting the vertical alignment.
\begin{center}
\verb|\def\x{abcd\\efg\\h}|
\medskip
\def\x{abcd\\efg\\h}
\begin{tabular}{ccc}
\verb"xyz\minibox{\x}" &
\verb"xyz\minibox[b]{\x}" &
\verb"xyz\minibox[t]{\x}" \\
xyz\minibox{\x} &
xyz\minibox[b]{\x} &
xyz\minibox[t]{\x}
\end{tabular}
\end{center}
\subsection{Framing your box}
The boxes which are showed in these examples are not displayed by default; use the \verb"frame" option to make them appear:
\miniboxsetup{frame=false}
\begin{center}
\verb|\def\x{abcd\\efg\\h}|
\medskip
\def\x{abcd\\efg\\h}
\begin{tabular}{ccc}
\verb"\minibox{\x}" &
\verb"\minibox[frame]{\x}" &
\verb"\minibox[frame,rule=1pt,pad=0pt]{\x}" \\
\minibox{\x} &
\minibox[frame]{\x} &
\minibox[frame,rule=1pt,pad=0pt]{\x} \\
\end{tabular}
\end{center}
Negative values can be input for \texttt{pad}.
\begin{quote}\itshape
\LaTeX\ experts: while these padding and rule options are internally controlled by \cs{fboxsep} and \cs{fboxrule}, changing these variables will have no effect on \cs{minibox}'s behaviour. Use \cs{miniboxsetup} as described next to change these options globally.
\end{quote}
\subsection{Setting options}
Obviously, any combination of these options can be applied:
\begin{center}
\verb|\def\x{abcd\\efg\\h}|
\medskip
\def\x{abcd\\efg\\h}
\begin{tabular}{ccc}
\verb"x\minibox[frame]{\x}" &
\verb"x\minibox[frame,c,b]{\x}" \\
x\minibox[frame]{\x} &
x\minibox[frame,c,b]{\x}
\end{tabular}
\end{center}
\DescribeMacro{\miniboxsetup}
You can change the defaults of \cs{minibox} using this command.
\begin{center}
\verb|\def\x{abcd\\efg\\h}|
\medskip
\def\x{abcd\\efg\\h}
\begin{tabular}{ccc}
& \verb"\miniboxsetup{frame,r}" \\
\verb"\minibox{\x}" &
\verb"\minibox{\x}" \\
\minibox{\x} &
\miniboxsetup{frame,r}\minibox{\x}
\end{tabular}
\end{center}
\section{Licence}
This package is freely modifiable and distributable under the terms and conditions of the \LaTeX\ Project Public Licence, version 1.3c or greater (your choice). The latest version of
this license is available at: \url{http://www.latex-project.org/lppl.txt}. This work is maintained by \textsc{Will Robertson}.
\newpage
\part{Implementation}
\parindent=0pt
\DocInput{\pkgname.sty}
\end{document}
|