-
Notifications
You must be signed in to change notification settings - Fork 0
/
latex-logo.lua
89 lines (82 loc) · 2.04 KB
/
latex-logo.lua
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
-- Render TeX and LaTeX like the `\TeX` and `\LaTeX{}` macros do.
-- Copyright © 2020 Albert Krewinkel <[email protected]>
-- License: MIT License
-- Style inspired by https://tess.oconnor.cx/2007/08/tex-poshlet
local style = pandoc.RawBlock('html', [[
<style>
.tex-logo sub, .latex-logo sub {
font-size: 100%;
margin-left: -0.1667em;
margin-right: -0.125em;
vertical-align: -0.5ex;
}
.latex-logo sup {
font-size: 0.85em;
margin-left: -0.36em;
margin-right: -0.15em;
vertical-align: 0.15em;
}
</style>
]])
local tex_text = pandoc.List{
pandoc.Str 'T',
pandoc.Subscript{pandoc.Str 'E'},
pandoc.Str 'X'
}
local latex_text = pandoc.List{
pandoc.Str 'L',
pandoc.Superscript{pandoc.Str 'A'}
} .. tex_text
local make_logo
if FORMAT:match 'tex$' then
make_logo = function (logo_text)
if logo_text == 'LaTeX' then
return pandoc.RawInline('latex', '\\LaTeX{}')
elseif logo_text == 'TeX' then
return pandoc.RawInline('tex', '\\TeX{}')
else
return nil
end
end
else
make_logo = function (logo_text)
if logo_text == 'TeX' then
return pandoc.Span(
tex_text,
pandoc.Attr("", {"tex-logo"})
)
elseif logo_text == 'LaTeX' then
return pandoc.Span(
latex_text,
pandoc.Attr("", {"latex-logo"})
)
else
return nil
end
end
end
function RawInline (raw)
if not raw.format:match 'tex$' then return nil end
local logo_text = raw.text:match '^\\(L?a?TeX)[%b{}]?'
return make_logo(logo_text)
end
function Str (str)
local logo_text, suffix = str.text:match '^(L?a?TeX)([^%a%*]?.*)'
if logo_text then
return {
make_logo(logo_text),
suffix ~= '' and pandoc.Str(suffix) or nil
}
end
end
if FORMAT:match 'html' then
function Meta (meta)
local header_includes = meta['header-includes'] or pandoc.MetaList{}
if header_includes.t ~= 'MetaList' then
header_includes = pandoc.MetaList(header_includes)
end
header_includes:insert{style}
meta['header-includes'] = header_includes
return meta
end
end