[Tex/LaTex] What’s the best way of typing the following 58 equations into LaTeX

datatoolequationsloopsmacros

For an applied math setting, I need to write multiple inequality constraints into a LaTeX report which are all in the form

x_{i} + x_{j} \ge 1.

I've typed up what "i" and "j" are in an excel sheet as parallel columns. I was wondering if there would be a way to loop through these values to generate the 58 equations, which would save a lot of typing (and it would also really make this scalable if we needed 500 equations, for instance)?

For example:
enter image description here

Best Answer

Here's a possible implementation; the delimiters can be changed.

\documentclass{article}
\usepackage{amsmath,multicol}
\usepackage{xparse}

\ExplSyntaxOn

\NewDocumentCommand{\constraints}{omO{x}}
 {
  \IfValueTF{#1}{\begin{multicols}{#1}\centering}{\begin{center}}
  \egreg_costraints:nn { #2 } { #3 }
  \IfValueTF{#1}{\end{multicols}}{\end{center}}
 }

\seq_new:N \l__egreg_constraints_seq

\cs_new_protected:Nn \egreg_costraints:nn
 {
  \seq_set_split:Nnn \l__egreg_constraints_seq { \\ } { #1 }
  \seq_map_inline:Nn \l__egreg_constraints_seq
   {
    \__egreg_constraints_item:nn { ##1 } { #2 }
   }
 }

\cs_new_protected:Nn \__egreg_constraints_item:nn
 {
  \tl_if_blank:nF { #1 }
   {
    $#2\sb{\clist_item:nn { #1 } { 1 }} + #2\sb{\clist_item:nn { #1 } { 2 }}\ge1$ \\
   }
 }

\ExplSyntaxOff

\begin{document}

\constraints{
  1,2 \\ 3,4 \\ 5,6
}

\constraints{
  1,2 \\ 3,4 \\ 5,6
}[y]

\constraints[3]{
  1,2 \\ 3,4 \\ 5,6 \\
  1,2 \\ 3,4 \\ 5,6 \\
  1,2 \\ 3,4 \\ 5,6 \\
  1,2 \\ 3,4 \\ 5,6 \\
  1,2 \\ 3,4 \\ 5,6 \\
  1,2 \\ 3,4 \\ 5,6 \\
  1,2 \\ 3,4 \\ 5,6 \\
  1,2 \\ 3,4 \\ 5,6 \\
  1,2 \\ 3,4 \\ 5,6 \\
}

\end{document}

enter image description here

Related Question