Skip to content

Commit

Permalink
Fix printing of Interval in LaTeX (#3866)
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat authored Nov 4, 2024
1 parent be7d350 commit 139bead
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ end

# Helper function that rounds carefully for the purposes of printing Reals
# for example, 5.3 => 5.3, and 1.0 => 1
function _string_round(mode, x::Union{Float32,Float64})
function _string_round(mode::MIME, x::Union{Float32,Float64})
if isinteger(x) && typemin(Int64) <= x <= typemax(Int64)
return string(round(Int64, x))
end
Expand Down Expand Up @@ -1054,7 +1054,7 @@ function in_set_string(mode::MIME, set::MOI.EqualTo)
return string(_math_symbol(mode, :eq), " ", _string_round(mode, set.value))
end

function in_set_string(::MIME"text/latex", set::MOI.Interval)
function in_set_string(mode::MIME"text/latex", set::MOI.Interval)
lower = _string_round(mode, set.lower)
upper = _string_round(mode, set.upper)
return string("\\in [", lower, ", ", upper, "]")
Expand Down
4 changes: 4 additions & 0 deletions test/test_print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,10 @@ end

function test_print_text_latex_interval_set()
@test in_set_string(MIME("text/latex"), MOI.Interval(1, 2)) == "\\in [1, 2]"
@test in_set_string(MIME("text/latex"), MOI.Interval(1.0, 2.0)) ==
"\\in [1, 2]"
@test in_set_string(MIME("text/latex"), MOI.Interval(1.5, 2.5)) ==
"\\in [1.5, 2.5]"
return
end

Expand Down

0 comments on commit 139bead

Please sign in to comment.