\ProvidesPackage{scalerel} [2013/05/07 v1.4 Routines for constrained scaling and stretching of objects, relative to a reference object or in absolute terms] %% Copyright 2013 Steven B. Segletes % % 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. % V1.01 Correct typos in documentation % V1.1 Corrected usepackage dependencies; Significant doc rewrite. % V1.2 Added \scaleleftright and \stretchleftright; revised docs. % V1.3 Corrected missing % in stretch routines, added \hstretch and % \vstretch commands; fixed version number in .sty file % V1.4 -Auto-detect mathmode and style; use the proper math display % style; Allow \ignoremathstyle and \discernmathstyle to % revert to former approach in rare cases and return to new % approach. % -Added \Isnextbyte as a supplemental routine % -Added \scaleobj (like \scalebox, but defaults to math mode % using current display style). \usepackage{calc} \usepackage{graphicx} \usepackage{mathstyle} \usepackage{ifthen} \global\newlength\thesrwidth \global\newlength\thesrheight \global\newlength\srblobheight \global\newlength\srblobdepth \global\newlength\mnxsrwidth \newsavebox{\prebox} \newcommand\scalerel{\@ifstar{\scalerelplain}{\scalerelplus}} \newcommand\scalerelplain[3][99in]{% \get@mmode% \sbox{\prebox}{\@obj{#2}}% \setbox0\hbox{\@obj{#3}}% \setlength\srblobheight{\ht0+\dp0}% \setlength\srblobdepth{\dp0}% \setbox0\hbox{\@obj{#2}}% \setlength\thesrwidth{\wd0*\ratio{\srblobheight}{\ht0+\dp0}}% \setlength\thesrheight{\ht0*\ratio{\srblobheight}{\ht0+\dp0}}% \setlength\mnxsrwidth{#1}% \ifdim\thesrwidth>\mnxsrwidth\setlength\thesrwidth{\mnxsrwidth}\fi% \raisebox{-\srblobdepth+\dp0*\ratio{\srblobheight}{\ht0+\dp0}}% {\resizebox{\thesrwidth}{\thesrheight}{\usebox{\prebox}}}% } \newcommand\scalerelplus[3][99in]{\scalerelplain[#1]{#2}{#3}#3} \newcommand\stretchrel{\@ifstar{\stretchrelplain}{\stretchrelplus}} \newcommand\stretchrelplain[3][10000]{% \get@mmode% \sbox{\prebox}{\@obj{#2}}% \setbox0\hbox{\@obj{#3}}% \setlength\srblobheight{\ht0+\dp0}% \setlength\srblobdepth{\dp0}% \setbox0\hbox{\@obj{#2}}% \setlength\thesrwidth{\wd0}% \setlength\thesrheight{\ht0*\ratio{\srblobheight}{\ht0+\dp0}}% \setlength\mnxsrwidth{\thesrheight*100/#1}% \ifdim\thesrwidth<\mnxsrwidth\setlength\thesrwidth{\mnxsrwidth}\fi% \raisebox{-\srblobdepth+\dp0*\ratio{\srblobheight}{\ht0+\dp0}}% {\resizebox{\thesrwidth}{\thesrheight}{\usebox{\prebox}}}% } \newcommand\stretchrelplus[3][10000]{\stretchrelplain[#1]{#2}{#3}#3} \newcommand\scaleto[3][99in]{% \get@mmode% \sbox{\prebox}{\@obj{#2}}% \setlength\srblobheight{#3}% \setlength\srblobdepth{0pt}% \setbox0\hbox{\@obj{#2}}% \setlength\thesrwidth{\wd0*\ratio{\srblobheight}{\ht0+\dp0}}% \setlength\thesrheight{\ht0*\ratio{\srblobheight}{\ht0+\dp0}}% \setlength\mnxsrwidth{#1}% \ifdim\thesrwidth>\mnxsrwidth\setlength\thesrwidth{\mnxsrwidth}\fi% \setlength\srblobdepth{\dp0*\ratio{\srblobheight}{\ht0+\dp0}}% \raisebox{-\srblobdepth+\dp0*\ratio{\srblobheight}{\ht0+\dp0}}% {\resizebox{\thesrwidth}{\thesrheight}{\usebox{\prebox}}}% } \newcommand\stretchto[3][10000]{% \get@mmode% \sbox{\prebox}{\@obj{#2}}% \setlength\srblobheight{#3}% \setlength\srblobdepth{0pt}% \setbox0\hbox{\@obj{#2}}% \setlength\thesrwidth{\wd0}% \setlength\thesrheight{\ht0*\ratio{\srblobheight}{\ht0+\dp0}}% \setlength\mnxsrwidth{\thesrheight*100/#1}% \ifdim\thesrwidth<\mnxsrwidth\setlength\thesrwidth{\mnxsrwidth}\fi% \setlength\srblobdepth{\dp0*\ratio{\srblobheight}{\ht0+\dp0}}% \raisebox{-\srblobdepth+\dp0*\ratio{\srblobheight}{\ht0+\dp0}}% {\resizebox{\thesrwidth}{\thesrheight}{\usebox{\prebox}}}% } \def\bl@nk{\rule{-.01ex}{1ex}} \newcommand\scaleleftright[4][99in]{% \if.#2\def\leftarg{\bl@nk}\else\def\leftarg{#2}\fi% \if.#4\def\rightarg{\bl@nk}\else\def\rightarg{#4}\fi% \scalerel[#1]{\leftarg}{#3}\scalerel*[#1]{\rightarg}{#3}% } \newcommand\stretchleftright[4][10000]{% \if.#2\def\leftarg{\bl@nk}\else\def\leftarg{#2}\fi% \if.#4\def\rightarg{\bl@nk}\else\def\rightarg{#4}\fi% \stretchrel[#1]{\leftarg}{#3}\stretchrel*[#1]{\rightarg}{#3}% } \newcommand\hstretch[2]{\get@mmode\stretchrel*{\scalebox{#1}{\@obj{#2}}}{#2}} \newcommand\vstretch[2]{\get@mmode\stretchrel*{#2}{\scalebox{#1}{\@obj{#2}}}} \newcommand\scaleobj[2]{\get@mmode\scalebox{#1}{\@obj{#2}}} % DETERMINE IF THE SCALEREL ROUTINE WAS CALLED IN MATH MODE. % IF SO, USE THE PROPER MATH DISPLAY STYLE FOR THE CALL, % *UNLESS* THE FIRST CHARACTER OF THE ARGUMENT IS A $ SIGN, % SIGNIFYING A DESIRED ESCAPE FROM MATH MODE FOR THE ARGUMENT. \newcommand\@obj[1]{% \if T\@mmode% \Isnextbyte[q]{$}{#1}% \if F\theresult% $\mathpalette{}{#1}$% \else% $#1$% \fi% \else% $#1$% \fi% } \let\sv@obj\@obj \newcommand\discernmathstyle{\let\@obj\sv@obj} % \ignoremathstyle WOULD BE USED RARELY, ONLY IF ONE WANTED TO USE % DOLLAR ($) DELIMITERS IN THE *MIDDLE* OF A scalerel ARGUMENT \newcommand\ignoremathstyle{\renewcommand\@obj[1]{$##1$}} \def\get@mmode{\ifmmode\gdef\@mmode{T}\else\gdef\@mmode{F}\fi} \def\PrimarySignalChar{@} \def\SecondarySignalChar{`} % THIS CAN REPLACE \isnextbyte IN STRINGSTRINGS PACKAGE % BECAUSE IT WORKS ON CHARS THAT CAN'T BE \edef'ED (\dag, ETC.) \newcommand\Isnextbyte[3][v]{% \let\SignalChar\PrimarySignalChar% \protected@edef\@x{\if #2#3\else\SignalChar\fi}% \protected@edef\@x{\if \SignalChar\@x F\else T\fi}% \let\SignalChar\SecondarySignalChar% \protected@edef\@y{\if #2#3\else\SignalChar\fi}% \protected@edef\@y{\if \SignalChar\@y F\else T\fi}% \ifthenelse{\equal{\@x\@y}{\@y\@x}}% {\protected@edef\theresult{\@x}}% {\protected@edef\theresult{T}}% \if q#1\else\theresult\fi% %\edef\theresult{T}% } \endinput