Skip to content

Commit 7229d74

Browse files
authored
Merge pull request #80 from karlwessel/master
implement \overline command
2 parents 50f8b4c + dd74625 commit 7229d74

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

src/engine/layout.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,21 @@ function tex_layout(expr, state)
137137
],
138138
[1, shrink, shrink]
139139
)
140+
elseif head == :overline
141+
content = tex_layout(args[1], state)
142+
143+
lw = thickness(font_family)
144+
y = topinkbound(content) - lw
145+
146+
hline = HLine(inkwidth(content) - 0.15, lw)
147+
148+
return Group(
149+
[hline, content],
150+
Point2f[
151+
(0.25, y + lw/2 + 0.2),
152+
(0, 0)
153+
]
154+
)
140155
elseif head == :space
141156
return Space(args[1])
142157
elseif head == :spaced
@@ -172,7 +187,6 @@ function tex_layout(expr, state)
172187
(rightinkbound(content), 0)
173188
]
174189
)
175-
176190
elseif head == :underover
177191
core, sub, super = tex_layout.(args, state)
178192

src/parser/commands_registration.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ end
6262

6363
command_to_canonical[raw"\frac"] = TeXExpr(:argument_gatherer, [:frac, 2])
6464
command_to_canonical[raw"\sqrt"] = TeXExpr(:argument_gatherer, [:sqrt, 1])
65+
command_to_canonical[raw"\overline"] = TeXExpr(:argument_gatherer, [:overline, 1])
6566
command_to_canonical[raw"\{"] = TeXExpr(:delimiter, '{')
6667
command_to_canonical[raw"\}"] = TeXExpr(:delimiter, '}')
6768

test/layout.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ end
101101
tex = L"Momentum $p_x$ (a.u.)"
102102
generate_tex_elements(tex)
103103

104+
tex = L"Average $\overline{an}_i$"
105+
@test length(generate_tex_elements(tex)) == 12
106+
104107
elems = generate_tex_elements(L"Time $t_0$")
105108
@test length(elems) == 7
106-
end
109+
end

test/parser.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ end
144144
)
145145
end
146146

147+
@testset "Overline" begin
148+
test_parse(raw"\overline{x}", (:overline, 'x'))
149+
test_parse(
150+
raw"\overline{abc}",
151+
(:overline, (:group, 'a', 'b', 'c'))
152+
)
153+
end
154+
147155
@testset "Space" begin
148156
test_parse(raw"\quad", (:space, 1))
149157
test_parse(raw"\qquad", (:space, 2))
@@ -186,4 +194,4 @@ end
186194
(:decorated, (:symbol, 'ω'), 'k', nothing)
187195
)
188196
end
189-
end
197+
end

0 commit comments

Comments
 (0)