From eea6b3d634666a714ba391fa8c3894d79708a831 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 14 Jul 2014 22:42:51 +0000 Subject: lpform (14jul14) git-svn-id: svn://tug.org/texlive/trunk@34608 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/generic/lpform/lpform.sty | 72 +++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Master/texmf-dist/tex/generic/lpform/lpform.sty (limited to 'Master/texmf-dist/tex') diff --git a/Master/texmf-dist/tex/generic/lpform/lpform.sty b/Master/texmf-dist/tex/generic/lpform/lpform.sty new file mode 100644 index 00000000000..75a228a425f --- /dev/null +++ b/Master/texmf-dist/tex/generic/lpform/lpform.sty @@ -0,0 +1,72 @@ +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{lpform}[2014/07/14] + +\usepackage{xifthen} + +\makeatletter + +\newcounter{subcounter} % This is the counter for the sub-equations +\newcounter{eqcounter} % This counts the number of equations in the lpformulation environment + +% Creating custom labels +\newcommand{\customlabel}[2]{\protected@write \@auxout{}{\string \newlabel {#1}{{#2}{}}}} + +% The name of the formulation +\newcommand{\lpname}{} + +% The lpformulation environment +\newenvironment{lpformulation}[1][]{\setcounter{eqcounter}{0}\renewcommand{\lpname}{#1} \start@align\tw@\st@rredfalse\m@ne \ifthenelse{\isempty{#1}}{}{\lpname}}{\endalign} + +% The method that is used to display the for all arguments +\newcommand{\lpforall}[1]{\quad \forall #1} + +% The size of the left indent +\newcommand{\lpindent}{\hspace{20pt}} + +% The method that is used to tag subequations +\newcommand{\lpsubeqtag}{\theequation\alph{subcounter}} + +% The text that is shown on the 'subject to' line +\newcommand{\lpsubjectto}{s.t.} + +% Labeling the lp formulation +\newcommand{\lplabel}[1]{\customlabel{#1}{\lpname}} + +% Splitting one equation into two lines +\newcommand{\lpnewline}{\nonumber\\&\lpindent} + +% \lpobj(*)[label]{min/max}{objective function} +\def\lpobj{\@ifstar\@@lpobj\@lpobj} +\newcommand{\@lpobj}[3][]{\ifthenelse{\value{eqcounter} = 0}{}{\displaybreak[0]\\}\stepcounter{eqcounter}&\lpindent\textrm{#2 } #3 \ifthenelse{\isempty{#1}}{}{\label{#1}}&\\&\lpindent\nonumber\textrm{\lpsubjectto}&} +\newcommand{\@@lpobj}[3][]{\ifthenelse{\value{eqcounter} = 0}{}{\displaybreak[0]\\}\stepcounter{eqcounter}&\lpindent\textrm{#2 } #3 \nonumber \ifthenelse{\isempty{#1}}{}{\label{#1}}&\\&\lpindent\nonumber\textrm{\lpsubjectto}&} + +% \lpeq(*)[label]{constraint}{for all} +\def\lpeq{\@ifstar\@@lpeq\@lpeq} +\newcommand{\@lpeq}[3][]{\ifthenelse{\value{eqcounter} = 0}{}{\displaybreak[0]\\}\stepcounter{eqcounter}&\lpindent #2 \ifthenelse{\isempty{#3}}{}{\lpforall{#3}}\ifthenelse{\isempty{#1}}{}{\label{#1}}&} +\newcommand{\@@lpeq}[3][]{\ifthenelse{\value{eqcounter} = 0}{}{\displaybreak[0]\\}\stepcounter{eqcounter}&\lpindent #2 \nonumber\ifthenelse{\isempty{#3}}{}{\lpforall{#3}}\ifthenelse{\isempty{#1}}{}{\label{#1}}&} + +% \lpnewsubeq(*)[label]{constraint}{for all} +\def\lpnewsubeq{\@ifstar\@@lpnewsubeq\@lpnewsubeq} +\newcommand{\@lpnewsubeq}[3][]{\ifthenelse{\value{eqcounter} = 0}{}{\displaybreak[0]\\}\stepcounter{eqcounter}&\lpindent\refstepcounter{equation}\setcounter{subcounter}{1} #2 \ifthenelse{\isempty{#3}}{}{\lpforall{#3}}\tag{\lpsubeqtag}\ifthenelse{\isempty{#1}}{}{\label{#1}}&} +\newcommand{\@@lpnewsubeq}[3][]{\ifthenelse{\value{eqcounter} = 0}{}{\displaybreak[0]\\}\stepcounter{eqcounter}&\lpindent\refstepcounter{equation}\setcounter{subcounter}{0} #2 \nonumber\ifthenelse{\isempty{#3}}{}{\lpforall{#3}}\ifthenelse{\isempty{#1}}{}{\label{#1}}&} + +% \lpsubeq(*)[label]{constraint}{for all} +\def\lpsubeq{\@ifstar\@@lpsubeq\@lpsubeq} +\newcommand{\@lpsubeq}[3][]{\ifthenelse{\value{eqcounter} = 0}{}{\displaybreak[0]\\}\stepcounter{eqcounter}&\lpindent\refstepcounter{subcounter} #2 \ifthenelse{\isempty{#3}}{}{\lpforall{#3}}\tag{\lpsubeqtag}\ifthenelse{\isempty{#1}}{}{\label{#1}}&} +\newcommand{\@@lpsubeq}[3][]{\ifthenelse{\value{eqcounter} = 0}{}{\displaybreak[0]\\}\stepcounter{eqcounter}&\lpindent #2 \nonumber\ifthenelse{\isempty{#3}}{}{\lpforall{#3}}\ifthenelse{\isempty{#1}}{}{\label{#1}}&} + +% Using the noforall option +\DeclareOption{noforall}{ + \renewcommand{\@lpeq}[2][]{\ifthenelse{\value{eqcounter} = 0}{}{\displaybreak[0]\\}\stepcounter{eqcounter}&\lpindent #2 \ifthenelse{\isempty{#1}}{}{\label{#1}}&} + \renewcommand{\@@lpeq}[2][]{\ifthenelse{\value{eqcounter} = 0}{}{\displaybreak[0]\\}\stepcounter{eqcounter}&\lpindent #2 \nonumber\ifthenelse{\isempty{#1}}{}{\label{#1}}&} + \renewcommand{\@lpnewsubeq}[2][]{\ifthenelse{\value{eqcounter} = 0}{}{\displaybreak[0]\\}\stepcounter{eqcounter}&\lpindent\refstepcounter{equation}\setcounter{subcounter}{1} #2 \tag{\lpsubeqtag}\ifthenelse{\isempty{#1}}{}{\label{#1}}&} + \renewcommand{\@@lpnewsubeq}[2][]{\ifthenelse{\value{eqcounter} = 0}{}{\displaybreak[0]\\}\stepcounter{eqcounter}&\lpindent\refstepcounter{equation}\setcounter{subcounter}{0} #2 \nonumber\ifthenelse{\isempty{#1}}{}{\label{#1}}&} + \renewcommand{\@lpsubeq}[2][]{\ifthenelse{\value{eqcounter} = 0}{}{\displaybreak[0]\\}\stepcounter{eqcounter}&\lpindent\refstepcounter{subcounter} #2 \tag{\lpsubeqtag}\ifthenelse{\isempty{#1}}{}{\label{#1}}&} + \renewcommand{\@@lpsubeq}[2][]{\ifthenelse{\value{eqcounter} = 0}{}{\displaybreak[0]\\}\stepcounter{eqcounter}&\lpindent #2 \nonumber\ifthenelse{\isempty{#1}}{}{\label{#1}}&} +} +\ExecuteOptions{} +\ProcessOptions\relax + +\makeatother + +\endinput \ No newline at end of file -- cgit v1.2.3