summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/ushort/ushort.sty
blob: a755e2c39c1fd0ec15ccf5b867f3df1ae31aeebf (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
110
111
112
113
114
115
116
%%
%% This file was generated by the docstrip utility from ushort.dtx.
%% You may distribute this file only together with the source ushort.dtx
%% (and if possible with ushort.ins) and only if these files are unmodified.
%%
%% Author:
%%
%% M. V\"ath      martin@mvath.de
%%

\ifx\typeout\undefined
  \def\ushrt@tmp{\immediate\write17}
\else
  \let\ushrt@tmp\typeout
\fi
\ushrt@tmp{ushort.sty by M. Vaeth: Release: 2.2 }

%% First, some LaTeX support:

\ifx\ProvidesPackage\undefined\else
  \ProvidesPackage{ushort}[2001/06/13 v2.2]
\fi

\ifx\newcommand\undefined\else
  \newcommand{\ushort}{}
  \newcommand{\ushortw}{}
  \newcommand{\ushortd}{}
  \newcommand{\ushortdw}{}
  \newcommand{\ushortdline}{}
  \newcommand{\ushortCreate}{}
  \newcommand{\ushortEnsuremath}{}
\fi

%% The implementation follows

\def\ushortCreate{\let\ushrt@calc\ushrt@empty\let\ushrt@TextMode\undefined
  \def\ushrt@FactorAfter{0.8}\let\ushrt@FactorBefore\ushrt@calc
  \let\ushrt@Summand\ushrt@empty\def\ushrt@cmd{\underline}\ushrt@TestLoop}
\def\ushrt@TestLoop{\ushrt@TestAndExec*\ushrt@Star\ushrt@TestCommand}
\def\ushrt@Star*{\def\ushrt@cmd{\underbar}\let\ushrt@TextMode\ushrt@empty
  \ushrt@TestLoop}
\def\ushrt@TestCommand{\ushrt@TestAndExec:\ushrt@GetCommand\ushrt@TestCalc}
\def\ushrt@GetCommand:#1{\def\ushrt@cmd{#1}\ushrt@TestLoop}
\def\ushrt@TestCalc{\ushrt@TestAndExec+\ushrt@GetCalc\ushrt@TestSummand}
\def\ushrt@GetCalc+#1{\def\ushrt@calc{#1}\ushrt@TestLoop}
\def\ushrt@TestSummand{\ushrt@TestAndExec[%]
  \ushrt@GetSummand\ushrt@TestFactorBefore}
\def\ushrt@GetSummand[#1]{\def\ushrt@Summand{\advance\dimen0 by#1}%
  \ushrt@TestLoop}
\def\ushrt@TestFactorBefore{\ushrt@TestAndExec<%>
  \ushrt@GetFactorBefore\ushrt@TestFactorAfter}
\def\ushrt@GetFactorBefore<#1>{\def\ushrt@FactorBefore{#1}\ushrt@TestLoop}
\def\ushrt@TestFactorAfter{\ushrt@TestAndExec(%)
  \ushrt@GetFactorAfter\ushrt@Main}
\def\ushrt@GetFactorAfter(#1){\def\ushrt@FactorAfter{#1}\ushrt@TestLoop}

\def\ushrt@TestAndExec#1#2#3{%
  \ushrt@SkipAndExec{%
    \ifx\ushrt@NextToken#1%
      \def\ushrt@exec{#2}%
    \else
      \def\ushrt@exec{#3}%
    \fi
    \ushrt@exec}}
\def\ushrt@SkipAndExec#1{\def\ushrt@tmp{#1}\ushrt@skip}
\def\ushrt@skip{\futurelet\ushrt@NextToken\ushrt@tmp}

\def\ushrt@Main#1{\def\ushrt@exec{\ushrt@Define}\ushrt@ExpandLoop
  \ushrt@cmd\ushrt@calc\ushrt@Summand\ushrt@FactorBefore\ushrt@FactorAfter
  {\csname#1\endcsname}{\csname ushrt@#1\endcsname}{}}

\def\ushrt@ExpandLoop#1{\def\ushrt@tmp{#1}%
  \ifx\ushrt@tmp\ushrt@empty
    \let\ushrt@tmp\ushrt@exec
  \else
    \let\ushrt@tmp\ushrt@ExpandLoop
    \expandafter\ushrt@Expand\expandafter{#1}%
  \fi\ushrt@tmp}
\def\ushrt@Expand#1{\expandafter
  \def\expandafter\ushrt@exec\expandafter{\ushrt@exec{#1}}}

\def\ushrt@Define#1#2#3#4#5#6#7{%
  \def#6##1{\ushortEnsuremath{\mathpalette#7{##1}##1}}%
  \ifx\ushrt@TextMode\undefined
    \def#7##1##2{\hbox to 0pt{{\mathsurround0pt$#1{%
      {\setbox0\hbox{\mathsurround0pt$##1##2$}%
        \dimen0=#4\wd0#3\dimen1\ht0\dimen2\dp0#2%
        \setbox0\hbox to#5\dimen0{}\ht0\dimen1\dp0\dimen2%
        \box0}}$\hss}}}%
  \else
    \def#7##1##2{\hbox to 0pt{#1{%
      {\setbox0\hbox{\mathsurround0pt$##1##2$}%
        \dimen0=#4\wd0#3\dimen1\ht0\dimen2\dp0#2%
        \setbox0\hbox to#5\dimen0{}\ht0\dimen1\dp0\dimen2%
        \box0}}\hss}}%
  \fi}

\def\ushortEnsuremath{\relax
  \ifmmode
    \let\ushrt@exec\ushrt@NoSwitch
  \else
    \let\ushrt@exec\ushrt@Switch
  \fi\ushrt@exec}
\def\ushrt@NoSwitch#1{#1}
\def\ushrt@Switch#1{\relax$#1\relax$\relax}

\def\ushrt@empty{}

\ushortCreate{ushort}
\ushortCreate()[-.1em]{ushortw}
\ushortCreate:\ushortdline{ushortd}
\ushortCreate:\ushortdline()[-.1em]{ushortdw}
\def\ushortdline#1{\underline{\underline #1}}
\endinput
%%
%% End of file `ushort.sty'.