diff options
author | Karl Berry <karl@freefriends.org> | 2017-11-29 22:08:27 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-11-29 22:08:27 +0000 |
commit | 41621b0b484649afdce10d4a48951b78320c6728 (patch) | |
tree | 668f3e839ab29b9c51ebd5cc83b77dcbfac613d2 /Master/texmf-dist/tex/latex/optidef/optidef.sty | |
parent | c10b224e35e41cba021f9ba70ab1fa1fce07b692 (diff) |
optidef (29nov17)
git-svn-id: svn://tug.org/texlive/trunk@45945 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/optidef/optidef.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/optidef/optidef.sty | 84 |
1 files changed, 48 insertions, 36 deletions
diff --git a/Master/texmf-dist/tex/latex/optidef/optidef.sty b/Master/texmf-dist/tex/latex/optidef/optidef.sty index 2e07f604dc1..d01c65beb36 100644 --- a/Master/texmf-dist/tex/latex/optidef/optidef.sty +++ b/Master/texmf-dist/tex/latex/optidef/optidef.sty @@ -1,18 +1,18 @@ -% optidef - Version 2.5 +% optidef - Version 2.6 % -%Copyright 2017 J. Lago Garcia +%Copyright 2017 Jesus Lago % %This work may be distributed and/or modified under the conditions of the LaTeX Project Public License, either version 1.3 of this license or (at your option) any later version. %The latest version of this license is in http://www.latex-project.org/lppl.txt and version 1.3 or later is part of all distributions of LaTeX version 2005/12/01 or later. % -%This work has the LPPL maintenance status 'maintained'. The Current Maintainer of this work is J. Lago Garcia. +%This work has the LPPL maintenance status 'maintained'. The Current Maintainer of this work is J. Lago . % %E-mail: J.LagoGarcia@tudelft.nl % %This work consists of the file optidef.sty. \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{optidef}[2017/06/21 - version=2.5, Package for defining optimization problems] +\ProvidesPackage{optidef}[2017/11/29 - version=2.6, Package for defining optimization problems] \RequirePackage{environ} \RequirePackage{mathtools} @@ -42,6 +42,11 @@ \ProcessOptions\relax +% This command is required to avoid breakdown of the \equal fragile command. In particular, before I had \equal{#2}{} tp check if argumetn #2 was empty. However, if the argument was a bmatrix object the command was breaking. Now this command is robust. +\newcommand{\equalsNothing}[3]{% + \ifthenelse{\equal{\unexpanded{#1}}{}}{#2}{#3}% +} + %%%%%%%%%%%%%%%%%%%%%%% % VARIABLES DEFINITION %%%%%%%%%%%%%%%%%%%%%%% @@ -117,7 +122,7 @@ % Main command. Dynamically redefined at every new problem definition. \DeclareDocumentCommand{\bodyconst}{m G{}} -{ \ifthenelse{\equal{#2}{}}{ +{ \equalsNothing{#2}{ \\ &\underset{\displaystyle \phantom{\localOptimalVariable}}{\mathrm{subject~to}} \quad & #2 }{ \\ &\underset{\displaystyle \phantom{\localOptimalVariable}}{\mathrm{subject~to}} \quad  & #2 @@ -140,15 +145,15 @@ {%%% \bodySubjectToDefinition %## Set the first constraint according to the format used for "subject to" -\ifthenelse{\equal{#3}{}}{%% - \ifthenelse{\equal{#2}{}}{% +\equalsNothing{#3}{%% + \equalsNothing{#2}{% \\ & \bodySubjectTo \quad & #2 }{% \\ &\bodySubjectTo \quad  & #2 }% \togglefalse{previousThird} }{%% - \ifthenelse{\equal{#2}{}}{% + \equalsNothing{#2}{% \\ &\bodySubjectTo \quad & #2 & }{% \\ &\bodySubjectTo \quad  & #2 & @@ -163,7 +168,7 @@ { \bodySubjectToDefinition %## Set the first constraint according to the format used for "subject to" - \ifthenelse{\equal{#3}{}}{ + \equalsNothing{#3}{ \\ &\bodySubjectTo\quad & #2 \togglefalse{previousThird} }{ \\ &\bodySubjectTo\quad & #2 & @@ -176,7 +181,7 @@ { \bodySubjectToDefinition %## Set the first constraint according to the format used for "subject to" - \ifthenelse{\equal{#3}{}}{ + \equalsNothing{#3}{ \\ &\bodySubjectTo \span\span\span\span \\ && #2 \togglefalse{previousThird} }{ @@ -191,8 +196,8 @@ { \bodySubjectToDefinition %## Set the first constraint according to the format used for "subject to" - \ifthenelse{\equal{#3}{}}{ - \ifthenelse{\equal{#2}{}}{ + \equalsNothing{#3}{ + \equalsNothing{#2}{ \\ &\bodySubjectTo\span\span\span\span \\ && #2 }{ @@ -201,7 +206,7 @@ } \togglefalse{previousThird} }{ - \ifthenelse{\equal{#2}{}}{ + \equalsNothing{#2}{ \\ &\bodySubjectTo \span\span\span\span \\ && #2 & }{ @@ -217,8 +222,8 @@ { \bodySubjectToDefinition %## Set the first constraint according to the format used for "subject to" - \ifthenelse{\equal{#3}{}}{ - \ifthenelse{\equal{#2}{}}{ + \equalsNothing{#3}{ + \equalsNothing{#2}{ \\ &\bodySubjectTo\span\span\span\span \nonumber \\ && #2 }{ @@ -227,7 +232,7 @@ } \togglefalse{previousThird} }{ - \ifthenelse{\equal{#2}{}}{ + \equalsNothing{#2}{ \\ &\bodySubjectTo\span\span\span\span \nonumber \\ && #2 & }{ @@ -243,7 +248,7 @@ { \bodySubjectToDefinition %## Set the first constraint according to the format used for "subject to" - \ifthenelse{\equal{#3}{}}{ + \equalsNothing{#3}{ \\ &\bodySubjectTo\span\span\span\span \nonumber \\ && #2 \togglefalse{previousThird} }{ @@ -262,9 +267,9 @@ % Main command. Dynamically redefined at every problem definiton. \DeclareDocumentCommand{\addConstraint}{m G{} G{}}{ % "If clause" selecting whether a third parameter (#3) defining extra constraint information is used -\ifthenelse{\equal{#3}{}}{ +\equalsNothing{#3}{ % Second "If clause" selecting whether two or 1 elements for the constraints are used - \ifthenelse{\equal{#2}{}}{ + \equalsNothing{#2}{ \iftoggle{bodyCon}{ \bodyconst{#1} \togglefalse{bodyCon} @@ -287,7 +292,7 @@ \bodyconst{#1}{#2}{#3} \togglefalse{bodyCon} }{ - \ifthenelse{\equal{#2}{}}{ + \equalsNothing{#2}{ \defaultOCPConstraint\\&\quad & #2 && #3 }{ \defaultOCPConstraint\\&\quad  & #2 && #3 @@ -299,25 +304,31 @@ } % Standard version of adding constraints +% The toggle previousThird indicates if the previous constraint had three arguments or two. According to that it adjust the required spans at the end of the previous contraint. It is needed because the line jump after a constraint it is done at the beginning of the next constraint, not after the constraint itself. That avoid the last jump of the last constraint. +% The toggle bodyCon indicate that it is the first contraint. The first contraint is different that the rest because it contains "subject to" +% The commands \equalsNothing checks if the optional arguments exists \DeclareDocumentCommand{\standardAddConstraint}{m G{} G{}}{ \iftoggle{previousThird} - {\renewcommand{\spanit}{}} - {\renewcommand{\spanit}{\span\span}} + { + \renewcommand{\spanit}{} + }{ + \renewcommand{\spanit}{\span\span} + } \iftoggle{bodyCon}{ \bodyconstRight{#1}{#2}{#3} \togglefalse{bodyCon} }{ - \ifthenelse{\equal{#2}{}}{ - \ifthenelse{\equal{#3}{}}{ - \defaultOCPConstraint\spanit\\&\quad & #2 + \equalsNothing{#2}{ + \equalsNothing{#3}{ + \defaultOCPConstraint\spanit\\&\quad & #2 \togglefalse{previousThird} }{ \defaultOCPConstraint\spanit\\&\quad & #2 && #3 \toggletrue{previousThird} } }{ - \ifthenelse{\equal{#3}{}}{ - \defaultOCPConstraint\spanit\\&\quad  & #2 + \equalsNothing{#3}{ + \defaultOCPConstraint\spanit\\&\quad  & #2 \togglefalse{previousThird} }{ \defaultOCPConstraint\spanit\\&\quad  & #2 && #3 @@ -328,21 +339,22 @@ } } + % Adding constraints below subject to \DeclareDocumentCommand{\BelowAddConstraint}{m G{} G{}}{ \iftoggle{bodyCon}{ \bodyconstBelow{#1}{#2}{#3} \togglefalse{bodyCon} }{ - \ifthenelse{\equal{#2}{}}{ - \ifthenelse{\equal{#3}{}}{ + \equalsNothing{#2}{ + \equalsNothing{#3}{ \defaultOCPConstraint\spanit\\&& #2 \togglefalse{previousThird} }{ \defaultOCPConstraint\spanit\\&& #2 && #3 \toggletrue{previousThird} } }{ - \ifthenelse{\equal{#3}{}}{ + \equalsNothing{#3}{ \defaultOCPConstraint\spanit\\ &  \togglefalse{previousThird} }{ \defaultOCPConstraint\spanit\\ &  && #3 @@ -359,7 +371,7 @@ \bodyconstOneAlign{#1}{#2}{#3} \togglefalse{bodyCon} }{ - \ifthenelse{\equal{#3}{}}{ + \equalsNothing{#3}{ \defaultOCPConstraint\spanit\\&\quad & #2 \togglefalse{previousThird} }{ \defaultOCPConstraint\spanit\\&\quad & #2 && #3 @@ -375,7 +387,7 @@ \bodyconstOneAlignBelow{#1}{#2}{#3} \togglefalse{bodyCon} }{ - \ifthenelse{\equal{#3}{}}{ + \equalsNothing{#3}{ \defaultOCPConstraint\spanit\\& & #2\togglefalse{previousThird} }{ \defaultOCPConstraint\spanit\\& & #2 && #3 @@ -391,15 +403,15 @@ \bodyconstBelowMult{#1}{#2}{#3} \togglefalse{bodyCon} }{ - \ifthenelse{\equal{#3}{}}{ - \ifthenelse{\equal{#2}{}}{ + \equalsNothing{#3}{ + \equalsNothing{#2}{ \defaultOCPConstraint\spanit\\&& #2 }{ \defaultOCPConstraint\spanit\\ &  } \togglefalse{previousThird} }{ - \ifthenelse{\equal{#2}{}}{ + \equalsNothing{#2}{ \defaultOCPConstraint\spanit\\&& #2 && #3 }{ \defaultOCPConstraint\spanit\\ & && #3} @@ -415,7 +427,7 @@ \bodyconstOneAlignBelowMult{#1}{#2}{#3} \togglefalse{bodyCon} }{ - \ifthenelse{\equal{#3}{}}{ + \equalsNothing{#3}{ \defaultOCPConstraint\spanit\\& & #2 \togglefalse{previousThird} }{ \defaultOCPConstraint\spanit\\& & #2 && #3 |