-
Notifications
You must be signed in to change notification settings - Fork 0
/
phiso.sty
156 lines (140 loc) · 6.09 KB
/
phiso.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
% LTeX: enabled=false
\ProvidesPackage{phiso}
\RequirePackage{ifluatex}
\ifluatex\else
\PackageError{luacode}{LuaTeX is required for this package. Aborting.}{%
This package can only be used with the LuaTeX engine\MessageBreak
(command ‘lualatex’). Package loading has been stopped\MessageBreak
to prevent additional errors.}
\expandafter\luacode@sty@endinput
\fi
% -- Package options ---------------------------------------------------------
\RequirePackage{kvoptions} % Required to load package from options
\SetupKeyvalOptions{family=phiso,prefix=phiso@}
\DeclareBoolOption{mathtools} % Option to load `mathtools`
\DeclareBoolOption{nablaregular} % Option to not use bold symbol for nabla
\DeclareBoolOption{diffitalic} % Option to use italic differential symbol
\ProcessKeyvalOptions*
\ifphiso@mathtools
\RequirePackage{mathtools} % Must be loaded before `unicode-math`
\fi
% -- Required packages -------------------------------------------------------
\RequirePackage{luacode}
\@ifpackageloaded{unicode-math}
{
\ifphiso@mathtools
\PassOptionsToPackage{%
math-style=ISO,%
warnings-off={mathtools-colon,mathtools-overbracket}}{unicode-math}
\else
\PassOptionsToPackage{math-style=ISO}{unicode-math}
\fi
}
{
\ifphiso@mathtools
\RequirePackage[%
math-style=ISO,%
warnings-off={mathtools-colon,mathtools-overbracket}]{unicode-math}
\else
\RequirePackage[math-style=ISO]{unicode-math}
\fi
}
\ifphiso@diffitalic
\RequirePackage[italic=true]{derivative}
\else
\RequirePackage{derivative}
\fi
% -- General math symbols ----------------------------------------------------
% `unicode-math` does its definition in `\AtBeginDocument`
% so one needs to do the same to overwrite
\AtBeginDocument{\renewcommand{\imath}{\symup{i}}}
\AtBeginDocument{\renewcommand{\Re}{\operatorname{Re}}}
\AtBeginDocument{\renewcommand{\Im}{\mathrm{Im}}}
\AtBeginDocument{\newcommand{\bigo}{\operatorname{O}}}
\AtBeginDocument{\newcommand{\smallo}{\operatorname{o}}}
\AtBeginDocument{\renewcommand{\vec}[1]{\symbfit{#1}}}
\AtBeginDocument{\newcommand{\mat}[1]{\symbfit{#1}}}
\AtBeginDocument{\newcommand{\ten}[1]{\symbfsfit{#1}}}
\ifphiso@nablaregular\else
\AtBeginDocument{
\let\nablaSymbol\nabla
\renewcommand{\nabla}{\symbf{\nablaSymbol}}
}
\fi
\newcommand{\trans}{^{\mkern-1.5mu\mathsf{T}}}
\newcommand{\FT}{\symcal{F}}
\newcommand{\LT}{\symcal{L}}
\newcommand{\Order}{\operatorname{O}}
\newcommand{\order}{\operatorname{o}}
% -- Dimensionless numbers ---------------------------------------------------
% Inspiration: https://tex.stackexchange.com/a/131687
\newcommand{\Arch}{\operatorname{\mathit{A\kern-.06em r}}}
\newcommand{\Atwo}{\operatorname{\mathit{A\kern-.06em t}}}
\newcommand{\Biot}{\operatorname{\mathit{B\kern-.06em i}}}
\newcommand{\Cauc}{\operatorname{\mathit{C\kern-.07em a}}}
\newcommand{\Damk}{\operatorname{\mathit{D\kern-.06em a}}}
\newcommand{\Ecke}{\operatorname{\mathit{E\kern-.06em c}}}
\newcommand{\Eule}{\operatorname{\mathit{E\kern-.03em u}}}
\newcommand{\Four}{\operatorname{\mathit{F\kern-.10em o}}}
\newcommand{\Frou}{\operatorname{\mathit{F\kern-.07em r}}}
\newcommand{\Gras}{\operatorname{\mathit{G\kern-.05em r}}}
\newcommand{\Hart}{\operatorname{\mathit{H\kern-.05em a}}}
\newcommand{\Karl}{\operatorname{\mathit{K\kern-.11em a}}}
\newcommand{\Knud}{\operatorname{\mathit{K\kern-.11em n}}}
\newcommand{\Lapl}{\operatorname{\mathit{L\kern-.05em a}}}
\newcommand{\Lewi}{\operatorname{\mathit{L\kern-.05em e}}}
\newcommand{\Mach}{\operatorname{\mathit{M\kern-.10em a}}}
\newcommand{\Nuss}{\operatorname{\mathit{N\kern-.09em u}}}
\newcommand{\Pecl}{\operatorname{\mathit{P\kern-.08em e}}}
\newcommand{\Pran}{\operatorname{\mathit{P\kern-.03em r}}}
\newcommand{\Rayl}{\operatorname{\mathit{R\kern-.04em a}}}
\newcommand{\Reyn}{\operatorname{\mathit{R\kern-.04em e}}}
\newcommand{\Rich}{\operatorname{\mathit{R\kern-.04em i}}}
\newcommand{\Rosh}{\operatorname{\mathit{R\kern-.04em o}}}
\newcommand{\Schm}{\operatorname{\mathit{S\kern-.07em c}}}
\newcommand{\Sher}{\operatorname{\mathit{S\kern-.07em h}}}
\newcommand{\Stro}{\operatorname{\mathit{S\kern-.07em r}}}
\newcommand{\Webe}{\operatorname{\mathit{W\kern-.14em e}}}
% -- Sub/superscript kerning fix ---------------------------------------------
% Source: https://tex.stackexchange.com/a/432291
\begin{luacode}
function suppl_math_kerning(s)
-- Subscript combinations
-- \nabla
s = s:gsub ("(\\nabla)%s-_%s-(%b{})" , "%1_{\\mkern-4mu %2}")
s = s:gsub ("(\\nabla)%s-_%s-(%w)" , "%1_{\\mkern-4mu %2}")
-- \Gamma
s = s:gsub ("(\\Gamma)%s-_%s-(%b{})" , "%1_{\\mkern-4mu %2}")
s = s:gsub ("(\\Gamma)%s-_%s-(%w)" , "%1_{\\mkern-4mu %2}")
-- \Psi
s = s:gsub ("(\\Psi)%s-_%s-(%b{})" , "%1_{\\mkern-3mu %2}")
s = s:gsub ("(\\Psi)%s-_%s-(%w)" , "%1_{\\mkern-3mu %2}")
-- \Upsilon
s = s:gsub ("(\\Upsilon)%s-_%s-(%b{})", "%1_{\\mkern-3mu %2}")
s = s:gsub ("(\\Upsilon)%s-_%s-(%w)" , "%1_{\\mkern-3mu %2}")
-- letters T, V, W, Y
s = s:gsub ("([VWY])%s-_%s-(%b{})" , "%1_{\\mkern-3mu %2}")
s = s:gsub ("([VWY])%s-_%s-(%w)" , "%1_{\\mkern-3mu %2}")
-- letters F, P, T
s = s:gsub ("([FPT])%s-_%s-(%b{})" , "%1_{\\mkern-1.5mu %2}")
s = s:gsub ("([FPT])%s-_%s-(%w)" , "%1_{\\mkern-1.5mu %2}")
-- Superscript combinations
-- \Delta
s = s:gsub ("(\\Delta)%s-%^%s-(%b{})" , "%1^{\\mkern-3mu %2}")
s = s:gsub ("(\\Delta)%s-%^%s-(%w)" , "%1^{\\mkern-3mu %2}")
-- \Lambda
s = s:gsub ("(\\Lambda)%s-%^%s-(%b{})", "%1^{\\mkern-3mu %2}")
s = s:gsub ("(\\Lambda)%s-%^%s-(%w)" , "%1^{\\mkern-3mu %2}")
-- \lambda
s = s:gsub ("(\\lambda)%s-%^%s-(%b{})", "%1^{\\mkern-2mu %2}")
s = s:gsub ("(\\lambda)%s-%^%s-(%w)" , "%1^{\\mkern-2mu %2}")
-- letters A, L
s = s:gsub ("([AL])%s-%^%s-(%b{})" , "%1^{\\mkern-1.5mu %2}")
s = s:gsub ("([AL])%s-%^%s-(%w)" , "%1^{\\mkern-1.5mu %2}")
return s
end
\end{luacode}
\newcommand\SupplKernOn{\directlua{luatexbase.add_to_callback(
"process_input_buffer", suppl_math_kerning , "suppl_math_kerning" )}}
\newcommand\SupplKernOff{\directlua{luatexbase.remove_from_callback(
"process_input_buffer", "suppl_math_kerning" )}}