summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/adjustbox/adjcalc.sty
blob: 0fc7a627de3b03a6d19e20168ee09b065b191608 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
\begingroup
\def\@tempa{adjcalc}
\expandafter
\endgroup
\ifx\@tempa\@currname
    \ProvidesPackage{adjcalc}[2011/08/07 v1.0 Provides advanced setlength with multiple back-ends (calc, etex, pgfmath)]
    \RequirePackage{xkeyval}
\fi
\AtEndOfPackage{\adjcalc@atend}
\def\adjcalc@atend{%
\begingroup
\expandafter\ifx\csname eTeXversion\endcsname\relax
    \endgroup
    \RequirePackage{calc}%
    \adjcalc@calc
    \def\adjcalc@etex{\PackageError{adjcalc}{e-TeX not available for current compiler!}}%
\else
    \endgroup
    \adjcalc@etex
\fi
}
\def\adjcalc@pgfmath{\AtEndOfPackage{\RequirePackage{pgf}}\def\adjcalc@atend{\adjcalc@pgfmath}}
\def\adjcalc@etex{\def\adjcalc@atend{\adjcalc@etex}}
\def\adjcalc@calc{\AtEndOfPackage{\RequirePackage{calc}}\def\adjcalc@atend{\adjcalc@calc}}
\def\adjcalc@overwrite{\AtEndOfPackage{\adjcalc@overwrite}}
\DeclareOptionX<adjbox>{pgfmath}{\adjcalc@pgfmath}
\DeclareOptionX<adjbox>{etex}{\adjcalc@etex}
\DeclareOptionX<adjbox>{calc}{\adjcalc@calc}
\DeclareOptionX<adjbox>{none}{\let\adjcalc@atend\relax\def\adjsetlength{\setlength}\let\adjcalc@overwrite\relax}
\DeclareOptionX<adjbox>{overwrite}{\adjcalc@overwrite}
\ProcessOptionsX*<adjbox>
\disable@keys{adjbox}{none}
\def\adjcalc@etex{%
    \protected\def\adjsetlength##1##2{%
        ##1=\glueexpr(##2)\relax
    }%
    \protected\def\adjaddtolength##1##2{%
        \advance##1 by \glueexpr(##2)\relax
    }%
    \protected\def\adjsetcounter##1##2{%
        \@ifundefined{c@##1}%
            {\@nocounterr{##1}}%
            {\global\csname c@##1\endcsname\numexpr(##2)\relax}%
    }%
    \protected\def\adjaddtocounter##1##2{%
        \@ifundefined{c@##1}%
            {\@nocounterr{##1}}%
            {\global\advance\csname c@##1\endcsname\numexpr(##2)\relax}%
    }%
    \def\adjbox@default##1##2{%
        \@defaultunits##1=\glueexpr##2 \adjbox@defaultunit\relax\@nnil
    }%
}
\def\adjcalc@calc{%
    \DeclareRobustCommand\adjsetlength{\calc@assign@skip}%
    \DeclareRobustCommand\adjaddtolength[1]{\calc@assign@skip{\advance ##1}}%
    \DeclareRobustCommand\adjsetcounter[2]{\@ifundefined{c@##1}{\@nocounterr{##1}}{\calc@assign@count{\global\csname c@##1\endcsname}{##2}}}%
    \DeclareRobustCommand\adjaddtocounter[2]{\@ifundefined{c@##1}{\@nocounterr{##1}}{\calc@assign@count{\global\advance\csname c@##1\endcsname}{##2}}}%
    \def\adjbox@default##1##2{%
        \begingroup
        \message{^^J\detokenize{##2}^^J}%
        \def\calc@post@scan####1!{%
            \def\@tempa{####1}%
            \ifx\@tempa\@empty
              \endgroup% to end calc processing
              % is number only
              \global\@adjbox@needsdefaulttrue
            \else
              \endgroup% to end calc processing
              % full expression
              \global\@adjbox@needsdefaultfalse
            \fi
        }%
        \calc@assign@skip{##1}{##2 \adjbox@defaultunit}%
        \endgroup
        \if@adjbox@needsdefault
            ##1=##2 \adjbox@defaultunit\relax
        \else
            \calc@assign@skip{##1}{##2}%
        \fi
    }%
    \def\adjbox@checkdefault##1\@nnil##2##3{%
        \ifx\relax##1\relax\else
            \calc@assign@skip{##2}{##3}%
        \fi
    }%
}
\newif\if@adjbox@needsdefault
\def\adjcalc@pgfmath{%
    \DeclareRobustCommand\adjsetlength{\pgfmathsetlength}%
    \DeclareRobustCommand\adjaddtolength{\pgfmathaddtolength}%
    \DeclareRobustCommand\adjsetcounter{\pgfmathsetcounter}%
    \DeclareRobustCommand\adjaddtocounter{\pgfmathaddtocounter}%
    \def\adjbox@default##1##2{%
        \edef\pgfmathresultunitscale{1\adjbox@defaultunit}%
        \let\pgfmathpostparse\pgfmathscaleresult
        \pgfmathparse{##2}%
        ##1=\pgfmathresult pt\relax
    }%
}
\def\adjcalc@overwrite{%
    \let\setlength\adjsetlength
    \let\addtolength\adjaddtolength
    \let\setcounter\adjsetcounter
    \let\addtocounter\adjaddtocounter
}
\endinput
%%
%% End of file `adjcalc.sty'.