| 1 |
\input pdfToolbox |
| 2 |
\input measurebox |
| 3 |
|
| 4 |
\setlayout{horizontal margin=2cm, vertical margin=2cm} |
| 5 |
\parindent=0pt |
| 6 |
\parskip=3pt plus 2pt minus 2pt |
| 7 |
|
| 8 |
\loadsyntax{TeX} |
| 9 |
\setsyntax{TeX} |
| 10 |
\everylisting={\lstlinenum=\z@} |
| 11 |
|
| 12 |
\def\mb{{\bf MeasureBox}} |
| 13 |
\def\macro#1{{\setfont{tt}\string#1}} |
| 14 |
\def\displaymacro#1{\quitvmode\kern-1cm\macro#1} |
| 15 |
\def\@setupverb{\setupverb\catcode`\ =10\relax} |
| 16 |
\def\inlinecode#1{ |
| 17 |
\bgroup% |
| 18 |
\@setupverb% |
| 19 |
\catcode`#1=2% |
| 20 |
\tt% |
| 21 |
} |
| 22 |
|
| 23 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 24 |
|
| 25 |
\centerline{\mbscalebox{5}{\mb}} |
| 26 |
\bigskip |
| 27 |
\centerline{Version \measureboxversion} |
| 28 |
\centerline{\measureboxauthor\ ---\ \measureboxemail} |
| 29 |
\bigskip |
| 30 |
|
| 31 |
\bgroup |
| 32 |
\leftskip=3cm plus 1fil \rightskip=\leftskip |
| 33 |
\hrule |
| 34 |
\medskip |
| 35 |
\mb{} is a package designed for measuring material. |
| 36 |
Its only dependency is the \url{https://ctan.org/pkg/pdftoolbox?lang=en}{\pdftoolbox} toolkit.\par |
| 37 |
\medskip |
| 38 |
\hrule |
| 39 |
\egroup |
| 40 |
\bigskip |
| 41 |
|
| 42 |
It provides four main macros: |
| 43 |
\blist |
| 44 |
\item \macro\mbscalebox; |
| 45 |
\item \macro\measurebox; |
| 46 |
\item \macro\measureh; |
| 47 |
\item \macro\measurew. |
| 48 |
\elist |
| 49 |
|
| 50 |
\displaymacro\mbscalebox{} is the simplest. |
| 51 |
It takes two inputs: a scale factor and material to scale, and then scales the material by the given factor. |
| 52 |
For example |
| 53 |
|
| 54 |
\blisting |
| 55 |
\mbscalebox{5}{Hello!} |
| 56 |
\elisting |
| 57 |
|
| 58 |
Will produce |
| 59 |
|
| 60 |
\centerline{\mbscalebox{5}{Hello!}} |
| 61 |
\bigskip |
| 62 |
|
| 63 |
\displaymacro\measurebox{} is the main player. |
| 64 |
It takes two arguments: the first is the material to measure, and the second is a list of \macro\measureh{} |
| 65 |
and \macro\measurew{} commands to add measurements. |
| 66 |
\macro\measurebox{} will draw a box around the material with a stroke width governed by \macro\mbstrokewd{} |
| 67 |
(non-dimension), with a dash pattern of \macro\mbdashwd{} (dimension), and a color determined by the color |
| 68 |
{\tt mbcolor}. |
| 69 |
It will then scale this box by a factor of \macro\mbscale. |
| 70 |
|
| 71 |
After boxing the material, \macro\measurebox{} sets \macro\mbwd, \macro\mbht, and \macro\mbdp{} to the width, |
| 72 |
height, and depth of the box respectively. |
| 73 |
These can then be used by the measurement commands. |
| 74 |
|
| 75 |
\displaymacro\measureh{} measures vertical dimensions. |
| 76 |
It accepts a single input, which is a list of key-value pairs. |
| 77 |
These keys are: |
| 78 |
\blist |
| 79 |
\item {\tt b} (default: \inlinecode|-\the\mbdp|): the height at which to begin the measurement; |
| 80 |
\item {\tt e} (required): the height at which to end the measurement; |
| 81 |
\item {\tt x} (default: \inlinecode|.5\mbwd|): the x-position to place the line connecting the beginning |
| 82 |
and end measurement; |
| 83 |
\item {\tt stroke} (default: .01): the stroke weight of the measurement; |
| 84 |
\item {\tt label}: the label of the measurement; |
| 85 |
\item {\tt color} (default: {\tt black}): the color to draw the measurement; |
| 86 |
\item {\tt dash}: the dash length to stroke the measurement with, if provided; |
| 87 |
\item {\tt legend} (valueless): add to add this measurement to the legend; |
| 88 |
\item {\tt noprint} (valueless): add to not print the label on the measurement. |
| 89 |
\elist |
| 90 |
|
| 91 |
\displaymacro\measurew{} measures horizontal dimensions. |
| 92 |
It accepts a single input, which is a list of key-value pairs. |
| 93 |
These keys are the same as \macro\measureh, except {\tt x} is swapped with {\tt y}, and the meanings of |
| 94 |
{\tt b}, {\tt e}, {\tt x} are the dual of their meanings for \macro\measureh{} (i.e. {\tt b} is the {\it width} |
| 95 |
at which to begin the measurement). |
| 96 |
|
| 97 |
The font scale at which the labels are printed (before magnification) is determined by \macro\mblblscale. |
| 98 |
|
| 99 |
For example |
| 100 |
|
| 101 |
\blisting |
| 102 |
\def\mbscale{7} |
| 103 |
\def\mbstrokewd{.01} |
| 104 |
\def\mblblscale{1pt} |
| 105 |
\measurebox{\mbnodp{$\prod$}}{% |
| 106 |
\measureh{b=.5\mbht, e=10pt, stroke=.01, color=blue, dash=.1, label=(top stroke top), noprint, legend}% |
| 107 |
\measureh{b=.5\mbht, e=9.6pt, stroke=.01, color=blue, dash=.1, label=(top stroke bot), noprint, legend}% |
| 108 |
\measurew{b=1.59pt, e=2.56pt, stroke=.01, color=red, dash=.1, label=(left stroke), noprint, legend}% |
| 109 |
\measurew{b=\mbwd-2.574pt, e=\mbwd, stroke=.01, color=red, dash=.1, label=(right stroke left), |
| 110 |
noprint, legend, y=.5\mbht-1pt}% |
| 111 |
\measurew{e=\mbwd, b=\mbwd-1.604pt, stroke=.01, color=red, dash=.1, label=(right stroke right), |
| 112 |
noprint, legend, y=.5\mbht-1pt}% |
| 113 |
\measurew{e=\mbwd, stroke=.01, color=green, y=2pt, label=(width), legend}% |
| 114 |
} |
| 115 |
\elisting |
| 116 |
|
| 117 |
will produce |
| 118 |
|
| 119 |
\bigskip |
| 120 |
\def\mbscale{7} |
| 121 |
\def\mbstrokewd{.01} |
| 122 |
\def\mblblscale{1pt} |
| 123 |
\centerline{\measurebox{\mbnodp{$\prod$}}{% |
| 124 |
\measureh{b=.5\mbht, e=10pt, stroke=.01, color=blue, dash=.1, label=(top stroke top), noprint, legend}% |
| 125 |
\measureh{b=.5\mbht, e=9.6pt, stroke=.01, color=blue, dash=.1, label=(top stroke bot), noprint, legend}% |
| 126 |
\measurew{b=1.59pt, e=2.56pt, stroke=.01, color=red, dash=.1, label=(left stroke), noprint, legend}% |
| 127 |
\measurew{b=\mbwd-2.574pt, e=\mbwd, stroke=.01, color=red, dash=.1, label=(right stroke left), |
| 128 |
noprint, legend, y=.5\mbht-1pt}% |
| 129 |
\measurew{e=\mbwd, b=\mbwd-1.604pt, stroke=.01, color=red, dash=.1, label=(right stroke right), |
| 130 |
noprint, legend, y=.5\mbht-1pt}% |
| 131 |
\measurew{e=\mbwd, stroke=.01, color=green, y=2pt, label=(width), legend}% |
| 132 |
}} |
| 133 |
|
| 134 |
\bye |
| 135 |
|