| 1 |
\documentclass{article} |
| 2 |
\def\version{1.8} |
| 3 |
% |
| 4 |
% This work may be distributed and/or modified under the |
| 5 |
% conditions of the LaTeX Project Public License, either version 1.3 |
| 6 |
% of this license or (at your option) any later version. |
| 7 |
% The latest version of this license is in |
| 8 |
% http://www.latex-project.org/lppl.txt |
| 9 |
% and version 1.3c or later is part of all distributions of LaTeX |
| 10 |
% version 2005/12/01 or later. |
| 11 |
% |
| 12 |
% This work has the LPPL maintenance status `maintained'. |
| 13 |
% |
| 14 |
% The Current Maintainer of this work is Steven B. Segletes. |
| 15 |
|
| 16 |
% V1.01 Correct typos in documentation |
| 17 |
% V1.1 Corrected usepackage dependencies; Significant doc rewrite. |
| 18 |
% V1.11 Corrected typo in documentation |
| 19 |
% V1.2 Added \scaleleftright and \stretchleftright; revised docs. |
| 20 |
% V1.3 Corrected missing % in stretch routines, added \hstretch and |
| 21 |
% \vstretch commands; fixed version number in .sty file |
| 22 |
% V1.4 -Auto-detect mathmode and style; use the proper math display |
| 23 |
% style; Allow \ignoremathstyle and \discernmathstyle to |
| 24 |
% revert to former approach in rare cases and return to new |
| 25 |
% approach. |
| 26 |
% -Added \Isnextbyte as a supplemental routine |
| 27 |
% -Added \scaleobj (like \scalebox, but defaults to math mode |
| 28 |
% using current display style). |
| 29 |
% V1.5 -Eliminated mathstyle package because of incompatibilites with |
| 30 |
% many other packages. Implemented \mathchoice approach instead. |
| 31 |
% V1.6 -Made available \LMex and \LMpt lengths (Local Math ex and |
| 32 |
% Local Math pt), usable inside \ThisStyle arguments (1ex/pt in |
| 33 |
% \textstyle and \displaystyle, 0.7ex/pt in \scriptstyle, and |
| 34 |
% 0.5ex/pt in \scriptscriptstyle). |
| 35 |
% -Revised/shortened/improved \Isnextbyte. |
| 36 |
% -Replaced ifthen package calls with etoolbox calls. |
| 37 |
% V1.7 -Note that the V1.5 implementation with \mathchoice seemed to |
| 38 |
% have made the use of \ignoremathstyle and \discernmathstyle |
| 39 |
% vestigial. Thus, \ignoremathstyle was revised to be used |
| 40 |
% for the purpose of streamlining package efficiency when |
| 41 |
% only textstyle (or displaystyle with \ignoremathstyle[D]) |
| 42 |
% processing is required. |
| 43 |
% -Fixed use of dot {.} as null argument in \scaleleftright{}{}{} |
| 44 |
% and \stretchleftright{}{}{}, which had been causing overflow. |
| 45 |
% -Made \hstretch and \vstretch routines more efficient, using |
| 46 |
% optional arguments of \scalebox, instead of \scalerel. |
| 47 |
% V1.8 -Fixed divide by 0 bugs that would arise when object to be |
| 48 |
% scaled fell completely below the baseline (zero height). |
| 49 |
% Required revisions to \scalerelplain, \stretchrelplain, |
| 50 |
% \scaleto, and \stretchto. |
| 51 |
% -Fixed aspect-ratio bug, that calculated aspect for stretched object |
| 52 |
% based only upon portion above baseline |
| 53 |
\parskip 1em |
| 54 |
\parindent 0em |
| 55 |
\newcommand\rl{\rule{2em}{0in}} |
| 56 |
\usepackage{scalerel} |
| 57 |
\usepackage{verbatim} |
| 58 |
\usepackage[only,llbracket,rrbracket,llparenthesis,rrparenthesis]{stmaryrd} |
| 59 |
\usepackage{stackengine} |
| 60 |
\usepackage{accsupp} % for ensuring the right Unicode codepoint upon pasting |
| 61 |
\def\sr{\textsf{scalerel}} |
| 62 |
\let\vb\verb |
| 63 |
\reversemarginpar |
| 64 |
\marginparwidth 1.6in |
| 65 |
\newcommand\margtt[1]{\marginpar{\hfill\ttfamily#1}} |
| 66 |
\newcommand\margcmd[1]{\marginpar{\hfill\ttfamily\char'134#1}} |
| 67 |
\newcommand\cmd[1]{\texttt{\char'134#1}} |
| 68 |
\begin{document} |
| 69 |
\begin{center} |
| 70 |
\LARGE The \textsf{scalerel} Package\\ |
| 71 |
\rule{0em}{.7em}\small Routines for constrained scaling and stretching |
| 72 |
of objects,\\relative to a reference object or in absolute terms\\ |
| 73 |
\rule{0em}{2.7em}\large Steven B. Segletes\\ |
| 74 |
[email protected]\\ |
| 75 |
\rule{0em}{1.7em}\today\\ |
| 76 |
v\version |
| 77 |
\end{center} |
| 78 |
|
| 79 |
\section{Commands and Description} |
| 80 |
|
| 81 |
The \textsf{scalerel} package is used to scale and vertically stretch |
| 82 |
objects, either relative to other objects, or in absolute terms. |
| 83 |
Its commands may be invoked in either math mode or text mode (if there |
| 84 |
is no math in the objects to manipulate); |
| 85 |
however, the objects it manipulates will, by default, be processed in |
| 86 |
math mode. |
| 87 |
Nonetheless, one may process the objects in text mode (assuming they |
| 88 |
do not contain math-specific characters or commands) by |
| 89 |
[non-intuitively] specifying arguments as \vb|{$object$}|, instead |
| 90 |
of the usual \vb|{object}|. |
| 91 |
|
| 92 |
There are four basic commands with the \textsf{scalerel} package, two |
| 93 |
of which have star variants: |
| 94 |
\begin{verbatim} |
| 95 |
\scalerel[*][max_width]{object}{reference} |
| 96 |
\stretchrel[*][narrowest_aspect]{object}{reference} |
| 97 |
\scaleto[max_width]{object}{height} |
| 98 |
\stretchto[narrowest_aspect]{object}{height} |
| 99 |
\end{verbatim} |
| 100 |
In addition, there are a number of added commands that have been |
| 101 |
implemented as composites of the four basic commands, they are |
| 102 |
\begin{verbatim} |
| 103 |
\scaleleftright[max_width]{left-obj.}{reference}{right-obj.} |
| 104 |
\stretchleftright[narrowest_aspect]{left-obj.}{reference}{right-obj.} |
| 105 |
\hstretch{scale}{object} |
| 106 |
\vstretch{scale}{object} |
| 107 |
\scaleobj{scale}{object} |
| 108 |
\end{verbatim} |
| 109 |
Unless delimited for text mode, \texttt{object} is assumed to be a math |
| 110 |
object and will be processed in the \textit{current} math style.% |
| 111 |
\footnote{By \LaTeX{} math styles, we mean \cmd{displaystyle}, \cmd{textstyle}, |
| 112 |
\cmd{scriptstyle}, and \cmd{scriptscriptstyle}.} |
| 113 |
On the other hand, \texttt{reference} will take on the current mode (text |
| 114 |
or math). |
| 115 |
If in math mode, \texttt{reference} will likewise be taken in the current |
| 116 |
math style. |
| 117 |
|
| 118 |
There are also several auxiliary commands, useful in their own |
| 119 |
right: |
| 120 |
\begin{verbatim} |
| 121 |
\ThisStyle{...\SavedStyle...} |
| 122 |
\LMex |
| 123 |
\LMpt |
| 124 |
\def\scriptstyleScaleFactor{0.7} |
| 125 |
\def\scriptscriptstyleScaleFactor{0.5} |
| 126 |
\Isnextbyte[[v] OR q]{test byte}{string} |
| 127 |
\ignoremathstyle[D] |
| 128 |
\discernmathstyle |
| 129 |
\end{verbatim} |
| 130 |
|
| 131 |
In the case of all \sr{} macros, \vb|object| is the object to be scaled or |
| 132 |
stretched. It can be as simple as a symbol, like a summation sign |
| 133 |
($\sum$), or it can be an object of complex description. Likewise, in |
| 134 |
cases of \textit{relative} scaling and stretching, \vb|reference| is |
| 135 |
the reference object in relation to which the manipulated |
| 136 |
\vb|object| is scaled or vertically stretched. The \vb|reference| |
| 137 |
may likewise be of complex description (such as a mathematical |
| 138 |
expression). When an \vb|object| is scaled or stretched |
| 139 |
\textit{relative} to a \vb|reference| object, it is also vertically |
| 140 |
shifted, if necessary, so that its vertical extent conforms to that of |
| 141 |
the \vb|reference| object. |
| 142 |
|
| 143 |
In cases of scaling or stretching \textit{to} a specified size, |
| 144 |
\vb|height| will be the \textit{total} vertical height${}+{}$depth of |
| 145 |
the \vb|object| following a scale or stretch manipulation. |
| 146 |
Since scaling or stretching to an |
| 147 |
absolute size provides no \vb|reference| object, the baseline of |
| 148 |
the manipulated \vb|object| remains unchanged. |
| 149 |
|
| 150 |
In cases of scaling (relative or absolute), the constraint |
| 151 |
\vb|max_width| is optionally specified as the maximum width allowable |
| 152 |
for the manipulated object. |
| 153 |
If the manipulated width would otherwise exceed this limit, the |
| 154 |
\vb|object| width is reduced to meet this limit. |
| 155 |
If the \vb|object| width is reduced, its aspect ratio will change with |
| 156 |
respect to its original shape. |
| 157 |
|
| 158 |
By definition, vertical stretching will increase the (height-to-width) |
| 159 |
aspect ratio |
| 160 |
of an object. |
| 161 |
In the case of stretching (relative or absolute), the constraint |
| 162 |
\vb|narrowest_aspect| is the narrowest aspect ratio allowed by the |
| 163 |
stretch.% |
| 164 |
\footnote{Prior to V1.8 of the package, the limiting aspect ratio was |
| 165 |
erroneously based on that portion of the stretched object |
| 166 |
\textit{above} the baseline, rather than the object's full vertical extent.} |
| 167 |
Its value is given in \%, such that a parameter value of \texttt{100} |
| 168 |
indicates 100\% or an aspect ratio of 1. |
| 169 |
If the stretch would otherwise cause the manipulated \vb|object|'s |
| 170 |
aspect ratio to become more narrow than (\textit{i.e.}, larger |
| 171 |
than) this value, the width of the manipulated \vb|object| is |
| 172 |
increased to meet this threshold. |
| 173 |
The value of \vb|narrowest_aspect| must be an integer. |
| 174 |
|
| 175 |
Because \textit{relative} scaling or stretching is done |
| 176 |
\textit{relative} to a reference object, the \vb|\scalerel| and |
| 177 |
\margcmd{scalerel}\margcmd{stretchrel}% |
| 178 |
\vb|\stretchrel| commands will, by default, print out the |
| 179 |
manipulated \vb|object| followed immediately by the \vb|reference| |
| 180 |
object. Because this may not always be desired, the star (*) version of |
| 181 |
these commands suppresses the output of the \vb|reference| object, so |
| 182 |
that only the \vb|object| that was manipulated is output. |
| 183 |
|
| 184 |
The \vb|\scaleleftright| and \vb|\stretchleftright| commands |
| 185 |
\margcmd{scaleleftright}\margcmd{stretchleftright}% |
| 186 |
are intended to provide the functional capability of the \vb|\left| and |
| 187 |
\vb|\right| commands in math mode, for delimiting symbols not |
| 188 |
otherwise supported by those commands. |
| 189 |
|
| 190 |
The \vb|\hstretch| and \vb|\vstretch commands| merely take the |
| 191 |
\margcmd{hstretch}\margcmd{vstretch}% |
| 192 |
second argument and either horizontally or vertically stretch it by a |
| 193 |
scale factor given by the first argument. The scale is not given in |
| 194 |
percent, like some aforementioned commands. Remember also, that these |
| 195 |
commands are, by default processed in math mode. In a like manner, |
| 196 |
\margcmd{scaleobj}% |
| 197 |
\vb|\scaleobj| performs a scale of the object. It is like the |
| 198 |
\vb|\scalebox| command of the \textsf{graphicx} package, except that |
| 199 |
its argument (like others in this package) defaults to math mode, and is |
| 200 |
displayed in the current math display style. |
| 201 |
|
| 202 |
A useful auxiliary command \vb|\ThisStyle{}| has been introduced for |
| 203 |
\margcmd{ThisStyle}% |
| 204 |
remembering the current math style. When invoked, this command will |
| 205 |
remember the math style present at the time of its invocation and then |
| 206 |
execute its argument. Within the extent of its argument, an invocation |
| 207 |
\margcmd{SavedStyle}% |
| 208 |
of the macro \vb|\SavedStyle| will reinstate the math style that was |
| 209 |
active upon invocation. This command is very useful when \LaTeX{} boxes |
| 210 |
are being set within the math environment, since the prevailing math |
| 211 |
style does not carry into the box, without the use of |
| 212 |
\vb|\SavedStyle|. |
| 213 |
|
| 214 |
The lengths \verb|\LMex| and \verb|\LMpt| work in conjunction with |
| 215 |
\verb|\ThisStyle| |
| 216 |
\margcmd{LMex}% |
| 217 |
\margcmd{LMpt}% |
| 218 |
and are what I am calling the ``local-mathstyle `ex'\,'' |
| 219 |
and ``local-mathstyle `pt','' respectively. |
| 220 |
They are lengths, available for use within the argument of \verb|\ThisStyle|, |
| 221 |
that scale with the current mathstyle, equalling 1ex and 1pt in |
| 222 |
\verb|\displaystyle| and \verb|\textstyle| math, and scaled by a |
| 223 |
factor of 0.7 in \verb|\scriptstyle| and 0.5 in \verb|\scriptscriptstyle|. |
| 224 |
Such a scalable length is useful when {\sr} is used to place objects |
| 225 |
\margcmd{scriptstyleScaleFactor}% |
| 226 |
relative to each other across various mathstyles. The 0.7 and 0.5 |
| 227 |
relative height factors apply to the default Computer Modern font. |
| 228 |
\margcmd{\footnotesize scriptscriptstyleScaleFactor}% |
| 229 |
For other fonts, these scale factors may be reset with a \verb|\def| |
| 230 |
on the macros \verb|\scriptstyleScaleFactor| and |
| 231 |
\verb|\scriptscriptstyleScaleFactor|. |
| 232 |
|
| 233 |
A service routine \vb|\Isnextbyte| was employed by this package. |
| 234 |
\margcmd{Isnextbyte}% |
| 235 |
Because of its more general utility, it is made accessible to the user. |
| 236 |
It is an improved version of the command \vb|\isnextbyte| from the |
| 237 |
\textsf{stringstrings} package. It will determine if the first |
| 238 |
byte from a passed string argument matches a specified |
| 239 |
\textit{match}-character. It produces a \vb|T| or \vb|F| result, |
| 240 |
which is printed out by default. With the use of the \vb|q| optional |
| 241 |
argument, the output can be suppressed, with the result instead being |
| 242 |
stored in a macro \vb|\theresult|. |
| 243 |
|
| 244 |
\subsection{Efficiency of nested \sr{} macros\label{s:nm}} |
| 245 |
|
| 246 |
As of version 1.4, {\sr} commands will autodetect the current math |
| 247 |
display style (so-called display-style, text-style, script-style, and/or |
| 248 |
scriptscript-style) and process its arguments in the same mode. The |
| 249 |
overhead associated with this capability is an invocation of |
| 250 |
\vb|\mathchoice|, which must create 4 boxes (one in each math style) |
| 251 |
before selecting one |
| 252 |
to typeset. While a small overhead in itself, an efficiency issue |
| 253 |
can arise when \sr{} macros are nested, since if 3 \sr{} macros |
| 254 |
are nested, \vb|\mathchoice| will build $4^3=64$ boxes in order |
| 255 |
to select the proper one to typeset (and a nesting level of 4 yields |
| 256 |
256 boxes). |
| 257 |
|
| 258 |
With the use of \vb|\ignoremathstyle|, the math style of the \sr{} |
| 259 |
\margcmd{ignoremathstyle}% |
| 260 |
processing can be fixed in a single math style, thus eliminating the |
| 261 |
construction of \vb|\mathchoice| boxes. The increase in processing |
| 262 |
efficiency can be noticeable when operating on deeply nested \sr{} |
| 263 |
macros. |
| 264 |
|
| 265 |
The invocation of \vb|\ignoremathstyle| will force all subsequent |
| 266 |
\sr{} calls to process its arguments in \vb|\textstyle| math. |
| 267 |
Alternately, \vb|\ignoremathstyle[D]| will force the processing |
| 268 |
of \sr{} macros in \vb|\displaystyle| math. |
| 269 |
|
| 270 |
\begin{sloppypar} |
| 271 |
This streamlining can be undone, reinstating the more general |
| 272 |
math-style preserving approach, with the invocation of |
| 273 |
\vb|\discernmathstyle|. |
| 274 |
\margcmd{discernmathstyle}% |
| 275 |
These macros can be used anywhere in a document by a user, to turn off |
| 276 |
and on the \vb|\mathchoice| feature of \sr{}, or they may be |
| 277 |
used within user macro definitions, to fix the math style by which |
| 278 |
\sr{} processes its macros within the confines of the user macro. |
| 279 |
\end{sloppypar} |
| 280 |
|
| 281 |
\section{Usage Examples} |
| 282 |
|
| 283 |
Now for a few examples. Let us define |
| 284 |
\begin{verbatim} |
| 285 |
\def\preblob{\displaystyle\sum_{i=0}^3} |
| 286 |
\def\blob{\displaystyle\frac{\displaystyle\frac{x^3}{z+r^3}}% |
| 287 |
{\displaystyle\frac{y}{x^2}}% |
| 288 |
} |
| 289 |
\end{verbatim} |
| 290 |
\def\preblob{\displaystyle\sum_{i=0}^3} |
| 291 |
\def\blob{\displaystyle\frac{\displaystyle\frac{x^3}{z+r^3}}% |
| 292 |
{\displaystyle\frac{y}{x^2}}% |
| 293 |
} |
| 294 |
Here are the raw definitions of \vb|$\preblob\blob$|, unscaled: |
| 295 |
|
| 296 |
\rl$\preblob\blob$ |
| 297 |
|
| 298 |
\subsection{The $\backslash$\texttt{scalerel} Command} |
| 299 |
|
| 300 |
Now we employ \vb|$\scalerel{\preblob}{\blob}$| to scale the summation |
| 301 |
to match the size of the acted-upon term: |
| 302 |
|
| 303 |
\rl$\scalerel{\preblob}{\blob}$ |
| 304 |
|
| 305 |
If we wish constrain the width of the summation to 3ex, we employ\\ |
| 306 |
\vb|$\scalerel[3ex]{\preblob}{\blob}$| |
| 307 |
|
| 308 |
\rl$\scalerel[3ex]{\preblob}{\blob}$ |
| 309 |
|
| 310 |
Of course, if the manipulated object contains text symbols (as in |
| 311 |
this case), a width constraint will change their aspect ratio, |
| 312 |
which is generally not desirable. |
| 313 |
|
| 314 |
Now let's say you wanted to introduce notation to bound mathematical |
| 315 |
expressions by triangles. After defining |
| 316 |
\vb|\blob| as before, you could use\\ |
| 317 |
\vb|$\scalerel[3ex]{\triangleleft}{\blob}|\\ |
| 318 |
\vb|\scalerel*[3ex]{\triangleright}{\blob}$| |
| 319 |
|
| 320 |
\rl% |
| 321 |
$\scalerel[3ex]{\triangleleft}{\blob}\scalerel*[3ex]{\triangleright}{\blob}$ |
| 322 |
|
| 323 |
Here, the second call to \vb|\scalerel| was with the star (\vb|*|) |
| 324 |
option, indicating that \vb|\blob| should not be printed out following |
| 325 |
the right-hand delimiter. A less-tall expression would appear in those |
| 326 |
same delimiters as |
| 327 |
|
| 328 |
\rl% |
| 329 |
$\scalerel[3ex]{\triangleleft}{Q}\scalerel*[3ex]{\triangleright}{Q}$ |
| 330 |
|
| 331 |
Because the width limit had not been reached, no horizontal compression |
| 332 |
of the object was required. Note: see the \vb|\scaleleftright| and |
| 333 |
\vb|\stretchleftright| commands for a more direct way to employ these |
| 334 |
sort of transformations. |
| 335 |
|
| 336 |
\subsection{The $\backslash$\texttt{stretchrel} Command} |
| 337 |
|
| 338 |
In its most simple application \vb|\stretchrel| can be used in the |
| 339 |
fashion of a \vb|\left\{| in math mode. While there is no reason to |
| 340 |
replace that more efficient usage supplied by \LaTeX{}, it is |
| 341 |
nonetheless instructional to see a comparison of |
| 342 |
\vb|$\left\{\blob\right.$| and \vb|$\stretchrel[550]{\{}{\blob}$|, to |
| 343 |
see how the aspect-ratio limiting option can be employed to avoid an |
| 344 |
overly stretched (narrow) manipulation: |
| 345 |
|
| 346 |
\rl$\left\{\blob\right.$ ~~~~~ $\stretchrel[550]{\{}{\blob}$ |
| 347 |
|
| 348 |
The expression on the right uses a standard \{ character, which has |
| 349 |
been vertically stretched, but limited to an aspect ratio no |
| 350 |
narrower than 5.5. |
| 351 |
To use symbols for which the \vb|\left| nomenclature will not work, |
| 352 |
\vb|\stretchrel| provides a viable alternative, as shown in this |
| 353 |
stick-figure example: |
| 354 |
|
| 355 |
\vb|3m $\stretchrel[600]{\updownarrow\,}|\\ |
| 356 |
\vb|{\fbox{\rule[-1.8em]{0ex}{4em}Work Table}}$| |
| 357 |
|
| 358 |
\rl3m $\stretchrel[600]{\updownarrow\,} |
| 359 |
{\fbox{\rule[-1.8em]{0ex}{4em}Work Table}}$ |
| 360 |
|
| 361 |
or in this use, \vb|$\stretchrel[350]{\int}{\blob} dx$|, of the |
| 362 |
stretched integral sign (aspect limited to 3.5): |
| 363 |
|
| 364 |
\rl$\stretchrel[350]{\int}{\blob} dx$ |
| 365 |
|
| 366 |
|
| 367 |
\subsection{Baseline Shifts of \textit{Relative} Scales and Stretches} |
| 368 |
|
| 369 |
It was mentioned that when \vb|\scalerel| and \vb|\stretchrel| are |
| 370 |
employed, the manipulated object gets vertically shifted to match the |
| 371 |
extent of the reference object. To see how this works, we provide the |
| 372 |
following example, that employs some inline math and scaling. |
| 373 |
|
| 374 |
\rl\underline{The baseline is the line that runs under this text} |
| 375 |
\fbox{$\scalerel{i}{\blob}$}\underline{\scaleto{i}{35pt}} |
| 376 |
|
| 377 |
The first case of the large letter ``i'' was generated with |
| 378 |
\vb|\scalerel|, and so the baseline of the ``i'', normally not a |
| 379 |
descending letter, was dropped to conform to the descended reference |
| 380 |
equation. |
| 381 |
All of this was set in an \vb|\fbox| to show the extent of |
| 382 |
the objects. |
| 383 |
For comparison, an ``i'', scaled to 35pt, was then placed |
| 384 |
using a \vb|\scaleto| command, which does not change the baseline of |
| 385 |
the original object. |
| 386 |
|
| 387 |
\subsection{The $\backslash$\texttt{scaleto} and |
| 388 |
$\backslash$\texttt{stretchto} Commands} |
| 389 |
|
| 390 |
The \vb|\scaleto| and \vb|\stretchto| commands are comparable to the |
| 391 |
\vb|\scalerel| and \vb|\stretchrel| commands, except they do not |
| 392 |
accept a reference object as their second mandatory argument. |
| 393 |
Rather, they take an absolute height (\textit{i.e.}, height${}+{}$depth), |
| 394 |
specified with units. |
| 395 |
These commands use the same optional arguments as \vb|\scalerel| and |
| 396 |
\vb|\stretchrel| to constrain the width and/or the aspect ratio, |
| 397 |
respectively, of the manipulated object. |
| 398 |
|
| 399 |
As was mentioned in the prior section, a difference between these and |
| 400 |
the \textit{relative} scale/stretch commands is that an object's |
| 401 |
baseline is not altered with the use of \vb|\scaleto| and |
| 402 |
\vb|\stretchto|. |
| 403 |
Because there is no reference object employed with these commands, |
| 404 |
there is no need for starred (\vb|*|) versions of these commands, |
| 405 |
which would otherwise suppress the printing of the reference object. |
| 406 |
|
| 407 |
Examples follow the established pattern established in prior sections. |
| 408 |
First, we scale the equation blob used as an example in this |
| 409 |
documentation to a vertical extent of 80pt, preserving the original |
| 410 |
aspect ratio, |
| 411 |
|
| 412 |
\rl\vb|$\scaleto{\blob}{80pt}$ | $\scaleto{\blob}{80pt}$ |
| 413 |
|
| 414 |
Below, we stretch the Greek letter, capital phi, to 60pt, but constrain |
| 415 |
the aspect ratio to no less than 1.75. |
| 416 |
|
| 417 |
\rl\vb|$\stretchto[175]{\Phi}{60pt}$ | $\stretchto[175]{\Phi}{80pt}$ |
| 418 |
|
| 419 |
\subsection{The $\backslash$\texttt{scaleleftright} and |
| 420 |
$\backslash$\texttt{stretchleftright}\\Commands} |
| 421 |
|
| 422 |
These commands are composites of several \vb|\scalerel| and |
| 423 |
\vb|\stretchrel| commands, intended to provide the functionality of |
| 424 |
the \vb|\left ...\right| syntax of mathmode, using symbols for which |
| 425 |
the \vb|\left ...\right| syntax does not work. It uses the same |
| 426 |
optional arguments as \vb|\scalerel| and \vb|\stretchrel| in order |
| 427 |
to limit the width or aspect ratio of the respective manipulated |
| 428 |
objects. If one of the symbols on the left or right end of the enclosed |
| 429 |
reference block is to be blank, these commands support the use of the |
| 430 |
period argument \vb|{.}| as a blank placeholder, in a fashion |
| 431 |
analogous to the \vb|\left ...\right| syntax of mathmode. |
| 432 |
|
| 433 |
\rl\vb|$\scaleleftright[3ex]{\prod}{\blob}{\coprod}$ | |
| 434 |
$\scaleleftright[3ex]{\prod}{\blob}{\coprod}$ |
| 435 |
|
| 436 |
\rl\vb|$\stretchleftright[450]{.}{\blob}{\in}$ | |
| 437 |
$\stretchleftright[450]{.}{\blob}{\in}$ |
| 438 |
|
| 439 |
\subsection{The $\backslash$\texttt{hstretch}, |
| 440 |
$\backslash$\texttt{vstretch}, and $\backslash$\texttt{scaleobj} |
| 441 |
Commands} |
| 442 |
|
| 443 |
These commands simply perform horizontal or vertical stretching, |
| 444 |
respectively. They use a scale factor, rather than an absolute length. |
| 445 |
If the stretch factor is greater than 1, the stretched length is larger |
| 446 |
than the original. If less than one, it is compressed with respect to |
| 447 |
the original. |
| 448 |
|
| 449 |
\rl\vb|$\otimes\hstretch{3}{\otimes}\hstretch{0.5}{\otimes}$ | |
| 450 |
$\otimes\hstretch{3}{\otimes}\hstretch{0.5}{\otimes}$ |
| 451 |
|
| 452 |
\rl\vb|$\otimes\vstretch{3}{\otimes}\vstretch{0.5}{\otimes}$ | |
| 453 |
$\otimes\vstretch{3}{\otimes}\vstretch{0.5}{\otimes}$ |
| 454 |
|
| 455 |
The \vb|\scaleobj| command performs scaling in the fashion of a |
| 456 |
\vb|\scalebox| command, except that its argument is processed in math |
| 457 |
mode of the current math display style, by default. Thus, the |
| 458 |
difference between the following two invocations: |
| 459 |
\begin{verbatim} |
| 460 |
\(\scaleobj{2}{\sum_{i=0}^{n}}\) |
| 461 |
\[\scaleobj{2}{\sum_{i=0}^{n}}\] |
| 462 |
\end{verbatim} |
| 463 |
is given as |
| 464 |
\(\scaleobj{2}{\sum_{i=0}^{n}}\) versus |
| 465 |
\[\scaleobj{2}{\sum_{i=0}^{n}}\] |
| 466 |
|
| 467 |
\subsection{The \textbackslash\texttt{ThisStyle}, \textbackslash\texttt{SavedStyle}, |
| 468 |
\textbackslash\texttt{LMex}, and \textbackslash\texttt{LMpt} Commands} |
| 469 |
|
| 470 |
These are very powerful macros that provide the ability to save the current |
| 471 |
math style and to import it to various places (for example, inside boxes and other |
| 472 |
macros) where the math style would otherwise be lost. These commands are |
| 473 |
part of this package because the various {\sr} macros employ them to |
| 474 |
automatically import the current math style into their arguments. |
| 475 |
|
| 476 |
The easiest way to show how these macros are used is to provide a working |
| 477 |
example, such as the one given below. |
| 478 |
|
| 479 |
\begin{verbatim} |
| 480 |
\documentclass{article} |
| 481 |
\usepackage{stackengine} |
| 482 |
\usepackage{graphicx} |
| 483 |
\usepackage{scalerel} |
| 484 |
\stackMath |
| 485 |
\def\ccdot{\scalebox{1.15}{$\SavedStyle\cdot$}} |
| 486 |
\def\altdiv{\mathbin{\ThisStyle{% |
| 487 |
\stackunder[-.6\LMex]{% |
| 488 |
\stackon[-.45\LMex]{\SavedStyle\sim}{\ccdot}% |
| 489 |
}{\ccdot}}}} |
| 490 |
\begin{document} |
| 491 |
$A \altdiv B ~~A \div B$\par |
| 492 |
$\scriptstyle A \altdiv B ~~A \div B$\par |
| 493 |
$\scriptscriptstyle A \altdiv B ~~A \div B$\par |
| 494 |
\end{document} |
| 495 |
\end{verbatim} |
| 496 |
|
| 497 |
The output of this example shows a fabricated glyph (\verb|\altdiv|) across the |
| 498 |
math styles, comparing it to \verb|\div|: |
| 499 |
|
| 500 |
\stackMath |
| 501 |
\def\ccdot{\scalebox{1.15}{$\SavedStyle\cdot$}} |
| 502 |
\def\altdiv{\mathbin{\ThisStyle{% |
| 503 |
\stackunder[-.6\LMex]{\stackon[-.45\LMex]{\SavedStyle\sim}{\ccdot}}{\ccdot}}}} |
| 504 |
\rl\scalebox{3}{\parbox{2in}{ |
| 505 |
$A \altdiv B ~~A \div B$\par |
| 506 |
$\scriptstyle A \altdiv B ~~A \div B$\par |
| 507 |
$\scriptscriptstyle A \altdiv B ~~A \div B$\par |
| 508 |
}} |
| 509 |
|
| 510 |
The difficulties that must be overcome are several: the composite glyph is created by |
| 511 |
way of a stack, which processes its arguments in either text mode or \verb|\textstyle| |
| 512 |
math mode; and the stacking distances between the components of the composite |
| 513 |
glyph need to vary with the mathstyle. To overcome the first issue, the \verb|\altdiv| |
| 514 |
macro is wrapped in a \verb|\ThisStyle{...}| wrapper. Whenever one of the glyph |
| 515 |
components (\textit{e.g.}, \verb|\sim| or \verb|\cdot|) is employed within the |
| 516 |
\textsf{stackengine} where the mathstyle is |
| 517 |
otherwise lost, it is prepended with a \verb|\SavedStyle| to reinstate the current |
| 518 |
math style. Thus, the glyph components will present in the proper mathstyle. |
| 519 |
Likewise, the vertical stacking gaps between the glyph components, |
| 520 |
given as optional arguments to the stacking commands, are here specified in |
| 521 |
multiples of \verb|\LMex|. In this way, the stacking gaps will shrink with the |
| 522 |
smaller math styles, keeping the spacings on the same relative scale as the size |
| 523 |
of the smaller glyphs. |
| 524 |
|
| 525 |
\section{Real World Application} |
| 526 |
|
| 527 |
\subsection{White Curly Brackets} |
| 528 |
|
| 529 |
Ref: http://tex.stackexchange.com/questions/100966/defining- |
| 530 |
scalable-white- curly-brackets-and-and |
| 531 |
|
| 532 |
\newcommand*{\llbrace}{% |
| 533 |
\BeginAccSupp{method=hex,unicode,ActualText=2983}% |
| 534 |
\textnormal{\usefont{OMS}{lmr}{m}{n}\char102}% |
| 535 |
\mathchoice{\mkern-4.05mu}{\mkern-4.05mu}{\mkern-4.3mu}{\mkern-4.8mu}% |
| 536 |
\textnormal{\usefont{OMS}{lmr}{m}{n}\char106}% |
| 537 |
\EndAccSupp{}% |
| 538 |
} |
| 539 |
\newcommand*{\rrbrace}{% |
| 540 |
\BeginAccSupp{method=hex,unicode,ActualText=2984}% |
| 541 |
\textnormal{\usefont{OMS}{lmr}{m}{n}\char106}% |
| 542 |
\mathchoice{\mkern-4.05mu}{\mkern-4.05mu}{\mkern-4.3mu}{\mkern-4.8mu}% |
| 543 |
\textnormal{\usefont{OMS}{lmr}{m}{n}\char103}% |
| 544 |
\EndAccSupp{}% |
| 545 |
} |
| 546 |
|
| 547 |
A user defined two new symbols made by combining the font glyphs of a |
| 548 |
brace and a vertical strut, calling them \vb|\llbrace| and |
| 549 |
\vb|\rrbrace|, to look as follows around an argument (in this case |
| 550 |
$x$): |
| 551 |
|
| 552 |
\def\wbrace{\scalebox{5}{$\llbrace x\rrbrace$}} |
| 553 |
\rl\wbrace |
| 554 |
|
| 555 |
But they found that when represented in reduced size fonts, the symbol |
| 556 |
glyphs of the brace and the strut separated (note: \vb|\tiny| font has |
| 557 |
been scaled up to match prior figure's height): |
| 558 |
|
| 559 |
\def\tinywbrace{\scalebox{3}{\tiny$\llbrace x\rrbrace$}} |
| 560 |
\rl$\scalerel*{\tinywbrace}{\wbrace}$ |
| 561 |
|
| 562 |
This happens because font designers don't merely scale their fonts when |
| 563 |
shrunk down in size, but they do things (like thickening up lines and |
| 564 |
changing aspect ratios) in an attempt to retain legibility. In this |
| 565 |
case, the font's auto-adjustment at smaller scale caused this composite |
| 566 |
representation to change in unacceptable ways. |
| 567 |
|
| 568 |
The \textsf{scalerel} solution was to use the image from the normal-size |
| 569 |
representation and to shrink it down as needed. So, in this case, a |
| 570 |
normal-sized copy of the braces were stored in boxes called |
| 571 |
\vb|\lXbrace| and \vb|\rXbrace|, resepctively. Then the following |
| 572 |
terms were defined: |
| 573 |
\begin{verbatim} |
| 574 |
\def\lxbrace{\scalerel*{\usebox{\lXbrace}}{\llbrace}} |
| 575 |
\def\rxbrace{\scalerel*{\usebox{\rXbrace}}{\rrbrace}} |
| 576 |
\end{verbatim} |
| 577 |
Now, in lieu of using \vb|\llbrace| directly, the use of |
| 578 |
\vb|\lxbrace| would take a copy of the normal-sized \vb|\lXbrace| |
| 579 |
and scale it down to the vertical height of the malformed tiny |
| 580 |
\vb|\llbrace|, and substitute for it. Here, we show the result at |
| 581 |
both normal size and tiny size: |
| 582 |
|
| 583 |
\newsavebox{\lXbrace} |
| 584 |
\savebox{\lXbrace}{$\llbrace$} |
| 585 |
\newsavebox{\rXbrace} |
| 586 |
\savebox{\rXbrace}{$\rrbrace$} |
| 587 |
\def\lxbrace{\scalerel*{\usebox{\lXbrace}}{\llbrace}} |
| 588 |
\def\rxbrace{\scalerel*{\usebox{\rXbrace}}{\rrbrace}} |
| 589 |
\rl$\scalerel*{\lxbrace x\rxbrace}{\wbrace}$ |
| 590 |
{\tiny$\scalerel*{\lxbrace x\rxbrace}{\wbrace}$} |
| 591 |
|
| 592 |
Note that the brace is the properly formed scale of the normal-sized |
| 593 |
brace in both cases, even as the $x$ adjusts to the fontsize reduction. |
| 594 |
|
| 595 |
If one wanted the default braces narrower (to match the look of the |
| 596 |
comparable symbols in the literature), one could use |
| 597 |
\vb|\hstretch| in the definitions to achieve that quickly as |
| 598 |
\begin{verbatim} |
| 599 |
\def\lxbrace{% |
| 600 |
\hstretch{0.6}{\scalerel*{\usebox{\lXbrace}}{\llbrace}}} |
| 601 |
\def\rxbrace{% |
| 602 |
\hstretch{0.6}{\scalerel*{\usebox{\rXbrace}}{\rrbrace}}} |
| 603 |
\end{verbatim} |
| 604 |
|
| 605 |
to give the following |
| 606 |
|
| 607 |
\def\lxbrace{\hstretch{0.6}{\scalerel*{\usebox{\lXbrace}}{\llbrace}}} |
| 608 |
\def\rxbrace{\hstretch{0.6}{\scalerel*{\usebox{\rXbrace}}{\rrbrace}}} |
| 609 |
\rl$\scalerel*{\lxbrace x\rxbrace}{\wbrace}$ |
| 610 |
{\tiny$\scalerel*{\lxbrace x\rxbrace}{\wbrace}$} |
| 611 |
|
| 612 |
Likewise, the \vb|\left| and \vb|\right| features of equation mode |
| 613 |
cannot be used with the white braces, |
| 614 |
|
| 615 |
\rl \(\llbrace \left\llbracket\left\{\left[(a) \cdot |
| 616 |
bc^{2^3}\right]^4\right\}^5\right\rrbracket \rrbrace\) |
| 617 |
|
| 618 |
but \textsf{scalerel} can fix that, too: |
| 619 |
|
| 620 |
\def\core{ \left\llbracket\left\{\left[(a) \cdot |
| 621 |
bc^{2^3}\right]^4\right\}^5\right\rrbracket}% |
| 622 |
\rl |
| 623 |
\(\scaleleftright[1.5ex]{\lxbrace}{\core}{\rxbrace}\) |
| 624 |
|
| 625 |
with |
| 626 |
\begin{verbatim} |
| 627 |
\(\scaleleftright[1.5ex]{\lxbrace}{\core}{\rxbrace}\) |
| 628 |
\end{verbatim} |
| 629 |
where \vb|\core| is the core inner equation to which the white braces |
| 630 |
need to be scaled. In this case, the scaled white braces were |
| 631 |
width-limited to 1.5ex. |
| 632 |
|
| 633 |
\subsection{Extra-Wide Oversymbols} |
| 634 |
|
| 635 |
Ref:\\ |
| 636 |
http://tex.stackexchange.com/questions/100574/really-wide-hat-symbol/101136\#101136 |
| 637 |
|
| 638 |
There are many oversymbols defined to stand over a single-letter |
| 639 |
variable. There are a smaller number of extra-wide oversymbols to |
| 640 |
extend over small groups of symbols. Occasionally, however, a need |
| 641 |
arises for an oversymbol to stretch over a larger group of symbols. |
| 642 |
|
| 643 |
With these definitions, |
| 644 |
\begin{verbatim} |
| 645 |
\usepackage{scalerel,stackengine} |
| 646 |
|
| 647 |
\newcommand\reallywidehat[1]{\ensurestackMath{% |
| 648 |
\savestack{\tmpbox}{\stretchto{% |
| 649 |
\scaleto{% |
| 650 |
\scalerel*[\widthof{\ensuremath{#1}}]{\kern-.6pt\bigwedge\kern-.6pt}% |
| 651 |
{\rule[-\textheight/2]{1ex}{\textheight}}%WIDTH-LIMITED BIG WEDGE |
| 652 |
}{\textheight}% |
| 653 |
}{0.5ex}}% |
| 654 |
\stackon[1pt]{#1}{\tmpbox}% |
| 655 |
}} |
| 656 |
|
| 657 |
\newcommand\reallywideparen[1]{\ensurestackMath{% |
| 658 |
\savestack{\tmpbox}{\stretchto{% |
| 659 |
\scaleto{% |
| 660 |
\scalerel*[\widthof{\ensuremath{#1}}]{\kern-.6pt\frown\kern-.6pt}% |
| 661 |
{\rule[-\textheight/2]{1ex}{\textheight}}%WIDTH-LIMITED BIG FROWN |
| 662 |
}{\textheight}% |
| 663 |
}{0.9ex}}% |
| 664 |
\stackon[-.5pt]{#1}{\tmpbox}% |
| 665 |
}} |
| 666 |
\end{verbatim} |
| 667 |
arbitrarily wide oversymbols may be constructed: |
| 668 |
|
| 669 |
\newcommand\reallywidehat[1]{\ensurestackMath{% |
| 670 |
\savestack{\tmpbox}{\stretchto{% |
| 671 |
\scaleto{% |
| 672 |
\scalerel*[\widthof{\ensuremath{#1}}]{\kern-.6pt\bigwedge\kern-.6pt}% |
| 673 |
{\rule[-\textheight/2]{1ex}{\textheight}}%WIDTH-LIMITED BIG WEDGE |
| 674 |
}{\textheight}% |
| 675 |
}{0.5ex}}% |
| 676 |
\stackon[1pt]{#1}{\tmpbox}% |
| 677 |
}} |
| 678 |
|
| 679 |
\newcommand\reallywideparen[1]{\ensurestackMath{% |
| 680 |
\savestack{\tmpbox}{\stretchto{% |
| 681 |
\scaleto{% |
| 682 |
\scalerel*[\widthof{\ensuremath{#1}}]{\kern-.6pt\frown\kern-.6pt}% |
| 683 |
{\rule[-\textheight/2]{1ex}{\textheight}}%WIDTH-LIMITED BIG FROWN |
| 684 |
}{\textheight}% |
| 685 |
}{0.9ex}}% |
| 686 |
\stackon[-.5pt]{#1}{\tmpbox}% |
| 687 |
}} |
| 688 |
|
| 689 |
\rl |
| 690 |
$\reallywideparen{POQ}$ $+ \reallywidehat{QOR} + \reallywidehat{ROP}= |
| 691 |
2\pi r$ |
| 692 |
|
| 693 |
\rl $\reallywidehat{zbcdefghijklm} \ne \reallywideparen{zbcdefghijklm}$ |
| 694 |
|
| 695 |
\section{Future Development} |
| 696 |
|
| 697 |
It would be relatively straightforward to extend this approach to |
| 698 |
horizontal scaling problems. However, it is not exactly clear to the |
| 699 |
author what format is best suited for user needs. If he gets feedback |
| 700 |
in that regard, it will inform him how best to proceed. |
| 701 |
|
| 702 |
\section{Code Listing} |
| 703 |
|
| 704 |
\small\verbatiminput{scalerel.sty} |
| 705 |
|
| 706 |
\end{document} |