Skip to content

Commit 36e2842

Browse files
authored
Merge pull request #115 from Kolaru/prime
Put primes as superscripts
2 parents c8cb679 + 5a27bfd commit 36e2842

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

src/engine/layout.jl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ function tex_layout(expr, state)
5656
elseif head == :decorated
5757
core, sub, super = tex_layout.(args, state)
5858

59+
if !isnothing(args[3]) && args[3].head == :primes
60+
super_x = min(hadvance(core), rightinkbound(core)) - 0.1
61+
super_y = 0.1
62+
super_shrink = 1
63+
else
64+
super_x = max(hadvance(core), rightinkbound(core))
65+
super_y = xheight(font_family)
66+
super_shrink = shrink
67+
end
68+
5969
return Group(
6070
[core, sub, super],
6171
Point2f[
@@ -64,13 +74,10 @@ function tex_layout(expr, state)
6474
# The logic is to have the ink of the subscript starts
6575
# where the ink of the unshrink glyph would
6676
hadvance(core) + (1 - shrink) * leftinkbound(sub),
67-
-0.1
77+
-0.2
6878
),
69-
(
70-
max(hadvance(core), rightinkbound(core)),
71-
xheight(font_family)
72-
)],
73-
[1, shrink, shrink]
79+
( super_x, super_y)],
80+
[1, shrink, super_shrink]
7481
)
7582
elseif head == :delimited
7683
elements = tex_layout.(args, state)
@@ -168,6 +175,9 @@ function tex_layout(expr, state)
168175
(0, 0)
169176
]
170177
)
178+
elseif head == :primes
179+
primes = [TeXExpr(:char, ''') for _ in 1:only(args)]
180+
return horizontal_layout(tex_layout.(primes, state))
171181
elseif head == :space
172182
return Space(args[1])
173183
elseif head == :spaced

src/parser/parser.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ function texparse(tex ; root = TeXExpr(:expr), showdebug = false)
155155
com_str = tex[pos:pos+len-1]
156156
push!(stack, TeXExpr(:command, [com_str]))
157157
conclude_command!!(stack)
158-
elseif token == underscore || token == caret
159-
dec = token == underscore ? :subscript : :superscript
158+
elseif token == underscore || token == caret || token == primes
159+
dec = (token == underscore) ? :subscript : :superscript
160160

161161
if isempty(first(stack).args)
162162
core = TeXExpr(:space, 0.0)
@@ -173,7 +173,12 @@ function texparse(tex ; root = TeXExpr(:expr), showdebug = false)
173173
end
174174

175175
push!(first(stack), core)
176-
push!(stack, TeXExpr(dec))
176+
177+
if token == primes
178+
core.args[subsuperindex(dec)] = TeXExpr(:primes, len)
179+
else
180+
push!(stack, TeXExpr(dec))
181+
end
177182
elseif token == char
178183
push!(stack, canonical_expr(tex[pos]))
179184
push_down!(stack)

src/parser/tokenizer.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
tex_tokens = [
22
:char => re".",
3+
:primes => re"'+",
34
:caret => re"\^",
45
:underscore => re"_",
56
:rcurly => re"}",

0 commit comments

Comments
 (0)