I am not able to make myself understood over at Mathematics Stackexchange in this question.

Therefore I ask here the Latex experts how to write these linear programming problems as latex, the standard way of communicating mathematics at the stack exchange network:

Linear programming problem written in Mathematica 8.0:

nn = 18;
  L2 = Table[
     Table[1/n, {n, 1, k}], {Table[If[n == 1, k, 1], {n, 1, k}]}, {{1,
        0}}, Table[
      If[n == 1, {-1, 1}, {-2 (n - 1), 0 (n - 1)}], {n, 1, k}]], {k, 
     1, nn}]]

Here is my own try:

$$\begin{array}{ll} \text{minimize} & \displaystyle\sum_{n=1}^{n=k} \frac{x_{n}}{n} \\ 
\text{subject to constraints:} & k + \displaystyle\sum_{n=2}^{n=k}x_{n}=1 \\ 
& x_1 \geq -1 \end{array}$$

for all $k$ and for all $n>1:$
$$-2(n-1) \leq x_n \leq 0 \tag{4}$$

enter image description here For some reason the latex above does not parse here on the Latex site. Maybe someone can edit appropriately, before I find it out myself how to write latex here?

  • 1
    to show latex output, clip a screenshot of your pdf viewer and upload the image. Jun 22, 2019 at 12:03
  • Yes they run MathJax on the mathematica site but it is not enabled here as it would be confusing as we need to see tex output. Jun 22, 2019 at 12:05
  • I added a screen shot Jun 22, 2019 at 12:05
  • Are you asking how to write this in latex or are you asking how to write this in mathjax, which is used on math.se
    – gigi
    Jun 22, 2019 at 12:16

1 Answer 1


You have a dedicated package for optimisation problems: optidef. Does this befit you?



{x}{\sum_{n=1}^{n=k} \frac{x_{n}}{n}}{\label{mylinpb}}{}
\addConstraint{ k + \sum_{n=2}^{n=k}x_{n}=1}{}{\quad\text{forall }k}
\addConstraint{x_1\ge 1}{}
\addConstraint{-2(n-1) \le x_n \le 0}{}{\quad\text{forall }n > 1.}


enter image description here

  • Did you translate this from the Mathematica program above? I am not used to the topics at tex stack exchange. What I am looking for is a latexification of the Mathematica program. Jun 22, 2019 at 13:25
  • NO, I mad it from scratch. Never used Mathematica. Doesn't Mathematice have a tool to convert its programs into LaTeX code?
    – Bernard
    Jun 22, 2019 at 13:29
  • Unfortunately not. They give examples though in the documentation how to translate specific cases, but not in general. Or at least I have not understood the documentation yet. For other commands such as sums and products used in calculus the translation is automatic. I am using version 8.0 of Mathematica. Jun 22, 2019 at 13:31

Not the answer you're looking for? Browse other questions tagged .