-
Notifications
You must be signed in to change notification settings - Fork 0
/
.latexindent.yaml
345 lines (333 loc) · 13.9 KB
/
.latexindent.yaml
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# this is a local setting file that overwrites the default setting written in latexindent/defaultSettings.yaml.
# location of that file can be found by running `latexindent -vv`.
# as the official doc suggests, you should not modify the default file but edit local one.
#------------------------------------------
#------------------------------------------
#------------------------------------------
#------------------------------------------
# only one backup per file:
# - if onlyOneBackUp is 0 then, as a safety measure,
# the number on the extension increments by 1 each time:
#
# myfile.bak0, myfile.bak1, myfile.bak2
# - if you set onlyOnebackUp to 1, then the backup file will
# be overwritten each time (not recommended until you trust the script)
onlyOneBackUp: 1
# preferences for information displayed in the log file
logFilePreferences:
showEveryYamlRead: 0
showAmalgamatedSettings: 0
defaultIndent: "\t"
fileExtensionPreference:
.tex: 1
.sty: 2
.cls: 3
.bib: 4
# name of code blocks that should have their body aligned at ampersand delimiters
lookForAlignDelims:
tabular:
spacesBeforeAmpersand: 2
spacesAfterAmpersand: 2
# specialBeginEnd is, by default, mathmode focus, although
# there's no restrictions
indentRules:
leftRightAutoSizeBrackets: ' '
specialBeginEnd:
leftRightAutoSizeBrackets:
begin: '\\left(?:\(|\[|\\\{|\.|\\l)'
end: '\\right(?:\)|\]|\\\}|\.|\\r)'
lookForThis: 1
# set indentRules globally for codeblocks; these need
# to be horizontal spaces, if they are to be used
indentRulesGlobal:
environments: "\t" # 0/h-space
lookForAlignDelims:
aligned:
delims: 1
alignDoubleBackSlash: 0
spacesBeforeDoubleBackSlash: 1
multiColumnGrouping: 1
alignRowsWithoutMaxDelims: 1
spacesBeforeAmpersand: 1
spacesAfterAmpersand: 1
justification: left
alignFinalDoubleBackSlash: 0
dontMeasure: 0
delimiterRegEx: (?<!\\)(&[\+\-\*=<>]?) # e.g., &=, &<
delimiterJustification: left
lookForChildCodeBlocks: 1
alignContentAfterDoubleBackSlash: 0
spacesAfterDoubleBackSlash: 0
# equation(*) and gather fields are placed here lookForAlignDelims just for DBSFinishesWithLineBreak to find and act on them. The content of setting itself is not important.
equation:
delims: 1
alignDoubleBackSlash: 0
spacesBeforeDoubleBackSlash: 1
multiColumnGrouping: 0
alignRowsWithoutMaxDelims: 1
spacesBeforeAmpersand: 0
spacesAfterAmpersand: 0
justification: left
alignFinalDoubleBackSlash: 0
dontMeasure: 0
delimiterRegEx: 0^ # no delimiters
delimiterJustification: left
lookForChildCodeBlocks: 1
alignContentAfterDoubleBackSlash: 0
spacesAfterDoubleBackSlash: 0
equation*:
delims: 1
alignDoubleBackSlash: 0
spacesBeforeDoubleBackSlash: 1
multiColumnGrouping: 0
alignRowsWithoutMaxDelims: 1
spacesBeforeAmpersand: 0
spacesAfterAmpersand: 0
justification: left
alignFinalDoubleBackSlash: 0
dontMeasure: 0
delimiterRegEx: 0^ # no delimiters
delimiterJustification: left
lookForChildCodeBlocks: 1
alignContentAfterDoubleBackSlash: 0
spacesAfterDoubleBackSlash: 0
gather:
delims: 1
alignDoubleBackSlash: 0
spacesBeforeDoubleBackSlash: 1
multiColumnGrouping: 0
alignRowsWithoutMaxDelims: 1
spacesBeforeAmpersand: 0
spacesAfterAmpersand: 0
justification: left
alignFinalDoubleBackSlash: 0
dontMeasure: 0
delimiterRegEx: 0^ # no delimiters
delimiterJustification: left
lookForChildCodeBlocks: 1
alignContentAfterDoubleBackSlash: 0
spacesAfterDoubleBackSlash: 0
gather*:
delims: 1
alignDoubleBackSlash: 0
spacesBeforeDoubleBackSlash: 1
multiColumnGrouping: 0
alignRowsWithoutMaxDelims: 1
spacesBeforeAmpersand: 0
spacesAfterAmpersand: 0
justification: left
alignFinalDoubleBackSlash: 0
dontMeasure: 0
delimiterRegEx: 0^ # no delimiters
delimiterJustification: left
lookForChildCodeBlocks: 1
alignContentAfterDoubleBackSlash: 0
spacesAfterDoubleBackSlash: 0
modifyLineBreaks:
preserveBlankLines: 1 # 0/1
condenseMultipleBlankLinesInto: 1 # 0/1
oneSentencePerLine:
manipulateSentences: 1 # 0/1
removeSentenceLineBreaks: 1 # 0/1
multipleSpacesToSingle: 1 # 0/1
sentencesBeginWith:
A-Z: 1 # 0/1
a-z: 1 # 0/1
other: [0-9"'] # regex
sentencesEndWith:
other: 0 # regex
environments:
BeginStartsOnOwnLine: 1 # -1,0,1,2,3,4
BodyStartsOnOwnLine: 1 # -1,0,1,2,3,4
EndStartsOnOwnLine: 1 # -1,0,1,2,3,4
EndFinishesWithLineBreak: 1
DBSFinishesWithLineBreak: 1
# setting for individual environments to overwrite the default
document:
BodyStartsOnOwnLine: 4 # -1,0,1,2,3,4
EndStartsOnOwnLine: 4 # -1,0,1,2,3,4
# "outer" math envs, such as equation and gather, are set to have a preceding blank line, so that they are easily distinguished by a neighboring sentence
# while "inner" math envs, such as aligned and cases, are set to have no additional blank line around them (use default)(see the example below).
#
# Example
#
# some sentence.
# %[a blank line here is useful to distinguish a preceding sentence and math env. So we set BeginStartsOnOwnLine: 4]
# \begin{equation*}
# %[need a blank line here? I don't think so.]
# \begin{aligned}
# \rank J_{p} &= \rank \restrict{F}{E_{p}} \\
# &= \dim \mathbb{R}^{k} \\
# \end{aligned}
# %[need a blank line here? I don't think so.]
# \end{equation*}
# %[a blank line here means the following line is a new paragraph, which is probably not always the case. So we set EndFinishesWithLineBreak: 1]
# some sentences
#
equation:
BeginStartsOnOwnLine: 4 # -1,0,1,2,3,4
BodyStartsOnOwnLine: 1 # -1,0,1,2,3,4
EndStartsOnOwnLine: 1 # -1,0,1,2,3,4
EndFinishesWithLineBreak: 1 # -1,0,1,2,3,4
equation*:
BeginStartsOnOwnLine: 4 # -1,0,1,2,3,4
BodyStartsOnOwnLine: 1 # -1,0,1,2,3,4
EndStartsOnOwnLine: 1 # -1,0,1,2,3,4
EndFinishesWithLineBreak: 1 # -1,0,1,2,3,4
gather:
BeginStartsOnOwnLine: 4 # -1,0,1,2,3,4
BodyStartsOnOwnLine: 1 # -1,0,1,2,3,4
EndStartsOnOwnLine: 1 # -1,0,1,2,3,4
EndFinishesWithLineBreak: 1 # -1,0,1,2,3,4
gather*:
BeginStartsOnOwnLine: 4 # -1,0,1,2,3,4
BodyStartsOnOwnLine: 1 # -1,0,1,2,3,4
EndStartsOnOwnLine: 1 # -1,0,1,2,3,4
EndFinishesWithLineBreak: 1 # -1,0,1,2,3,4
# replacements, only active when either -r or -rr switches are active
replacements:
-
amalgamate: 1
#
#--------------------------------------------------#
# GLOBAL ENV #
#--------------------------------------------------#
#
-
# Insert half-width space at every end of brace if it is followed by digit or alphabet
substitution: s/(?<=\)|\}|])([0-9a-zA-Z])/ $1/g
lookForThis: 1
when: after
-
# Remove space before comma and punctuation
substitution: s/\h+([,\.])/$1/g
lookForThis: 1
when: after
-
# remove consecutive blank lines
# this is a symptomatic treatment.
substitution: s/\n\h*\n\h*\n/\n\n/g
lookForThis: 1
when: after
#
#--------------------------------------------------#
# MATH ENV #
#--------------------------------------------------#
#
# Replacements for \begin{env}-\end{env} style math environment.
#
# Suppose we would like to apply some regular expressions to a formula inside a nested math environment
# like \begin{equation*}\begin{aligned}f(x)&=g(x)+h(x)\\&=0\end{aligned}\end{equation*}.
# (Consider non-nested environment as a trivial nested environment.)
# the following code classifies formula ($body), \begin{env} ($begin) and \end{env} ($end) statements from the nested environments in a recursive way.
# (Technical Note) It seems that there are some perl syntax latexindent(v3.22.2) does not support, such as "if ($body =~ /regexp/)".
# The following code is written in a way that avoids such syntax.
-
# function to align a formula inside a nested math environment.
# The first line in substitution must be a regular expression? (otherwise it will not work in my experience).
substitution: |-
s/(\\begin\{(?:equation|gather)\*?\}[\h\n]*)(?<!\n)(.*?)(?!\h)([\h\n]*\\end\{(?:equation|gather)\*?\}[\h\n]*)/
my ($begin, $body, $end) = ($1, $2, $3);
# name of environment that could come into equation or gather.
my @envs = ("aligned","cases");
# choose only envs that are present in the body
@envs = grep { contain_env($_, $body) } @envs;
# function to cut \begin\end in body and paste in \begin and \end
sub process_gather {
my ($b, $c, $e, $be, $en) = @_;
$$be .= $b;
$$en = $e.$$en;
return $c;
}
# test if body contains \begin{env*?} statement
sub contain_env {
my ($env, $body) = @_;
return index($body, "\\begin\{".$env) != -1;
}
# recursively cut out \begin and \end from body and add them to $begin and $end
while (1){
foreach my $env (@envs){
if (contain_env($env, $body)){
$body =~ s@([\h\n]*?\\begin\{$env\*?\}[\h\n]*)(?<!\n)(.*?)(?!\h)([\h\n]*\\end\{$env\*?\}[\h\n]*)@process_gather($1, $2, $3, \$begin, \$end)@egxs;
next;
}
}
last;
}
# add space around operators +-=/*\\ if they are not paired with &
$body =~ s@\h*(?<![&\{:])([\+\-=\/\*])(?![\:}&])\h*@ $1 @sg;
# Add braces to superscripts and subscripts
$body =~ s@(\^|\_)([a-zA-Z0-9]+)@$1\{$2\}@sg;
# add space before "\"
$body =~ s@(?<=\w)\\@ \\@sg;
# add space around <>
$body =~ s@(?<!\\left|\\right)\h*(<|>)\h*(?!\\left|\\right)@ $1 @sg;
$begin . $body . $end /sxge;
lookForThis: 1
when: before
#
#--------------------------------------------------#
# INLINE MATH #
#--------------------------------------------------#
#
# Replacements for inline math block \( x \).
-
substitution: |-
s/(?<=\\\()\h*(.*?)\h*(?=\\\))/
# ↑ this expression is solely for \( x \) style inline math.
my $body = $1;
# Add braces to superscripts and subscripts
$body =~ s@(\^|\_)([a-zA-Z0-9]+)@$1\{$2\}@sg;
# add a single space around + - = * /
$body =~ s@\h*(?<![\{:])([\+\-=\/\*])(?![\}:])\h*@ $1 @sg;
# add space before "\"
$body =~ s@(?<=\w)\\@ \\@sg;
# add space around <>
$body =~ s@(?<!\\left|\\right)\h*(<|>)\h*(?!\\left|\\right)@ $1 @sg;
$body;/sxge
lookForThis: 1
when: after
-
# Insert space at the beginning&end of inline math env
# \(x\) -> \( x \)
substitution: s/(?<=\\\()\h*(.*?)\h*(?=\\\))/ $1 /g
lookForThis: 1
when: after
fineTuning:
# fineTuning for trailing comments seems to cause trouble. so I disable it.
trailingComments:
notPreceededBy: # (?<!\\)
afterComment: 0^ # .*?
modifyLineBreaks:
comma: ','
# exclude .\hoge
betterFullStop: |-
(?x) # ignore spaces in the below
(?: #
\.\) # .)
(?!\h*[a-z\\]) # not *followed by* a-z and \
) #
| # OR
(?: #
(?<! # not *preceded by*
(?: #
(?:[eE]\.[gG]) # e.g OR E.g OR e.G OR E.G
| #
(?:[iI]\.[eE]) # i.e OR I.e OR i.E OR I.E
| #
(?:etc) # etc
| #
(?:[wW]\.[rR]\.[tT]) # w.r.t OR W.r.t OR w.R.t OR w.r.T OR W.R.t OR W.r.T OR w.R.T OR W.R.T
) #
) #
) #
\. # .
(?! # not *followed by*
(?: #
[a-zA-Z0-9-~,\\] #
| #
\), # ),
| #
\)\. # ).
) #
) #