blob: fdd7a6a822b565fb05eb2de3f54cf053d0261ee3 (
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
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
157
|
\RequirePackage{xparse,mathtools}
\ProvidesExplPackage{leftindex}{2020/08/25}{0.1beta}{}
%----------------------------------------------------------------
% leftindex -- left indices with better spacing
% Version: 0.1beta
% Maintained by Sebastian Ørsted
% E-mail: sorsted@gmail.com
% Released under the LaTeX Project Public License v1.3c or later
% See http://www.latex-project.org/lppl.txt
%----------------------------------------------------------------
\DeclareDocumentCommand\manualleftindex { mmmm }
{
% #1 = height phantom
% #2 = slanting phantom
% #3 = left superscript
% #4 = left subscript
\mathpalette \__leftindex_auxiliary_mathpalette_command:nn { {#1}{#2}{#3}{#4} }
}
\ExplSyntaxOff
\DeclareDocumentCommand\leftindex { o o E{^_}{{}{}} m }
{
% #1 = slanting phantom
% #2 = height phantom
% #3 = left superscript
% #4 = left subscript
% #5 = symbol
\IfValueTF {#1}
{
\IfValueTF{#2}
{
\manualleftindex { #2 } { #1 } { #3 } { #4 }
}
{
\manualleftindex { #5 } { #1 } { #3 } { #4 }
}
}
{
\manualleftindex { #5 } { #5 } { #3 } { #4 }
}
#5
}
\ExplSyntaxOn
\cs_new_protected:Npn\leftindex_kern_horizontal:n#1
{
\kern #1 \relax
}
\cs_new_protected:Npn\leftindex_set_mathsurround_to_zero:
{
% This is equivalent to "\m@th"
\dim_set:Nn \mathsurround { 0pt }
}
\cs_new_protected:Npn\__leftindex_auxiliary_mathpalette_command:nn#1#2
{
\__leftindex_auxiliary:nnnnn { #1 } #2
}
\dim_new:N\l__leftindex_phantom_height_dim
\box_new:N \l__leftindex_slanting_phantom_with_subscript_box
\dim_new:N \l__leftindex_slanting_phantom_with_subscript_dim
\box_new:N \l__leftindex_slanting_phantom_with_subscript_without_indentation_box
\dim_new:N \l__leftindex_slanting_phantom_with_subscript_without_indentation_dim
\dim_new:N \l__leftindex_indentation_of_slanting_phantom_subscript
\box_new:N \l__leftindex_superscript_temp_box
\dim_new:N \l__leftindex_width_of_superscript_dim
\box_new:N \l__leftindex_subscript_temp_box
\dim_new:N \l__leftindex_width_of_subscript_dim
\cs_new_protected:Npn\__leftindex_auxiliary:nnnnn#1#2#3#4#5
{
\group_begin:
\hbox_set:Nn \l__leftindex_slanting_phantom_with_subscript_box
{ $ #1 #3 \sb{xxxxxx} $ }
\dim_set:Nn \l__leftindex_slanting_phantom_with_subscript_dim
{ \box_wd:N \l__leftindex_slanting_phantom_with_subscript_box }
\hbox_set:Nn \l__leftindex_slanting_phantom_with_subscript_without_indentation_box
{ $ #1 \hbox:n {$ #1 #3 $} \sb{xxxxxx} $ }
\dim_set:Nn \l__leftindex_slanting_phantom_with_subscript_without_indentation_dim
{ \box_wd:N \l__leftindex_slanting_phantom_with_subscript_without_indentation_box }
\dim_set:Nn \l__leftindex_indentation_of_slanting_phantom_subscript
{
\l__leftindex_slanting_phantom_with_subscript_without_indentation_dim
-
\l__leftindex_slanting_phantom_with_subscript_dim
}
\tl_if_blank:nTF { #4 }
{
\dim_zero:N \l__leftindex_width_of_superscript_dim
}
{
\hbox_set:Nn \l__leftindex_superscript_temp_box
{
$
\leftindex_set_mathsurround_to_zero:
#1 \sp { #4 }
$
}
\dim_set:Nn \l__leftindex_width_of_superscript_dim
{
\box_wd:N \l__leftindex_superscript_temp_box
-
\l__leftindex_indentation_of_slanting_phantom_subscript
}
}
\tl_if_blank:nTF { #5 }
{
\dim_zero:N \l__leftindex_width_of_subscript_dim
}
{
\hbox_set:Nn \l__leftindex_subscript_temp_box
{
$
\leftindex_set_mathsurround_to_zero:
#1 \sb { #5 }
$
}
\dim_set:Nn \l__leftindex_width_of_subscript_dim
{
\box_wd:N \l__leftindex_subscript_temp_box
}
}
\leftindex_kern_horizontal:n
{
\dim_max:nn
{ \l__leftindex_width_of_superscript_dim }
{ \l__leftindex_width_of_subscript_dim }
}
\mathop{}
\mathopen{ \vphantom { #2 } }
\tl_if_blank:nF { #4 }
{
\sp {
\mathmakebox[0pt][l]{
\mathmakebox[ \l__leftindex_indentation_of_slanting_phantom_subscript ][r]{ #4 }
}
}
}
\tl_if_blank:nF { #5 }
{
\sb {
\mathmakebox[0pt][r]{ #5 }
}
}
\group_end:
}
|