I want to write a macro for optimisation problems and my current approach is to write a macro, that takes the target function and a list of constraints. The entries are separated by comma, and each entry is of the type "(in)equality / range", e.g.
x_i \geq 0 / i=1,...,n
I got the idea from Defining a command with arbitrary number of parameters. However, this does not allow new lines inside an align.
My friend found out to use \pgfplotsforeachungrouped, but now I cannot write & inside the loop.
The following code compiles, but does not look nice.
edit: now has entries of type \x/\y.
\documentclass{article}
\usepackage{extarrows,pgffor}
\usepackage{pgfplots}
\begin{document}
\begin{align*}
\pgfplotsforeachungrouped \x/\y in {a/3, b/5, foo/0}{
\x_i : \x = \x \quad i=\y \\
}
\end{align*}
\end{document}
But if I replace the body of the loop by \x_i : \x &= \x \quad i=\y \\ (just adding the &), I get multiple errors `! Undefined control sequence.
Furthermore, using entry a/{0,\ldots,5} does not work as expected.
It only takes the 0.
Also I might wish to put the range of my variable inside \tag, or similar.
Tying this, I get another Undefined control sequence for `\y¸.
- So how can I align these lines inside the loop? solved in answer of Steven B. Segletes
- How can I have more complex values in the entries?
- How can I place the second part of an entry inside
\tag*{}?
Maybe-helpful-link: I don't understand Foreach loop in tabular, missing endgroup inserted, so I can't tell, whether the idea helps, but it seems to go in the direction.


