| 1 |
\def\pkgname{minibox} |
| 2 |
|
| 3 |
\RequirePackage{filecontents} |
| 4 |
\begin{filecontents*}{README.txt} |
| 5 |
___________________ |
| 6 |
The minibox package |
| 7 |
v0.2a |
| 8 |
|
| 9 |
A small package to provide a convenient input syntax for |
| 10 |
boxes that don't break their text over lines automatically, |
| 11 |
but do allow manual lines breaks, and that shrink to |
| 12 |
the natural width of the maximum line width. |
| 13 |
|
| 14 |
\minibox{Some\\ broken\\ text} |
| 15 |
\minibox[c]{Centred\\ broken\\ text} |
| 16 |
\minibox[c,t]{Centred\\ aligned\\ top} |
| 17 |
|
| 18 |
Will Robertson |
| 19 |
Copyright 2009, 2013 |
| 20 |
\end{filecontents*} |
| 21 |
|
| 22 |
|
| 23 |
%%%%%%%%%1%%%%%%%%%2%%%%%%%%%3%%%%%%%%%4%%%%%%%%%5%%%%%%%%%6%%%%%%%%%7%%%%%%%%% |
| 24 |
\begin{filecontents*}{minibox.sty} |
| 25 |
% \begin{macrocode} |
| 26 |
\RequirePackage{expl3} |
| 27 |
\ProvidesExplPackage |
| 28 |
{minibox} |
| 29 |
{2013/06/21} |
| 30 |
{0.2a} |
| 31 |
{Another type of box.} |
| 32 |
% \end{macrocode} |
| 33 |
% |
| 34 |
% \begin{macrocode} |
| 35 |
\bool_new:N \l_minibox_frame_bool |
| 36 |
\keys_define:nn {minibox} |
| 37 |
{ |
| 38 |
frame .choice: , |
| 39 |
frame / true .code:n = { \bool_set_true:N \l_minibox_frame_bool } , |
| 40 |
frame / false .code:n = { \bool_set_false:N \l_minibox_frame_bool } , |
| 41 |
frame .default:n = { true } , |
| 42 |
|
| 43 |
l .code:n = { \tl_set:Nn \l_minibox_tabular_preamble_tl {l} } , |
| 44 |
c .code:n = { \tl_set:Nn \l_minibox_tabular_preamble_tl {c} } , |
| 45 |
r .code:n = { \tl_set:Nn \l_minibox_tabular_preamble_tl {r} } , |
| 46 |
|
| 47 |
t .code:n = { \tl_set:Nn \l_minibox_tabular_valign_tl {t} } , |
| 48 |
m .code:n = { \tl_set:Nn \l_minibox_tabular_valign_tl {c} } , |
| 49 |
b .code:n = { \tl_set:Nn \l_minibox_tabular_valign_tl {b} } , |
| 50 |
|
| 51 |
rule .dim_set:N = \l_minibox_rule_dim , |
| 52 |
pad .dim_set:N = \l_minibox_pad_dim , |
| 53 |
} |
| 54 |
% \end{macrocode} |
| 55 |
% |
| 56 |
% \begin{macrocode} |
| 57 |
\cs_new:Npn \miniboxsetup #1 { \keys_set:nn {minibox} {#1} } |
| 58 |
\miniboxsetup {l,m,rule=\fboxrule,pad=\fboxsep} |
| 59 |
% \end{macrocode} |
| 60 |
% |
| 61 |
% \begin{macrocode} |
| 62 |
\newcommand\minibox[2][] |
| 63 |
{ |
| 64 |
\group_begin: |
| 65 |
\keys_set:nn {minibox} {#1} |
| 66 |
\bool_if:NTF \l_minibox_frame_bool |
| 67 |
{ |
| 68 |
\setlength\fboxrule{\l_minibox_rule_dim} |
| 69 |
\setlength\fboxsep{\l_minibox_pad_dim} |
| 70 |
\fbox |
| 71 |
} |
| 72 |
{ \use:n } |
| 73 |
{ |
| 74 |
\use:x |
| 75 |
{ |
| 76 |
\exp_not:N \begin{tabular} |
| 77 |
[\l_minibox_tabular_valign_tl] |
| 78 |
{ @{} \l_minibox_tabular_preamble_tl @{} } |
| 79 |
\exp_not:n {#2} |
| 80 |
\exp_not:N \end{tabular} |
| 81 |
} |
| 82 |
} |
| 83 |
\group_end: |
| 84 |
} |
| 85 |
% \end{macrocode} |
| 86 |
\end{filecontents*} |
| 87 |
%%%%%%%%%1%%%%%%%%%2%%%%%%%%%3%%%%%%%%%4%%%%%%%%%5%%%%%%%%%6%%%%%%%%%7%%%%%%%%% |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
% Conditionally compile the documentation & generate the .ins file: |
| 93 |
\providecommand\pstoolCompile{Y} |
| 94 |
\if\pstoolCompile N |
| 95 |
\expandafter\endinput |
| 96 |
\fi |
| 97 |
|
| 98 |
|
| 99 |
\begin{filecontents*}{\pkgname.ins} |
| 100 |
%&latex |
| 101 |
\def\pstoolCompile{N} |
| 102 |
\input minibox.tex |
| 103 |
\csname@@end\endcsname |
| 104 |
\end{filecontents*} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
\makeatletter |
| 110 |
\documentclass{ltxdoc} |
| 111 |
|
| 112 |
\usepackage[rm,medium]{titlesec} |
| 113 |
|
| 114 |
\usepackage{xcolor,booktabs} |
| 115 |
\usepackage[colorlinks,linktocpage]{hyperref} |
| 116 |
|
| 117 |
\usepackage{tocloft,varwidth,array} |
| 118 |
\setcounter{tocdepth}{1} |
| 119 |
\def\tocwidthA{0.45} |
| 120 |
\def\tocwidthB{0.45} |
| 121 |
\def\cftpartfont{\scshape} |
| 122 |
\def\cftsecfont{\small} |
| 123 |
\cftbeforesecskip=0pt |
| 124 |
\def\cftpartleader{} |
| 125 |
\def\cftpartafterpnum{\cftparfillskip} |
| 126 |
\def\cftsecleader{} |
| 127 |
\def\cftsecafterpnum{\cftparfillskip} |
| 128 |
|
| 129 |
\let\pkg\textsf |
| 130 |
\def\pkgopt#1{\texttt{[#1]}} |
| 131 |
|
| 132 |
\def\PDF{\textsc{pdf}} |
| 133 |
\def\PS{\textsc{ps}} |
| 134 |
\def\DVI{\textsc{dvi}} |
| 135 |
\def\EPS{\textsc{eps}} |
| 136 |
|
| 137 |
\usepackage{\pkgname} |
| 138 |
\usepackage[T1]{fontenc} |
| 139 |
\usepackage{microtype} |
| 140 |
\usepackage{lmodern} |
| 141 |
\linespread{1.1} |
| 142 |
\frenchspacing |
| 143 |
|
| 144 |
\GetFileInfo{\pkgname.sty} |
| 145 |
\begin{document} |
| 146 |
|
| 147 |
\title{The \pkg{\pkgname} package} |
| 148 |
\author{Will Robertson\\\texttt{[email protected]}} |
| 149 |
\date{\fileversion\qquad\filedate} |
| 150 |
|
| 151 |
\maketitle |
| 152 |
|
| 153 |
\section{Introduction} |
| 154 |
|
| 155 |
It's sometimes useful to be able to stack text over lines |
| 156 |
in a small box; this is similar to paragraph text broken over lines, but |
| 157 |
for small amounts of text when automatic line breaking is not required. |
| 158 |
In other words, I'm looking for an \cmd\mbox\ that allows manual line breaks. |
| 159 |
\begin{center} |
| 160 |
\fbox{\vbox{\hbox{abcd}\hbox{efg}\hbox{h}}} |
| 161 |
\end{center} |
| 162 |
This sort of thing is a little awkward in plain \TeX\ and \LaTeX. |
| 163 |
\begin{center} |
| 164 |
|\vbox{\hbox{abcd}\hbox{efg}\hbox{h}}|\par |
| 165 |
\end{center} |
| 166 |
|
| 167 |
\section{The command \cs{minibox}} |
| 168 |
|
| 169 |
This package defines the \cmd\minibox\DescribeMacro{\minibox}\ command |
| 170 |
to write this more conveniently separately lines with \verb"\\". |
| 171 |
Various options are allowed to control the alignment and whether to frame the box, shown in Table~\ref{opt}. |
| 172 |
|
| 173 |
\begin{table} |
| 174 |
\centering |
| 175 |
\begin{tabular}{rl} |
| 176 |
\toprule |
| 177 |
\texttt{frame(=true)} & Has a frame \\ |
| 178 |
\texttt{frame=false} & Has not a frame (default) \\ |
| 179 |
\texttt{rule=}\meta{dim} & Thickness of the rule (default \the\fboxrule) \\ |
| 180 |
\texttt{pad=}\meta{dim} & Space on the inside of the frame (default \the\fboxsep) \\ |
| 181 |
\midrule |
| 182 |
\texttt{l} & Left-aligned text (default) \\ |
| 183 |
\texttt{c} & Centred text \\ |
| 184 |
\texttt{r} & Right-aligned text \\ |
| 185 |
\midrule |
| 186 |
\texttt{b} & Align the box with the bottom line \\ |
| 187 |
\texttt{m} & Vertically centre the box (default) \\ |
| 188 |
\texttt{t} & Align the box with the top line \\ |
| 189 |
\bottomrule |
| 190 |
\end{tabular} |
| 191 |
\caption{Optional arguments for the \cs{minibox} command.} |
| 192 |
\label{opt} |
| 193 |
\end{table} |
| 194 |
|
| 195 |
\subsection{Horizontal alignment of the text} |
| 196 |
Here's an example adjusting the horizontal alignment. |
| 197 |
\miniboxsetup{frame} |
| 198 |
\begin{center} |
| 199 |
\verb|\def\x{abcd\\efg\\h}| |
| 200 |
\def\x{abcd\\efg\\h} |
| 201 |
\begin{tabular}{ccc} |
| 202 |
\verb"\minibox{\x}" & |
| 203 |
\verb"\minibox[c]{\x}" & |
| 204 |
\verb"\minibox[r]{\x}" \\ |
| 205 |
\minibox{\x} & |
| 206 |
\minibox[c]{\x} & |
| 207 |
\minibox[r]{\x} |
| 208 |
\end{tabular} |
| 209 |
\end{center} |
| 210 |
|
| 211 |
\subsection{Vertical alignment of the box} |
| 212 |
Here's an example adjusting the vertical alignment. |
| 213 |
\begin{center} |
| 214 |
\verb|\def\x{abcd\\efg\\h}| |
| 215 |
\medskip |
| 216 |
|
| 217 |
\def\x{abcd\\efg\\h} |
| 218 |
\begin{tabular}{ccc} |
| 219 |
\verb"xyz\minibox{\x}" & |
| 220 |
\verb"xyz\minibox[b]{\x}" & |
| 221 |
\verb"xyz\minibox[t]{\x}" \\ |
| 222 |
xyz\minibox{\x} & |
| 223 |
xyz\minibox[b]{\x} & |
| 224 |
xyz\minibox[t]{\x} |
| 225 |
\end{tabular} |
| 226 |
\end{center} |
| 227 |
|
| 228 |
\subsection{Framing your box} |
| 229 |
The boxes which are showed in these examples are not displayed by default; use the \verb"frame" option to make them appear: |
| 230 |
\miniboxsetup{frame=false} |
| 231 |
\begin{center} |
| 232 |
\verb|\def\x{abcd\\efg\\h}| |
| 233 |
\medskip |
| 234 |
|
| 235 |
\def\x{abcd\\efg\\h} |
| 236 |
\begin{tabular}{ccc} |
| 237 |
\verb"\minibox{\x}" & |
| 238 |
\verb"\minibox[frame]{\x}" & |
| 239 |
\verb"\minibox[frame,rule=1pt,pad=0pt]{\x}" \\ |
| 240 |
\minibox{\x} & |
| 241 |
\minibox[frame]{\x} & |
| 242 |
\minibox[frame,rule=1pt,pad=0pt]{\x} \\ |
| 243 |
\end{tabular} |
| 244 |
\end{center} |
| 245 |
Negative values can be input for \texttt{pad}. |
| 246 |
\begin{quote}\itshape |
| 247 |
\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. |
| 248 |
\end{quote} |
| 249 |
|
| 250 |
\subsection{Setting options} |
| 251 |
|
| 252 |
Obviously, any combination of these options can be applied: |
| 253 |
\begin{center} |
| 254 |
\verb|\def\x{abcd\\efg\\h}| |
| 255 |
\medskip |
| 256 |
|
| 257 |
\def\x{abcd\\efg\\h} |
| 258 |
\begin{tabular}{ccc} |
| 259 |
\verb"x\minibox[frame]{\x}" & |
| 260 |
\verb"x\minibox[frame,c,b]{\x}" \\ |
| 261 |
x\minibox[frame]{\x} & |
| 262 |
x\minibox[frame,c,b]{\x} |
| 263 |
\end{tabular} |
| 264 |
\end{center} |
| 265 |
\DescribeMacro{\miniboxsetup} |
| 266 |
You can change the defaults of \cs{minibox} using this command. |
| 267 |
\begin{center} |
| 268 |
\verb|\def\x{abcd\\efg\\h}| |
| 269 |
\medskip |
| 270 |
|
| 271 |
\def\x{abcd\\efg\\h} |
| 272 |
\begin{tabular}{ccc} |
| 273 |
& \verb"\miniboxsetup{frame,r}" \\ |
| 274 |
\verb"\minibox{\x}" & |
| 275 |
\verb"\minibox{\x}" \\ |
| 276 |
\minibox{\x} & |
| 277 |
\miniboxsetup{frame,r}\minibox{\x} |
| 278 |
\end{tabular} |
| 279 |
\end{center} |
| 280 |
|
| 281 |
\section{Licence} |
| 282 |
|
| 283 |
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 |
| 284 |
this license is available at: \url{http://www.latex-project.org/lppl.txt}. This work is maintained by \textsc{Will Robertson}. |
| 285 |
|
| 286 |
\newpage |
| 287 |
\part{Implementation} |
| 288 |
\parindent=0pt |
| 289 |
\DocInput{\pkgname.sty} |
| 290 |
\end{document} |