forked from sisl/tufte_algorithms_book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector.sty
70 lines (63 loc) · 1.55 KB
/
vector.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
\ProvidesPackage{vector}
% based on: http://tex.stackexchange.com/questions/167172/consistent-macro-for-bold-upright-vectors-in-both-latin-and-greek
\RequirePackage{xparse}
\RequirePackage{bm,upgreek}
\ExplSyntaxOn
\NewDocumentCommand\vect{m}
{
\commexo_vector:n { #1 }
}
\cs_new_protected:Npn \commexo_vector:n #1
{
\tl_map_inline:nn { #1 }
{
\commexo_vector_inner:n { ##1 }
}
}
\cs_new_protected:Npn \commexo_vector_inner:n #1
{
\tl_if_in:VnTF \g_commexo_latin_tl { #1 }
{% we check whether the argument is a Latin letter
\mathbf { #1 } % a Latin letter
}
{% if not a Latin letter, we check if it's an uppercase Greek letter
\tl_if_in:VnTF \g_commexo_ucgreek_tl { #1 }
{
\bm { #1 } % a Greek uppercase letter
}
{% if not, we check if it's a lowercase Greek letter
\tl_if_in:VnTF \g_commexo_lcgreek_tl { #1 }
{
\commexo_makeboldupright:n { #1 }
}
{% none of the above, just issue #1
#1 % fall back
}
}
}
}
\cs_new_protected:Npn \commexo_makeboldupright:n #1
{
\bm { \use:c { up \cs_to_str:N #1 } }
}
\tl_new:N \g_commexo_latin_tl
\tl_new:N \g_commexo_ucgreek_tl
\tl_new:N \g_commexo_lcgreek_tl
\tl_gset:Nn \g_commexo_latin_tl
{
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
0123456789
}
\tl_gset:Nn \g_commexo_ucgreek_tl
{
\Gamma\Delta\Theta\Lambda\Pi\Sigma\Upsilon\Phi\Chi\Psi\Omega
}
\tl_gset:Nn \g_commexo_lcgreek_tl
{
\alpha\beta\gamma\delta\epsilon\zeta\eta\theta\iota\kappa
\lambda\mu\nu\xi\pi\rho\sigma\tau\upsilon\phi\chi\psi\omega
\varepsilon\vartheta\varpi\varphi\varsigma\varrho
}
\ExplSyntaxOff
\endinput