# How to convert `x[1] = 1.0` as \$x_1\$ = 1.0 in Jupyter notebook?

MWE:

``````using JuMP, GLPK
model = Model(GLPK.Optimizer)
@variable(model, x[i=1:4]>= 0.5, Int)
@objective(model, Min, sum(x))
optimize!(model)

for x in all_variables(model)
println("\$(name(x)) = \$(value(x))")
end
``````

As you know, run it in `Jupyter notebook`, you can get the output like this:

``````x[1] = 1.0
x[2] = 1.0
x[3] = 1.0
x[4] = 1.0
``````

and when you just input `x[1]`, you will get： x_1

So, I want to show my output like:

x_1 = 1.0\\ x_2 = 1.0\\ x_3 = 1.0\\ x_4 = 1.0

How to get these result with a simple code? And it will be the best if this result can be showed in REPL.

Thanks in advance!

There’s no easy answer to this. JuMP has a special `show` call to print variables and constraints in LaTeX, and this doesn’t get called for things via `println`.

What do you need if for? What’s your goal?

You could do something like this:

or, using the LaTeXStrings.jl package:

1 Like

I just think the result show in LaTeX style is more friendly which make variables look like letters printed in real books.