-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbookml-init.sty.ltxml
More file actions
517 lines (488 loc) · 18.1 KB
/
bookml-init.sty.ltxml
File metadata and controls
517 lines (488 loc) · 18.1 KB
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
# -*- mode: Perl -*-
# vim: syntax=perl
=begin comment
BookML: bookdown flavoured GitBook port for LaTeXML
Copyright (C) 2021-25 Vincenzo Mantova <v.l.mantova@leeds.ac.uk>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
=end comment
=cut
package LaTeXML::Package::Pool;
use strict;
use warnings;
# bookml/bookml uses AtBeginDocument()! we must load it in the
# @document@preamble@atend hook which runs *before* @at@begin@document
PushValue('@document@preamble@atend', Tokenize('\usepackage{bookml/bookml}'));
# LaTeXML currently does not support the class options 10pt, 11pt, etc so we have to do the work ourselves
# we try to do this immediately after \document class, so that the correct size is set before \title, \author, etc
DefPrimitiveI('\bml@process@pt@size', undef, sub {
# ensure we do not run this twice
return if defined LookupValue('BML_PT_SIZE');
my ($stomach) = @_;
my ($class, $pt);
my @classoptions = @{ LookupValue('class_options') || [] };
# check 'aa', 'elsart' etc first since they load 'article', 'amsart' etc internally
for my $cls ('a0poster', 'aastex', 'acmart', 'beamer', 'elsart', 'IEEEtran', 'iopart', 'JHEP', 'JHEP2', 'JHEP3', 'minimal', 'slides', 'amsart', 'amsbook', 'amsproc', 'article', 'report', 'book') {
if (LookupValue("$cls.cls.ltxml_loaded")) {
$class = $cls; last; } }
for my $opt (grep(/^\d+pt$/, @classoptions)) {
$pt = $opt =~ s/pt//r; }
my %bml_font_sizes = (
# article
'size10.clo' => {
normalsize => [10, 12],
small => [9, 11],
footnotesize => [8, 9.5],
scriptsize => [7, 8],
tiny => [5, 6],
large => [12, 14],
Large => [14.4, 18],
LARGE => [17.28, 22],
huge => [20.74, 25],
Huge => [24.88, 30]
},
'size11.clo' => {
normalsize => [10.95, 13.6],
small => [10, 12],
footnotesize => [9, 11],
scriptsize => [8, 9.5],
tiny => [6, 7],
large => [12, 14],
Large => [14.4, 18],
LARGE => [17.28, 22],
huge => [20.74, 25],
Huge => [24.88, 30]
},
'size12.clo' => {
normalsize => [12, 14.5],
small => [10.95, 13.6],
footnotesize => [10, 12],
scriptsize => [8, 9.5],
tiny => [6, 7],
large => [14.4, 18],
Large => [17.28, 22],
LARGE => [20.74, 25],
huge => [24.88, 30],
Huge => [24.88, 30]
},
# extsizes
'size8.clo' => {
normalsize => [8, 9.5],
small => [7, 8],
footnotesize => [6, 7],
scriptsize => [5, 6],
tiny => [5, 6],
large => [10, 10.95],
Large => [10.95, 12],
LARGE => [12, 14],
huge => [14.4, 18],
Huge => [17.28, 22]
},
'size9.clo' => {
normalsize => [9, 10.95],
small => [8, 9],
footnotesize => [7, 8],
scriptsize => [6, 7],
tiny => [5, 6],
large => [10, 12],
Large => [10.95, 13],
LARGE => [12, 14],
huge => [14.4, 18],
Huge => [17.28, 22]
},
'size14.clo' => {
normalsize => [14.4, 17],
small => [12, 14],
footnotesize => [10, 12],
scriptsize => [8, 9.5],
tiny => [6, 7],
large => [17.28, 22],
Large => [20.74, 25],
LARGE => [24.88, 30],
huge => [29.86, 35],
Huge => [35.83, 40]
},
'size17.clo' => {
normalsize => [17.28, 22],
small => [14.4, 17],
footnotesize => [12, 14],
scriptsize => [10, 11],
tiny => [8, 9],
large => [20.74, 25],
Large => [24.88, 30],
LARGE => [29.86, 35],
huge => [35.83, 41],
Huge => [42.99, 52]
},
'size20.clo' => {
normalsize => [20.74, 25],
small => [17.28, 22],
footnotesize => [14.4, 17],
scriptsize => [12, 14],
tiny => [10, 11],
large => [24.88, 30],
Large => [29.86, 35],
LARGE => [35.83, 41],
huge => [42.99, 52],
Huge => [51.59, 63]
},
# book, amsdtx, amsldoc
'bk10.clo' => {
normalsize => [10, 12],
small => [9, 11],
footnotesize => [8, 9.5],
scriptsize => [7, 8],
tiny => [5, 6],
large => [12, 14],
Large => [14.4, 18],
LARGE => [17.28, 22],
huge => [20.74, 25],
Huge => [24.88, 30]
},
'bk11.clo' => {
normalsize => [10.95, 13.6],
small => [10, 12],
footnotesize => [9, 11],
scriptsize => [8, 9.5],
tiny => [6, 7],
large => [12, 14],
Large => [14.4, 18],
LARGE => [17.28, 22],
huge => [20.74, 25],
Huge => [24.88, 30]
},
'bk12.clo' => {
normalsize => [12, 14.5],
small => [10.95, 13.6],
footnotesize => [10, 12],
scriptsize => [8, 9.5],
tiny => [6, 7],
large => [14.4, 18],
Large => [17.28, 22],
LARGE => [20.74, 25],
huge => [24.88, 30],
Huge => [24.88, 30]
},
# amsart, amsbook, amsproc
'amscls10.clo' => {
Tiny => [5, 6],
tiny => [6, 7],
scriptsize => [7, 8],
footnotesize => [8, 10],
small => [9, 11],
normalsize => [10, 12],
large => [10.95, 13],
Large => [12, 14],
LARGE => [14.4, 17],
huge => [17.28, 20],
Huge => [20.74, 24]
},
'amscls11.clo' => {
Tiny => [6, 7],
tiny => [7, 8],
scriptsize => [8, 10],
footnotesize => [9, 11],
small => [10, 12],
normalsize => [10.95, 13],
large => [12, 14],
Large => [14.4, 17],
LARGE => [17.28, 20],
huge => [20.74, 24],
Huge => [24.88, 30]
},
'amscls12.clo' => {
Tiny => [7, 8],
tiny => [8, 10],
scriptsize => [9, 11],
footnotesize => [10, 12],
small => [10.95, 13],
normalsize => [12, 14],
large => [14.4, 17],
Large => [17.28, 20],
LARGE => [20.74, 24],
huge => [24.88, 30],
Huge => [24.88, 30]
},
'amscls8.clo' => {
Tiny => [5, 6],
tiny => [5, 6],
scriptsize => [5, 6],
footnotesize => [6, 7],
small => [7, 8],
normalsize => [8, 10],
large => [9, 11],
Large => [10, 12],
LARGE => [10.95, 13],
huge => [12, 14],
Huge => [14.4, 17]
},
'amscls9.clo' => {
Tiny => [5, 6],
tiny => [5, 6],
scriptsize => [6, 7],
footnotesize => [7, 8],
small => [8, 10],
normalsize => [9, 11],
large => [10, 12],
Large => [10.95, 13],
LARGE => [12, 14],
huge => [14.4, 17],
Huge => [17.28, 20]
},
# aa (which version? 9.0 on arXiv does not have *pt options)
'aa10.clo' => {
normalsize => [10, 11],
small => [9, 10],
scriptsize => [7, 8],
tiny => [8, 9],
large => [10.95, 13],
Large => [14.4, 16],
LARGE => [17.28, 20],
huge => [20.74, 24],
Huge => [24.88, 30],
footnotesize => [9, 10]
},
'aa11.clo' => {
normalsize => [10.95, 13.6],
small => [10, 12],
scriptsize => [8, 9.5],
tiny => [6, 7],
large => [12, 14],
Large => [14.4, 18],
LARGE => [17.28, 22],
huge => [20.74, 25],
Huge => [24.88, 30],
footnotesize => [10, 12]
},
'a12.clo' => {
normalsize => [12, 14.5],
small => [10.95, 13.6],
scriptsize => [8, 9.5],
tiny => [6, 7],
large => [14.4, 18],
Large => [17.28, 22],
LARGE => [20.74, 25],
huge => [24.88, 30],
Huge => [24.88, 30],
footnotesize => [10.95, 13.6]
},
# elsart
'elsart.clo' => {
normalsize => [12, 14.5],
small => [10.95, 13.6],
footnotesize => [10.95, 13.6],
scriptsize => [8, 9.5],
tiny => [6, 7],
large => [14.4, 18],
Large => [17.28, 22],
LARGE => [20.74, 22],
huge => [20.74, 27],
Huge => [20.74, 27]
},
# a0poster
'a0poster.cls' => {
tiny => [12, 14],
scriptsize => [14.4, 18],
footnotesize => [17.28, 22],
small => [20.74, 24],
normalsize => [24.88, 30],
large => [29.86, 37],
Large => [35.83, 45],
LARGE => [43, 54],
huge => [51.6, 64],
Huge => [61.92, 77],
veryHuge => [74.3, 93],
VeryHuge => [89.16, 112],
VERYHuge => [107, 134]
},
# minimal
'minimal.cls' => {
normalsize => [10, 12]
},
# slides
'slides.cls' => {
normalsize => [19.907, 28],
small => [16.59, 19],
footnotesize => [16.59, 19],
scriptsize => [16.59, 19],
tiny => [13.82, 16],
large => [23.89, 42],
Large => [28.66, 48],
LARGE => [34.4, 52],
huge => [41.28, 60],
Huge => [41.28, 60]
},
# IEEEtran
'IEEEtran9.cls' => {
normalsize => [9, 11.0476],
small => [8.5, 10],
footnotesize => [8, 9],
scriptsize => [7, 8],
tiny => [5, 6],
sublargesize => [10, 12],
large => [10, 12],
Large => [12, 14],
LARGE => [14, 17],
huge => [17, 20],
Huge => [20, 24]
},
'IEEEtran10.cls' => {
normalsize => [10, 12],
small => [9, 10],
footnotesize => [8, 9],
scriptsize => [7, 8],
tiny => [5, 6],
sublargesize => [11, 13.4],
large => [12, 14],
Large => [14, 17],
LARGE => [17, 20],
huge => [20, 24],
Huge => [24, 28]
},
'IEEEtran11.cls' => {
normalsize => [11, 13.3846],
small => [10, 12],
footnotesize => [9, 10.5],
scriptsize => [8, 9],
tiny => [6, 7],
sublargesize => [12, 14],
large => [12, 14],
Large => [14, 17],
LARGE => [17, 20],
huge => [20, 24],
Huge => [24, 28]
},
'IEEEtran12.cls' => {
normalsize => [12, 13.92],
small => [10, 12],
footnotesize => [9, 10.5],
scriptsize => [8, 9],
tiny => [6, 7],
sublargesize => [14, 17],
large => [14, 17],
Large => [17, 20],
LARGE => [20, 24],
huge => [22, 26],
Huge => [24, 28]
},
);
my $file;
if ($class eq 'a0poster') {
$file = 'a0poster.cls'; }
elsif ($class eq 'aastex') {
if (!defined $pt) {
$pt = 10;
for (@classoptions) {
if (m/^(?:manuscript|aasms4)$/) { $pt = 12; }
elsif (m/^(?:preprint|aaspp4|aj_pt4|apjpt4)$/) { $pt = 11; }
elsif (m/^(?:preprint2|aas2pp4)$/) { $pt = 10; } } }
$file = "size$pt.clo"; }
elsif ($class eq 'acmart') {
if (!defined $pt) {
$pt = 10;
for (@classoptions) {
if (m/^(?:manuscript|acmtog|sigconf|siggraph|sigchi|acmp)$/) { $pt = 9; }
elsif (m/^(?:acmsall|acmlarge|sigplan|sigchi-a|acmengage)$/) { $pt = 10; } } }
$file = "amscls$pt.clo"; }
elsif ($class =~ m/^(amsart|amsbook|amsproc)$/) {
$pt //= 10;
$file = "amscls$pt.clo"; }
elsif ($class =~ m/^(article|report)$/) {
$pt //= 10;
$file = "size$pt.clo"; }
elsif ($class eq 'beamer') {
if (!defined $pt) {
$pt = 11;
for (@classoptions) {
if (m/^smaller$/) { $pt = 10; }
elsif (m/^bigger$/) { $pt = 12; } } }
$file = "size$pt.clo"; }
elsif ($class eq 'book') {
$pt //= 10;
$file = ((10 <= $pt && $pt <= 12) ? 'bk' : 'size') . "$pt.clo"; }
elsif ($class eq 'elsart') {
$file = 'elsart.clo'; }
elsif ($class eq 'IEEEtran') {
$pt //= 10;
$file = "IEEEtran$pt.clo"; }
elsif ($class eq 'iopart') {
$file = ($pt == 10) ? 'size10.clo' : 'size12.clo'; }
elsif ($class =~ m/^JHEP/) {
$pt //= 11;
for (@classoptions) {
if (m/^proceedings$/) { $pt = 10; }
elsif (m/^published$/) { $pt = 11; } }
$file = "size$pt.clo"; }
elsif ($class eq 'minimal') {
$file = 'minimal.cls'; }
elsif ($class eq 'slides') {
$file = 'slides.cls'; }
# Remaining classes currently supported by LaTeXML:
# aa, elsarticle, ieeeconf, llcns, moderncv, quantumarticle covered by defaults
# aipproc OMITTED, font sizes are picked in the preamble by \layoutstyle
# standalone, subfiles not true classes
# TODO gen-j-l, gen-m-l, gen-p-l, mn, mn2e, mnras, PoS, revtex, revtex4-1, revtex4, svjour, svjour3, svmult
my $sizes = $bml_font_sizes{$file};
$pt //= 10;
AssignValue(BML_PT_SIZE => $pt, 'global');
if (!$sizes) {
# fall back to standard (ext)article sizes
$sizes = $bml_font_sizes{"size$pt.clo"};
if ($sizes) {
# in case LaTeXML adds support for a new class BookML does not know about
Warn('unexpected', $pt . 'pt', undef, "BookML does not know how the class handles the option '${pt}pt', falling back to extarticle sizes"); } }
# LaTeXML makes \baselinestretch a register with value 0, but it should be a macro with value 1
my $defn;
if (!($defn = LookupDefinition(T_CS('\baselinestretch'))) || $defn->isRegister) {
DefMacroI('\baselinestretch', undef, 1); }
if ($sizes) {
for my $name (keys %{$sizes}) {
my ($size, $skip) = @{ $sizes->{$name} };
# mimic the internal \@setfontsize
DefPrimitiveI("\\$name", undef, sub {
my ($stomach) = @_;
my $stretched = $skip * ToString(Expand(T_CS('\baselinestretch')));
$stretched = Glue("${stretched}pt");
AssignRegister('\normalbaselineskip' => $stretched);
AssignRegister('\baselineskip' => $stretched);
RawTeX('\normalbaselineskip\baselineskip');
return;
}, font => { size => $size });
}
# mimic running \normalsize in the preamble (hence scope 'global')
my ($normalsize, $skip) = @{ $sizes->{normalsize} };
my $stretched = $skip * ToString(Expand(T_CS('\baselinestretch')));
$stretched = Glue("${stretched}pt");
AssignRegister('\normalbaselineskip' => $stretched, 'global');
AssignRegister('\baselineskip' => $stretched, 'global');
# configure LaTeXML font size
AssignValue(NOMINAL_FONT_SIZE => $normalsize, 'global');
# save the pt font size in the output, for later use in CSS
# (at begin document, after latexml has been loaded)
AtBeginDocument(Tokens(T_CS('\lx@save@parameter'), T_OTHER('bml-font-size'), T_OTHER($normalsize)));
# set the font size to normal size
$stomach->digest(T_CS('\normalsize'));
} else {
Error('unexpected', $pt . 'pt', undef, "BookML does not know how the current class handles the option '${pt}pt' and no fall back found in extarticle"); }
return;
});
if (grep { m/\.cls\.ltxml_loaded$|\.cls_loaded$/ } keys %{ $STATE->{value} }) {
# called after \documentclass
Info('bookml', 'init', $STATE->getStomach, 'for best results, add \RequirePackage{bookml-init} or \RequirePackage{bookml/bookml} before \documentclass');
RawTeX('\bml@process@pt@size'); }
else {
# patch \documentclass to run \bml@process@pt@size
Let('\bml@orig@documentclass', '\documentclass');
DefMacro('\documentclass OptionalSemiverbatim SkipSpaces Semiverbatim []', sub {
my ($gullet, $options, $class, $postoptions) = @_;
Tokens(T_CS('\bml@orig@documentclass'), $options ? (T_OTHER('['), $options, T_OTHER(']')) : (), T_BEGIN, $class, T_END, $postoptions ? (T_OTHER('['), $postoptions, T_OTHER(']')) : (), T_CS('\bml@process@pt@size'));
}); }
1;