-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmathmode-spacing.tex
117 lines (106 loc) · 2.42 KB
/
mathmode-spacing.tex
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
117
% Source: http://tex.stackexchange.com/a/129454
% Adjusts spacing between letters in math mode for multiple-letter identifiers.
% Requires \usepackage{etexcmds}
\makeatletter
\newtoks\m@toks@math
\newtoks\m@toks@text
\edef\m@tmp@restore{%
\lccode\number`\X=\the\lccode`\X\relax
\lccode\number`\~=\the\lccode`\~\relax
}
\newcommand*{\m@activate}{}
\newcommand*{\m@check@letter}{}
\newcommand*{\m@check@fi}{}
\newif\ifm@single
\let\m@start\relax
\def\m@loop{%
\lccode`\X=\count@
\lccode`\~=\count@
\lowercase{%
\expandafter\mathchardef\csname m@code@X\endcsname=\mathcode\count@
\edef\m@activate{%
\etex@unexpanded\expandafter{\m@activate}%
\mathcode\the\count@="8000\relax
\def\noexpand~{\m@start\csname m@code@X\endcsname X}%
}%
\g@addto@macro\m@check@letter{%
\ifx\@let@token X\else
}%
}%
\g@addto@macro\m@check@fi{\fi}%
\advance\count@\@ne
}
% A-Z
\count@=`\A\relax
\@whilenum\count@<\numexpr`\Z+1\relax\do{\m@loop}
% a-z
\count@=`\a\relax
\@whilenum\count@<\numexpr`\z+1\relax\do{\m@loop}
\newcommand*{\m@start}[2]{%
\bgroup
\m@toks@math{#1}%
\m@toks@text{#2}%
\m@singletrue
\futurelet\@let@token\m@check
}
\edef\m@check{%
\etex@unexpanded{%
\let\m@next\m@add
\ifx\@let@token\space
\let\m@next\m@finish
\else
\ifx\@let@token\egroup
\let\m@next\m@finish
\else
}%
\etex@unexpanded\expandafter{%
\m@check@letter
}%
\etex@unexpanded{%
\let\m@next\m@finish
}%
\etex@unexpanded\expandafter{%
\m@check@fi
}%
\etex@unexpanded{%
\fi
\fi
\m@next
}%
}
\newcommand*{\m@add}[1]{%
\m@singlefalse
\m@toks@math\expandafter{%
\the\expandafter\m@toks@math
\csname m@code@#1\endcsname
}%
\m@toks@text\expandafter{%
\the\m@toks@text
#1%
}%
\futurelet\@let@token\m@check
}
\newcommand*{\m@finish}{%
\ifm@single
\expandafter\mprintsingle\expandafter{%
\the\expandafter\m@toks@math\expandafter
}\expandafter{%
\the\expandafter\m@toks@text\expandafter
}%
\else
\expandafter\mprintmulti\expandafter{%
\the\expandafter\m@toks@math\expandafter
}\expandafter{%
\the\expandafter\m@toks@text\expandafter
}%
\fi
\egroup
}
\let\mprintsingle\@firstoftwo
\let\mprintmulti\@firstoftwo
\everymath{\m@activate}
\everydisplay{\m@activate}
\m@tmp@restore
\makeatother
\renewcommand*{\mprintsingle}[2]{{#1}}%
\renewcommand*{\mprintmulti}[2]{\mathit{#1}}%