-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.jl
134 lines (110 loc) · 2.53 KB
/
utils.jl
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
using Franklin
mutable struct Theorem
chapter::Int
section::Int
subsection::Int
Theorem() = new(0, 0, 0)
end
mutable struct State
level::Symbol
thm::Theorem
label2thm::Dict{Any,Any}
end
# global state
state = State(:chapter, Theorem(), Dict())
function get_current_state()
state
end
function lx_initcounter(com, _)
global state
state = State(:chapter, Theorem(), Dict())
return ""
end
function setlevel(new::Symbol)
global state
state.level = new
end
setlevel(new::AbstractString) = setlevel(Symbol(new))
function lx_setlevel(com, _)
brace_content = Franklin.content(com.braces[1])
setlevel(brace_content)
return ""
end
function record_theorem_number(label)
global state
state.label2thm[label] = deepcopy(state.thm)
end
function lx_generateLabel(com, _)
label = Franklin.content(com.braces[1])
if label != ""
return "\\label{$(label)}"
else
return ""
end
end
function lx_generateTheoremName(com, _)
name = Franklin.content(com.braces[1])
if name != ""
return "($name)"
else
return ""
end
end
function increment()
global state
t = state.thm
state.level == :chapter && (t.chapter += 1)
state.level == :section && (t.section += 1)
state.level == :subsection && (t.subsection += 1)
# update
state.thm = t
end
function lx_increment(com, _)
increment()
return ""
end
function resetcount()
global state
t = state.thm
state.level == :chapter && (t.chapter = 0)
state.level == :section && (t.section = 0)
state.level == :subsection && (t.subsection = 0)
# update
state.thm = t
end
function lx_resetcount(com, _)
resetcount()
return ""
end
get_theorem_number(t::Theorem) = "$(t.chapter).$(t.section).$(t.subsection)"
function get_theorem_number()
global state
get_theorem_number(state.thm)
end
function lx_getTheoremNumber(com, _)
global state
get_theorem_number(state.thm)
end
function ref(label::AbstractString)
global state
try
n = get_theorem_number(state.label2thm[label])
return "[$n](#$label)"
catch
@warn "fail to ref $label"
return "???"
end
end
function lx_ref(com, _)
brace_content = Franklin.content(com.braces[1])
ref(brace_content)
end
function lx_recordTheoremNumber(com, _)
brace_content = Franklin.content(com.braces[1])
record_theorem_number(brace_content)
return ""
end
function lx_bold(com, _)
text = Franklin.content(com.braces[1])
return "__$(text)__"
end