From 66681cce466f39f0fc76a55d7a0b1d9c6142c660 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 10 Jun 2016 21:47:45 +0000 Subject: optidef (10jun16) git-svn-id: svn://tug.org/texlive/trunk@41347 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/latex/optidef/optidef.sty | 568 +++++++++--------------- 1 file changed, 209 insertions(+), 359 deletions(-) (limited to 'Master/texmf-dist/tex/latex/optidef') diff --git a/Master/texmf-dist/tex/latex/optidef/optidef.sty b/Master/texmf-dist/tex/latex/optidef/optidef.sty index 47addfa92dc..9967b8919ad 100644 --- a/Master/texmf-dist/tex/latex/optidef/optidef.sty +++ b/Master/texmf-dist/tex/latex/optidef/optidef.sty @@ -1,4 +1,4 @@ -% optidef - Version 08/06/2016 +% optidef - Version 1.0 % %Copyright 2016 J. Lago Garcia % @@ -17,367 +17,217 @@ \RequirePackage{environ} \RequirePackage{mathtools} \RequirePackage{xifthen} +\RequirePackage{etoolbox} +\newtoggle{bodyCon} +\toggletrue{bodyCon} - % Input minimization evironments - - % Macros for objective definition, constraint definition and extra constraint definition - \newcommand{\bodyobj}[4] +% Input minimization evironments + +% Macros for objective definition, constraint definition and extra constraint definition +\newcommand{\bodyobj}[4] +{ + \ifthenelse{\isempty{#4}} { - \ifthenelse{\isempty{#4}} - { - &\underset{\displaystyle #1}{\mbox{#3}} \quad #2\span\span\span\span - } - { - #4 ~~ &\underset{\displaystyle #1}{\mbox{#3}} \quad #2\span\span\span\span - } + &\underset{\displaystyle #1}{\mbox{#3}} \quad #2\span\span\span\span } - - - \newcommand{\bodyconst}[2] - {&\mbox{subject to} \quad  & #2\span\span} - - \newcommand{\addConstraint}[2]{&\quad  & #2, \\} - \newcommand{\finalConstraint}[2]{&\quad  & #2} - - - %\newcommand(\breakObjectiveUnconstraint)[1]{\\% - %\bodyobjUn{}{#1}{\phantom{minimize}}{}} - \newcommand{\breakObjectiveOneConstraint}[1]{&&\\} - %\newcommand(\breakObjective)[1]{\bodyobj{}{#4}{\phantom{minimize}}{}\nonumber\\} } - - \newcommand{\bodyconstOne}[2] - {&\text{subject to} \quad & #2} - - % This body of the objective is only valid for - % one constraint problem since there is no need to - % use mathllap to achieve second alignment level - \newcommand{\bodyobjOne}[4] { - \ifthenelse{\isempty{#4}} - { - &\underset{\displaystyle #1}{\text{#3}} \quad & - } - { - #4 ~~ &\underset{\displaystyle #1}{\text{#3}} \quad &} - } - - - % This body of the objective is only valid for - % no constraint problem since there is no need to - % align - \newcommand{\bodyobjUn}[4] - { - \ifthenelse{\isempty{#4}} - { - } - { - #4~ - } - \underset{\displaystyle #1}{\text{#3}} \quad #2 - } - - %MINIMIZATION ENVIRONMENTS - - \NewEnviron{mini}[7]{% - \ifthenelse{\equal{#1}{0}}{% - \begin{equation} - #6 - \bodyobjUn{#2}{#3}{minimize}{#7} - \end{equation} - }% - {% - \ifthenelse{\equal{#1}{1}}{% - \begin{equation} - #6 - \begin{alignedat}{3} - \bodyobjOne{#2}{#3}{minimize}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignedat} - \end{equation} - }% - {% - \begin{equation} - #6 - \begin{alignedat}{4} - \bodyobj{#2}{#3}{minimize}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignedat} - \end{equation} - }% - }% - } - - \NewEnviron{argmini}[7]{% - \ifthenelse{\equal{#1}{0}}{% - \begin{equation} - #6 - \bodyobjUn{#2}{#3}{arg min}{#7} - \end{equation} - }% - {% - \ifthenelse{\equal{#1}{1}}{% - \begin{equation} - #6 - \begin{alignedat}{3} - \bodyobjOne{#2}{#3}{arg min}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignedat} - \end{equation} - }% - {% - \begin{equation} - #6 - \begin{alignedat}{4} - \bodyobj{#2}{#3}{arg min}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignedat} - \end{equation} - }% - }% - } - - \NewEnviron{mini*}[7]{% - \ifthenelse{\equal{#1}{0}}{% - \begin{equation*} - \bodyobjUn{#2}{#3}{minimize}{#7} - \end{equation*} - }% - {% - \ifthenelse{\equal{#1}{1}}{% - \begin{alignat*}{3} - \bodyobjOne{#2}{#3}{minimize}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignat*} - }% - {% - \begin{alignat*}{5} - \bodyobj{#2}{#3}{minimize}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignat*} - }% - }% - } - - \NewEnviron{argmini*}[7]{% - \ifthenelse{\equal{#1}{0}}{% - \begin{equation*} - \bodyobjUn{#2}{#3}{arg min}{#7} - \end{equation*} - }% - {% - \ifthenelse{\equal{#1}{1}}{% - \begin{alignat*}{3} - \bodyobjOne{#2}{#3}{arg min}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignat*} - }% - {% - \begin{alignat*}{4} - \bodyobj{#2}{#3}{arg min}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignat*} - }% - }% - } - - - \NewEnviron{mini!}[7]{% - \ifthenelse{\equal{#1}{1}}{% - \begin{subequations} - #6 - \begin{alignat}{3} - \bodyobjOne{#2}{#3}{minimize}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignat} - \end{subequations} - }% - {% - \begin{subequations} - #6 - \begin{alignat}{4} - \bodyobj{#2}{#3}{minimize}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignat} - \end{subequations} - }% - } - - \NewEnviron{argmini!}[7]{% - \ifthenelse{\equal{#1}{1}}{% - \begin{subequations} - #6 - \begin{alignat}{3} - \bodyobjOne{#2}{#3}{arg min}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignat} - \end{subequations} - }% - {% - \begin{subequations} - #6 - \begin{alignat}{4} - \bodyobj{#2}{#3}{arg min}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignat} - \end{subequations} - }% - } - - %MAXIMIZATION ENVIRONMENTS - - \NewEnviron{maxi}[7]{% - \ifthenelse{\equal{#1}{0}}{% - \begin{equation} - #6 - \bodyobjUn{#2}{#3}{maximize}{#7} - \end{equation} - }% - {% - \ifthenelse{\equal{#1}{1}}{% - \begin{equation} - #6 - \begin{alignedat}{3} - \bodyobjOne{#2}{#3}{maximize}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignedat} - \end{equation} - }% - {% - \begin{equation} - #6 - \begin{alignedat}{4} - \bodyobj{#2}{#3}{maximize}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignedat} - \end{equation} - }% - }% - } - - \NewEnviron{argmaxi}[7]{% - \ifthenelse{\equal{#1}{0}}{% - \begin{equation} - #6 - \bodyobjUn{#2}{#3}{arg max}{#7} - \end{equation} - }% - {% - \ifthenelse{\equal{#1}{1}}{% - \begin{equation} - #6 - \begin{alignedat}{3} - \bodyobjOne{#2}{#3}{arg max}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignedat} - \end{equation} - }% - {% - \begin{equation} - #6 - \begin{alignedat}{4} - \bodyobj{#2}{#3}{arg max}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignedat} - \end{equation} - }% - }% + #4 ~~ &\underset{\displaystyle #1}{\mbox{#3}} \quad #2\span\span\span\span } - - \NewEnviron{maxi*}[7]{% - \ifthenelse{\equal{#1}{0}}{% - \begin{equation*} - \bodyobjUn{#2}{#3}{maximize}{#7} - \end{equation*} - }% - {% - \ifthenelse{\equal{#1}{1}}{% - \begin{alignat*}{3} - \bodyobjOne{#2}{#3}{maximize}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignat*} - }% - {% - \begin{alignat*}{5} - \bodyobj{#2}{#3}{maximize}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignat*} - }% - }% - } - - \NewEnviron{argmaxi*}[7]{% - \ifthenelse{\equal{#1}{0}}{% - \begin{equation*} - \bodyobjUn{#2}{#3}{arg max}{#7} - \end{equation*} - }% - {% - \ifthenelse{\equal{#1}{1}}{% - \begin{alignat*}{3} - \bodyobjOne{#2}{#3}{arg max}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignat*} - }% - {% - \begin{alignat*}{4} - \bodyobj{#2}{#3}{arg max}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignat*} - }% - }% - } - - - \NewEnviron{maxi!}[7]{% - \ifthenelse{\equal{#1}{1}}{% - \begin{subequations} - #6 - \begin{alignat}{3} - \bodyobjOne{#2}{#3}{maximize}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignat} - \end{subequations} - }% - {% - \begin{subequations} - #6 - \begin{alignat}{4} - \bodyobj{#2}{#3}{maximize}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignat} - \end{subequations} - }% +} + + +\newcommand{\bodyconst}[2] +{\\ &\text{subject to} \quad  & #2} + +\newcommand{\bodyconstRight}[2] +{\\ &\text{subject to} \quad  & #2} + +\newcommand{\bodyconstBelow}[2] +{\\ &\text{subject to} \span\span \\ + &\quad & #2} + +\newcommand{\bodyconstBelowMult}[2] +{\\ &\text{subject to} \span\span\span\span \nonumber \\ + &\quad & #2} + +\newcommand{\addConstraint}[2]{ + \iftoggle{bodyCon}{ + \bodyconst{#1}{#2} + \togglefalse{bodyCon} + }{ + ,\\&\quad  & #2 + \togglefalse{bodyCon} } - - \NewEnviron{argmaxi!}[7]{% - \ifthenelse{\equal{#1}{1}}{% - \begin{subequations} - #6 - \begin{alignat}{3} - \bodyobjOne{#2}{#3}{arg max}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignat} - \end{subequations} - }% - {% - \begin{subequations} - #6 - \begin{alignat}{4} - \bodyobj{#2}{#3}{arg max}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignat} - \end{subequations} - }% - } \ No newline at end of file +} + +\newcommand{\breakObjectiveOneConstraint}[1]{&&\\} + + + +%MINIMIZATION ENVIRONMENTS + +\NewEnviron{mini}[5][]{% + \ifthenelse{\equal{#1}{1}}{ + \let\bodyconst\bodyconstBelow + }{} + \begin{equation} + #4 + \begin{alignedat}{4} + \bodyobj{#2}{#3}{minimize}{#5} + \BODY + \end{alignedat} + \end{equation} +\toggletrue{bodyCon} +\let\bodyconst\bodyconstRight +} + +\NewEnviron{argmini}[5][]{% + \ifthenelse{\equal{#1}{1}}{ + \let\bodyconst\bodyconstBelow + }{} + \begin{equation} + #4 + \begin{alignedat}{4} + \bodyobj{#2}{#3}{arg min}{#5} + \BODY + \end{alignedat} + \end{equation} +} + +\NewEnviron{mini*}[5][]{% + \ifthenelse{\equal{#1}{1}}{ + \let\bodyconst\bodyconstBelow + }{} + \begin{equation*} + #4 + \begin{alignedat}{4} + \bodyobj{#2}{#3}{minimize}{#5} + \BODY + \end{alignedat} +\end{equation*} +\toggletrue{bodyCon} +\let\bodyconst\bodyconstRight +} + +\NewEnviron{argmini*}[5][]{% + \ifthenelse{\equal{#1}{1}}{ + \let\bodyconst\bodyconstBelow + }{} + \begin{equation*} + #4 + \begin{alignedat}{4} + \bodyobj{#2}{#3}{arg min}{#5} + \BODY + \end{alignedat} + \end{equation*} +} + + +\NewEnviron{mini!}[5][]{% + \ifthenelse{\equal{#1}{1}}{ + \let\bodyconst\bodyconstBelowMult + }{} + \begin{subequations} + #4 + \begin{alignat}{4} + \bodyobj{#2}{#3}{minimize}{#5} + \BODY + \end{alignat} + \end{subequations} + \toggletrue{bodyCon} +\let\bodyconst\bodyconstRight +} + +\NewEnviron{argmini!}[5][]{% + \ifthenelse{\equal{#1}{1}}{ + \let\bodyconst\bodyconstBelowMult + }{} + \begin{subequations} + #4 + \begin{alignat}{4} + \bodyobj{#2}{#3}{arg min}{#5} + \BODY + \end{alignat} + \end{subequations} +} + +%MAXIMIZATION ENVIRONMENTS + +\NewEnviron{maxi}[5][]{% + \ifthenelse{\equal{#1}{1}}{ + \let\bodyconst\bodyconstBelow + }{} + \begin{equation} + #4 + \begin{alignedat}{4} + \bodyobj{#2}{#3}{maximize}{#5} + \BODY + \end{alignedat} + \end{equation} +} + +\NewEnviron{argmaxi}[5][]{% + \ifthenelse{\equal{#1}{1}}{ + \let\bodyconst\bodyconstBelow + }{} + \begin{equation} + #4 + \begin{alignedat}{4} + \bodyobj{#2}{#3}{arg maxi}{#5} + \BODY + \end{alignedat} + \end{equation} +} + +\NewEnviron{maxi*}[5][]{% + \ifthenelse{\equal{#1}{1}}{ + \let\bodyconst\bodyconstBelow + }{} + \begin{equation*} + #4 + \begin{alignedat}{4} + \bodyobj{#2}{#3}{maximize}{#5} + \BODY + \end{alignedat} + \end{equation*} +} + +\NewEnviron{argmaxi*}[5][]{% + \ifthenelse{\equal{#1}{1}}{ + \let\bodyconst\bodyconstBelow + }{} + \begin{equation*} + #4 + \begin{alignedat}{4} + \bodyobj{#2}{#3}{arg maxi}{#5} + \BODY + \end{alignedat} + \end{equation*} +} + + +\NewEnviron{maxi!}[5][]{% + \ifthenelse{\equal{#1}{1}}{ + \let\bodyconst\bodyconstBelowMult + }{} + \begin{subequations} + #4 + \begin{alignat}{4} + \bodyobj{#2}{#3}{maximize}{#5} + \BODY + \end{alignat} + \end{subequations} +} + +\NewEnviron{argmaxi!}[5][]{% + \ifthenelse{\equal{#1}{1}}{ + \let\bodyconst\bodyconstBelowMult + }{} + \begin{subequations} + #4 + \begin{alignat}{4} + \bodyobj{#2}{#3}{arg maxi}{#5} + \BODY + \end{alignat} + \end{subequations} +} \ No newline at end of file -- cgit v1.2.3