forked from CS234319/safot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cf.sty
55 lines (49 loc) · 1.1 KB
/
cf.sty
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
\def\cf #1 {%
\def\kind@cf{#1}%
\beginIteration@cf
}
\def\beginIteration@cf{%
\begingroup
\catcode`:=11%
\def\idAccumulator@cf{}%
\iterateOnNextToken@cf
}
\def\iterateOnNextToken@cf{%
\futurelet\nextToken@cf
\examineNextToken@cf
}
\def\examineNextToken@cf{%
\ifcase 0% Trick: will expand the next tokens to see if more digits follow.
\ifx\nextToken@cf\@sptoken 0\else
\ifcat a\nextToken@cf 1\else
\ifcat 0\nextToken@cf 2\fi% test of token is catcode "other"
\fi\fi
\relax
\expandafter\endIteration@cf
\or
\expandafter\accumulateCharacter@cf
\else
\expandafter\cf@checknum
\fi
}
\def\accumulateCharacter@cf#1{%
\edef\idAccumulator@cf{\idAccumulator@cf#1}%
\iterateOnNextToken@cf
}
% Checks whether the parameter is a number (ASCII 48-57)
\def\cf@checknum#1{%
\ifcase 0%
\ifnum`#1>47
\ifnum`#1<58 1\fi\fi
\relax
\def\next{\endIteration@cf#1}%
\else
\def\next{\accumulateCharacter@cf{#1}}%
\fi
\next
}
\def\endIteration@cf{%
\edef\label@cf{\kind@cf:\idAccumulator@cf}%
\kind@cf~\expandafter\ref\expandafter{\label@cf}%
\endgroup
}