JuMP element wise `latex_formulation`

I have some large JuMP models which I’d like to convert to latex, however, this quickly becomes impractical.

Given a model

using JuMP

model = Model()

@variable(model, x[1:10])
@constraint(model, x_min, x .≤ 10)
@constraint(model, x_max, x .≥ 0)
@objective(model, Min, sum(x))

Calling latex_formulation(model) gives:

\begin{aligned} \min\quad & x_{1} + x_{2} + x_{3} + x_{4} + x_{5} + x_{6} + x_{7} + x_{8} + x_{9} + x_{10}\\ \text{Subject to} \quad & x_{1} \geq 0.0\\ & x_{2} \geq 0.0\\ & x_{3} \geq 0.0\\ & \vdots \\ & x_{1} \leq 10.0\\ & x_{2} \leq 10.0\\ & x_{3} \leq 10.0\\ & \vdots \end{aligned}

Which for large models becomes impractical to read, is it possible to get something like this?

\begin{aligned} \min\quad & \sum_i^{|x_i|} x\\ \text{Subject to} \quad & x_i \geq 0.0, \quad \forall i=1,\dots, |x|\\ & x_i \leq 10.0, \quad \forall i=1,\dots, |x|\\ \end{aligned}

Which closely resembles the code used to make the model.

Can’t help you on this one, but a correct formulation would be:
\begin{aligned} \min_x \quad & \sum_{i=1}^n x_i \\ \text{subject to} \quad & x_i \geq 0.0, \quad \forall i=1,\dots, n \\ & x_i \leq 10.0, \quad \forall i=1,\dots, n \\ \end{aligned}
or even
\begin{aligned} \min_x \quad & \sum_{i=1}^n x_i \\ \text{subject to} \quad & 0.0 \le x_i \le 10.0, \quad \forall i=1,\dots, n \end{aligned}


No, its not possible. Its surprisingly hard to implement in the general case

1 Like

I had a feeling this would be the answer. I’ll think about implementing a use case specific one, cheers.