# JuMP element wise \`latex\_formulation\`

**URL:** <https://discourse.julialang.org/t/jump-element-wise-latex-formulation/86842>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [September 6, 2022, 1:35pm UTC](https://discourse.julialang.org/t/jump-element-wise-latex-formulation/86842 "2022-09-06T13:35:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![this\_josh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/this_josh/32/42679_2.png) [@this\_josh](https://discourse.julialang.org/u/this_josh)\
**Post date:** [September 6, 2022, 1:35pm UTC](https://discourse.julialang.org/t/jump-element-wise-latex-formulation/86842/1 "2022-09-06T13:35:53Z")

</div>

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

Given a model

```nohighlight
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.

---

<div class="post-metadata">

**Author:** ![cvanaret](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cvanaret/32/11594_2.png) [@cvanaret](https://discourse.julialang.org/u/cvanaret)\
**Post date:** [September 6, 2022, 2:57pm UTC](https://discourse.julialang.org/t/jump-element-wise-latex-formulation/86842/2 "2022-09-06T14:57:14Z")

</div>

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}

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [September 6, 2022, 6:30pm UTC](https://discourse.julialang.org/t/jump-element-wise-latex-formulation/86842/3 "2022-09-06T18:30:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![this\_josh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/this_josh/32/42679_2.png) [@this\_josh](https://discourse.julialang.org/u/this_josh)\
**Post date:** [September 6, 2022, 7:22pm UTC](https://discourse.julialang.org/t/jump-element-wise-latex-formulation/86842/4 "2022-09-06T19:22:18Z")

</div>

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