diff options
author | Karl Berry <karl@freefriends.org> | 2013-05-07 23:12:49 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2013-05-07 23:12:49 +0000 |
commit | ba25ca7d24c2c129f2e7bbac09232a98b8f61561 (patch) | |
tree | 91806ff9329a5f6801fb30e987a4079f35314699 /Master/texmf-dist/tex/latex/scalerel | |
parent | 2efc5dd6b50aaf251dbf029ce7e738f385a57d79 (diff) |
scalerel (7may13)
git-svn-id: svn://tug.org/texlive/trunk@30322 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/scalerel')
-rw-r--r-- | Master/texmf-dist/tex/latex/scalerel/scalerel.sty | 87 |
1 files changed, 74 insertions, 13 deletions
diff --git a/Master/texmf-dist/tex/latex/scalerel/scalerel.sty b/Master/texmf-dist/tex/latex/scalerel/scalerel.sty index 54beb15dce2..77504b214c5 100644 --- a/Master/texmf-dist/tex/latex/scalerel/scalerel.sty +++ b/Master/texmf-dist/tex/latex/scalerel/scalerel.sty @@ -1,5 +1,5 @@ \ProvidesPackage{scalerel} -[2013/03/20 v1.3 +[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 @@ -21,8 +21,18 @@ % 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 @@ -33,11 +43,12 @@ \newcommand\scalerel{\@ifstar{\scalerelplain}{\scalerelplus}} \newcommand\scalerelplain[3][99in]{% - \sbox{\prebox}{$#2$}% - \setbox0\hbox{$#3$}% + \get@mmode% + \sbox{\prebox}{\@obj{#2}}% + \setbox0\hbox{\@obj{#3}}% \setlength\srblobheight{\ht0+\dp0}% \setlength\srblobdepth{\dp0}% - \setbox0\hbox{$#2$}% + \setbox0\hbox{\@obj{#2}}% \setlength\thesrwidth{\wd0*\ratio{\srblobheight}{\ht0+\dp0}}% \setlength\thesrheight{\ht0*\ratio{\srblobheight}{\ht0+\dp0}}% \setlength\mnxsrwidth{#1}% @@ -50,11 +61,12 @@ \newcommand\stretchrel{\@ifstar{\stretchrelplain}{\stretchrelplus}} \newcommand\stretchrelplain[3][10000]{% - \sbox{\prebox}{$#2$}% - \setbox0\hbox{$#3$}% + \get@mmode% + \sbox{\prebox}{\@obj{#2}}% + \setbox0\hbox{\@obj{#3}}% \setlength\srblobheight{\ht0+\dp0}% \setlength\srblobdepth{\dp0}% - \setbox0\hbox{$#2$}% + \setbox0\hbox{\@obj{#2}}% \setlength\thesrwidth{\wd0}% \setlength\thesrheight{\ht0*\ratio{\srblobheight}{\ht0+\dp0}}% \setlength\mnxsrwidth{\thesrheight*100/#1}% @@ -66,10 +78,11 @@ \newcommand\stretchrelplus[3][10000]{\stretchrelplain[#1]{#2}{#3}#3} \newcommand\scaleto[3][99in]{% - \sbox{\prebox}{$#2$}% + \get@mmode% + \sbox{\prebox}{\@obj{#2}}% \setlength\srblobheight{#3}% \setlength\srblobdepth{0pt}% - \setbox0\hbox{$#2$}% + \setbox0\hbox{\@obj{#2}}% \setlength\thesrwidth{\wd0*\ratio{\srblobheight}{\ht0+\dp0}}% \setlength\thesrheight{\ht0*\ratio{\srblobheight}{\ht0+\dp0}}% \setlength\mnxsrwidth{#1}% @@ -80,10 +93,11 @@ } \newcommand\stretchto[3][10000]{% - \sbox{\prebox}{$#2$}% + \get@mmode% + \sbox{\prebox}{\@obj{#2}}% \setlength\srblobheight{#3}% \setlength\srblobdepth{0pt}% - \setbox0\hbox{$#2$}% + \setbox0\hbox{\@obj{#2}}% \setlength\thesrwidth{\wd0}% \setlength\thesrheight{\ht0*\ratio{\srblobheight}{\ht0+\dp0}}% \setlength\mnxsrwidth{\thesrheight*100/#1}% @@ -106,8 +120,55 @@ \stretchrel[#1]{\leftarg}{#3}\stretchrel*[#1]{\rightarg}{#3}% } -\newcommand\hstretch[2]{\stretchrel*{\scalebox{#1}{$#2$}}{#2}} +\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$}} -\newcommand\vstretch[2]{\stretchrel*{#2}{\scalebox{#1}{$#2$}}} +\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 |