Skip to content

Commit be81f8d

Browse files
authored
Fix unicode check for \( and \) (#260)
1 parent 1424d90 commit be81f8d

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/show.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ function _trim_LaTeX(s::AbstractString)
142142
i = nextind(s, i)
143143
j = prevind(s, j)
144144
elseif i < j && (
145-
(s[i:i+1] == "\\(" && s[j-1:j] == "\\)") ||
146-
(s[i:i+1] == "\\[" && s[j-1:j] == "\\]")
145+
(s[i:nextind(s, i)] == "\\(" && s[prevind(s, j):j] == "\\)") ||
146+
(s[i:nextind(s, i)] == "\\[" && s[prevind(s, j):j] == "\\]")
147147
)
148148
i = nextind(s, i, 2)
149149
j = prevind(s, j, 2)

test/show.jl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
struct CustomLaTeXPrint end
1+
struct CustomLaTeXPrint
2+
s::String
3+
end
24

3-
Base.:-(::CustomLaTeXPrint) = CustomLaTeXPrint()
5+
Base.:-(s::CustomLaTeXPrint) = s
46
Base.iszero(::CustomLaTeXPrint) = false
5-
function Base.show(io::IO, ::MIME"text/latex", ::CustomLaTeXPrint)
6-
return print(io, " \$\$ \\[\\(a_a \\) \\]\t \$\$")
7+
function Base.show(io::IO, ::MIME"text/latex", s::CustomLaTeXPrint)
8+
return print(io, s.s)
79
end
810

911
@testset "Show" begin
@@ -57,11 +59,15 @@ end
5759
@test sprint(print, 2x[1]^2 + 3x[3] + 1 + x[4]) ==
5860
"1 + x[4] + 3*x[3] + 2*x[1]^2"
5961

60-
a = CustomLaTeXPrint()
62+
a = CustomLaTeXPrint(" \$\$ \\[\\(α_β∀ \\) \\]\t \$\$")
6163
@test sprint((io, x) -> show(io, "text/latex", x), term(a, x[1]^2)) ==
62-
"\$\$ (a_a)x_{1}^{2} \$\$"
64+
"\$\$ (α_β∀)x_{1}^{2} \$\$"
6365
@test sprint(
6466
(io, x) -> show(io, "text/latex", x),
6567
polynomial([a, a], [x[1]^2, x[2]]),
66-
) == "\$\$ (a_a)x_{2} + (a_a)x_{1}^{2} \$\$"
68+
) == "\$\$ (α_β∀)x_{2} + (α_β∀)x_{1}^{2} \$\$"
69+
# Test that the check for `\\)` handles unicode well
70+
a = CustomLaTeXPrint("\\(β∀")
71+
@test sprint((io, x) -> show(io, "text/latex", x), term(a, x[1]^2)) ==
72+
"\$\$ (\\(β∀)x_{1}^{2} \$\$"
6773
end

0 commit comments

Comments
 (0)