summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/optidef
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2016-06-27 20:38:25 +0000
committerKarl Berry <karl@freefriends.org>2016-06-27 20:38:25 +0000
commit30396a603a178a5cf062125e543547313701f87a (patch)
tree647b0cb57171ec576ce3b50d60c208fe1c17d810 /Master/texmf-dist/doc/latex/optidef
parente747f7b4250571d8894112eb0d47e37ae61928c9 (diff)
optidef (27jun16)
git-svn-id: svn://tug.org/texlive/trunk@41551 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/latex/optidef')
-rw-r--r--Master/texmf-dist/doc/latex/optidef/README.md34
-rw-r--r--Master/texmf-dist/doc/latex/optidef/optidef.pdfbin90198 -> 212361 bytes
-rw-r--r--Master/texmf-dist/doc/latex/optidef/optidef.tex442
3 files changed, 368 insertions, 108 deletions
diff --git a/Master/texmf-dist/doc/latex/optidef/README.md b/Master/texmf-dist/doc/latex/optidef/README.md
index 69c9ae4fc04..272cd586561 100644
--- a/Master/texmf-dist/doc/latex/optidef/README.md
+++ b/Master/texmf-dist/doc/latex/optidef/README.md
@@ -2,15 +2,16 @@
Optidef is a small library that provides a standard set of environments for writing optimization problems.
-## Features:
+
+## Features
The most important features are:
- It automatically aligns the problems in the most convenient way allowing even two different output formats:
* Beginning of the words "minimize/argmin" and "subject to"
* Double format for the location of the constraints: either to the right of subject to aligned with the objective function or below subject to.
- * The $= | > | <$ signs of the constraints.
- * Optionally, the user can add manually a double align character \&\& to align some common constraints feature. A clear example could be the constraints names, e.g. (boundary constraint) alignment with (dynamic constraint), or the index of the constraints, e.g. in the case of having something like $h(x_k,u_k)\leq 0,\quad k=0,\ldots,N$, align the indexes $k=0,\ldots,N$ across constraint lines.
+ * The =, > and < signs of the constraints.
+ * Optionally, an alignment point for some constraints features. An example could be the constraints names, e.g. align (boundary constraint) with (dynamic constraint), or the index of the constraints, e.g. in the case of having something like h(xk,uk) < 0, k=0, ...,N, the third alignment point can align the constraint indexes k=0, ...,N across different constraint lines.
- It provides an easy interface to define optimization problem for three different reference situations:
@@ -25,9 +26,13 @@ The most important features are:
* maximize
* arg mini
* arg maxi
-
-## Syntax:
+## Usage
+
+Import the package by directly adding \usepackage{optidef} to your LaTeX document. Consult the documentation for different examples and syntax usage.
+
+
+## Syntax
The syntax to define an optimization problem is given by:
@@ -35,12 +40,13 @@ The syntax to define an optimization problem is given by:
{Optimization variable}
{Objective function \label{Objective function referece}}
{\label{Global referece of Optimization Problem}}
- {Result of the optimization problem or any expression on the left of the minimize word}
- \addConstraint{LHS Constraint 1}{RHS Constraint 1 \label{Reference Constraint 1}}
- \addConstraint{LHS Constraint 2}{RHS Constraint 2 \label{Reference Constraint 2}}
+ {Result of the optimization problem or any expression on the left
+ of the minimize word}
+ \addConstraint{LHS Constraint 1}{RHS Constraint 1 \label{Reference Constraint 1}}{Extra Info Constraint 1}
+ \addConstraint{LHS Constraint 2}{RHS Constraint 2 \label{Reference Constraint 2}}{Extra Info Constraint 2}
.
.
- \addConstraint{LHS N} {RHSConstraint N \label{Reference Constraint N}}
+ \addConstraint{LHS N}{RHSConstraint N \label{Reference Constraint N}}{Extra Info Constraint N}
\end{mini#}
@@ -57,11 +63,17 @@ After the definition of this parameters, the environment accepts the definition
Finally note that \begin{mini#} can be substituted by \begin{maxi#}, \begin{argmini#} or \begin{argmaxi#}.
-## Contact:
+## Contact for issue reporting or suggestions
E-mail: jesus.lago.garcia@venus.uni-freiburg.de
-## Licensing:
+Github: https://github.com/jeslago/optidef
+
+## Latest stable version: Optidef 1.1
+
+CTAN: https://www.ctan.org/pkg/optidef
+
+## Licensing
Copyright 2016 Jesus Lago Garcia
diff --git a/Master/texmf-dist/doc/latex/optidef/optidef.pdf b/Master/texmf-dist/doc/latex/optidef/optidef.pdf
index 801d5d6faee..8c966d10d7b 100644
--- a/Master/texmf-dist/doc/latex/optidef/optidef.pdf
+++ b/Master/texmf-dist/doc/latex/optidef/optidef.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/optidef/optidef.tex b/Master/texmf-dist/doc/latex/optidef/optidef.tex
index 746870c3cdb..1a18a94e0aa 100644
--- a/Master/texmf-dist/doc/latex/optidef/optidef.tex
+++ b/Master/texmf-dist/doc/latex/optidef/optidef.tex
@@ -1,9 +1,10 @@
\documentclass[]{report}
\usepackage{remreset}
\usepackage{optidef}
+\usepackage{listings}
% Title Page
-\title{\textit{\textbf{Optidef}} \\ A Latex library for optimization problems\\ \textnormal{Version - 1.0}}
+\title{\textit{\textbf{Optidef}} \\ A Latex library for optimization problems\\ \textnormal{Version - 1.1}}
\author{Jesus Lago Garcia}
@@ -20,12 +21,37 @@
This small library provides a standard set of environments for writing minimization problems. The most important features are:
\begin{enumerate}
- \item It automatically aligns the problems in the most convenient way allowing even two different output formats:
+ \item It automatically aligns the problems in the most convenient way allowing different output formats:
\begin{enumerate}
- \item Alignment at the beginning of the words \textit{minimize/argmin} and \textit{subject to}.
+ \item Alignment at the beginning of the words \textit{minimize/argmin} and \textit{subject to}:
+ \begin{mini*}
+ {w}{f(w)+ R(w+6x)}
+ {\label{eq:Ex1}}{}
+ \addConstraint{g(w)}{=0}
+ \end{mini*}
\item Double format for the location of the constraints: either to the right of \textit{subject to} aligned with the objective function or below \textit{subject to}.
- \item Alignment at the $=,~>,~<$ signs of the constraints.
- \item Optionally, the user can add manually a double align character \&\& to align some common constraints feature. A clear example could be the constraints names, e.g. (boundary constraint) alignment with (dynamic constraint), or the index of the constraints, e.g. in the case of having something like $h(x_k,u_k)\leq 0,\quad k=0,\ldots,N$, align the indexes $k=0,\ldots,N$ across constraint lines.
+ \item Optional alignment at the $=,~>,~<$ signs of the constraints.
+ \begin{mini*}
+ {w}{f(w)+ R(w+6x)}
+ {\label{eq:Ex1}}{}
+ \addConstraint{g(w)+h(w)}{=0}
+ \addConstraint{l(w)}{=5w.}
+ \end{mini*}
+ \item Optionally, the user can add a third alignment point on the constraints to set some constraint features. A clear example could be the constraints names:
+ \begin{mini*}
+ {w}{f(w)+ R(w+6x)}
+ {\label{eq:Ex1}}{}
+ \addConstraint{g(w)+h(w)}{=0,}{\text{(Topological Constraint)}}
+ \addConstraint{l(w)}{=5w,\quad}{\text{(Boundary Constraint)}}
+ \end{mini*}
+
+ or the index of the constraints:
+ \begin{mini*}
+ {w,u}{f(w)+ R(w+6x)}
+ {\label{eq:Ex1}}{}
+ \addConstraint{g(w_k)+h(w_k)}{=0,}{k=0,\ldots,N-1}
+ \addConstraint{l(w_k)}{=5u,\quad}{k=0,\ldots,N-1}
+ \end{mini*}
\end{enumerate}
\item It provides an easy interface to define optimization problem for three different reference situations:
@@ -38,7 +64,6 @@ This small library provides a standard set of environments for writing minimizat
\item It also allows a definition of any optimization problem without a limitless number of constraints.
\end{enumerate}
-
\section{Environment types}
There are three basic environments depending on the type of referencing that should be used.
\begin{enumerate}
@@ -62,25 +87,42 @@ There are three basic environments depending on the type of referencing that sho
\end{mini!}
\end{enumerate}
-\section{Environment types}
-There are two basic output formats. By default the constraints are aligned with the objective function and to the right of \textit{subject to}. However the user can choose to locate them below \textit{subject to}.
-\begin{enumerate}
- \item Standard format:
- \begin{mini}
- {w}{f(w)+ R(w+6x)}
- {\label{eq:Ex1}}{}
- \addConstraint{g(w)}{=0}
- \end{mini}
- \item Alternative format:
- \begin{mini}[1]
- {w}{f(w)+ R(w+6x)}
- {\label{eq:Ex1}}{}
- \addConstraint{g(w)}{=0}
- \end{mini}
-\end{enumerate}
-
+\section{Output formats}
+\label{sec:format}
+There are four basic output formats.
+ \begin{enumerate}
+ \item \textbf{Standard format}: by default the constraints are aligned with the objective function, to the right of \textit{subject to} and with a second alignment point at the $=,~\leq,~\geq$:
+ \begin{mini}
+ {w}{f(w)+ R(w+6x)}
+ {\label{eq:Ex1}}{}
+ \addConstraint{g(w)+h(w)}{=0}
+ \addConstraint{t(w)}{=0.}
+ \end{mini}
+ \item \textbf{Alternative 1}: a possible variation is to locate the constraints below \textit{subject to}:
+ \begin{mini}[1]
+ {w}{f(w)+ R(w+6x)}
+ {\label{eq:Ex1}}{}
+ \addConstraint{g(w)+h(w)}{=0}
+ \addConstraint{t(w)}{=0.}
+ \end{mini}
+ \item \textbf{Alternative 2}: a second variation is to copletely remove the second alignment point:
+ \begin{mini}[2]
+ {w}{f(w)+ R(w+6x)}
+ {\label{eq:Ex1}}{}
+ \addConstraint{g(w)+h(w)}{=0}
+ \addConstraint{t(w)}{=0.}
+ \end{mini}
+ \item \textbf{Alternative 3}: a third variation would be the combination of both of them:
+ \begin{mini}[3]
+ {w}{f(w)+ R(w+6x)}
+ {\label{eq:Ex1}}{}
+ \addConstraint{g(w)+h(w)}{=0}
+ \addConstraint{t(w)}{=0.}
+ \end{mini}
+ \end{enumerate}
+
\section{Environment Syntaxes}
-The three environments use the same syntax with the same number of parameters. In particular, considering that LHS stands for Left-hand-side and RHS for Right-hand-side, the basic structure to define a general optimization problem is:
+The three environments use the same syntax with the same number of parameters. In particular, considering that \textit{Const} stands for constraint ,\textit{LHS} stands for Left-hand-side and \textit{RHS} for Right-hand-side, the basic structure to define a general optimization problem is:
\begin{verbatim}
\begin{mini#}[Format]
@@ -90,11 +132,14 @@ The three environments use the same syntax with the same number of parameters. I
{Result of the optimization problem or any expression on
the left of the minimize word}
- \addConstraint{LHS Constraint 1}{RHS Constraint 1 \label{Reference Constraint 1}}
- \addConstraint{LHS Constraint 2}{RHS Constraint 2 \label{Reference Constraint 2}}
+ \addConstraint{LHS Const 1}{RHS Const 1 \label{Reference
+ Const 1}}{Extra Const 1 Info}
+ \addConstraint{LHS Const 2}{RHS Const 2 \label{Reference
+ Constraint 2}}{Extra Const 2 Info}
.
.
- \addConstraint{LHS N}{RHSConstraint N \label{Reference Constraint N}}
+ \addConstraint{LHS N}{RHS Const N \label{Reference
+ Const N}}{Extra Const N Info}
\end{mini#}
\end{verbatim}
@@ -107,7 +152,13 @@ The number of parameters that the environment uses is 6:
\item \verb|Objective function|, e.g. $\|w\|_2$.
\item \verb|\label{Global referece of Optimization Problem}|: it defines the main and general reference for the optimization problem. It is used for the \verb|mini| and \verb|mini!| enviroments. In the \verb|mini*| environment leave it blank, i.e. \{\}.
\item \verb|Result of the optimization problem|: optionally a term expressing the result of the optimization problem, e.g. $J(w^*)~=$.
- \item \verb|Format|: optional parameter if the user want to start the constraints right below \textit{subject to}, instead to the default location on the right of \textit{subject to}.
+ \item \verb|Format|: optional parameter to change the format of the constraints. By default the constraints are located at the right of \textit{subject to} and aligned on the $=,\leq,\geq$ signs. However, as represented in Section \ref{sec:format}), the following variations are possible:
+ \begin{enumerate}
+ \item If Format=1: same alignment as the default format but the constraints appear right below \textit{subject to}. Check Alternative 1 in Section \ref{sec:format}).
+ \item If Format=2: constraints are located on the right of \textit{subject to} but left aligned. Check Alternative 2 in Section \ref{sec:format}).
+ \item If Format=3: constraints are located below \textit{subject to} but left aligned. Check Alternative 3 in Section \ref{sec:format}).
+ \end{enumerate}
+
\end{enumerate}
\noindent Notice that only the first two mandatory parameters (variable and objective) will be really necessary in every definition, nevertheless and for the sake of having homogeneous definitions, we opted for requiring the 4 parameters in every definition and expecting empty parameters definitions, i.e. \{\}, when they are not needed.
@@ -119,12 +170,15 @@ After the definition of this parameters, the environment accepts the definition
\verb|\addConstraint{LHS Constraint k}|
\verb|{RHS Constraint k \label{Reference Constraint k}}|
+
+\verb|{Extra Infor Contraint k}|
~\\
\noindent has to be used, where:
\begin{enumerate}
\item \verb|LHS Constraint|: the left-hand side of the any constraint, e.g. $3w^\top w$.
- \item \verb|RHS Constraint|: the right-hand side of the first constraints including the equal, less and greater signs, e.g. $\leq \|w\|_\infty$, as well as the constraint label.
+ \item \verb|RHS Constraint|: the right-hand side of the first constraints including the equal, less and greater signs, e.g. $\leq \|w\|_\infty$, as well as the constraint label.\textbf{ Keep in mind that this parameter is optional and if not included or leave it blank all the constraints will be aligned to the left (See alternative format 2 and 3 in Section \ref{sec:format}).}
+ \item \verb|Extra Info|: optional parameter to add extra info such as contraints set definition or constraint name. Look Example 8 or the fourth described feature in Section 1.
\end{enumerate}
\subsubsection{Constraints referencing}
@@ -264,19 +318,73 @@ On the other hand:
\addConstraint{h(x)}{=0.}
\end{mini}
+\subsubsection{Example 6 - third format}
-\subsubsection{Example 6 - mini* + extra constraint alignment}
-Adding the fourth optional alignment to add constraint names:
+\noindent If including a 2 as optional parameter, the constraint will appear to the right of \textit{subject to} but a single alignment point.
\begin{verbatim}
-\begin{mini*}
+\begin{mini}[2]
+{w}{f(w)+ R(w+6x)}
+{\label{eq:Example1}}
+{}
+
+\addConstraint{g(w)}{=0}
+\addConstraint{n(w)}{= 6}
+\addConstraint{L(w)+r(x)}{=Kw+p}
+\addConstraint{h(x)}{=0.}
+\end{mini}
+\end{verbatim}
+
+\noindent outputs:
+
+\begin{mini}[2]
+ {w}{f(w)+ R(w+6x)}
+ {\label{eq:Ex1}}{}
+ \addConstraint{g(w)}{=0}
+ \addConstraint{n(w)}{= 6}
+ \addConstraint{L(w)+r(x)}{=Kw+p}
+ \addConstraint{h(x)}{=0.}
+\end{mini}
+
+\subsubsection{Example 7 - fourth format}
+
+\noindent If including a 3 as optional parameter, the first constraint will appear aligned to the left right below \textit{subject to} and with a single alignment point.
+
+\begin{verbatim}
+\begin{mini}[3]
{w}{f(w)+ R(w+6x)}
-{}{}
+{\label{eq:Example1}}
+{}
-\addConstraint{g(w)}{=0, \quad && \text{(Dynamic constraint)}}
-\addConstraint{n(w)}{= 6, \quad && \text{(Boundary constraint)}}
-\addConstraint{L(w)+r(x)}{=Kw+p, \quad && \text{(Random constraint)}}
-\addConstraint{h(x)}{=0.\quad && \text{(Path constraint)}}
+\addConstraint{g(w)}{=0}
+\addConstraint{n(w)}{= 6}
+\addConstraint{L(w)+r(x)}{=Kw+p}
+\addConstraint{h(x)}{=0.}
+\end{mini}
+\end{verbatim}
+
+\noindent outputs:
+
+\begin{mini}[3]
+ {w}{f(w)+ R(w+6x)}
+ {\label{eq:Ex1}}{}
+ \addConstraint{g(w)}{=0}
+ \addConstraint{n(w)}{= 6}
+ \addConstraint{L(w)+r(x)}{=Kw+p}
+ \addConstraint{h(x)}{=0.}
+\end{mini}
+
+\subsubsection{Example 8 - mini* + extra constraint alignment}
+Adding the fourth optional alignment to add constraint names:
+
+\begin{verbatim}
+\begin{mini*}
+ {w}{f(w)+ R(w+6x)}
+ {}{}
+ \addConstraint{g(w)}{=0,}{ \quad \text{(Dynamic constraint)}}
+ \addConstraint{n(w)}{= 6,}{ \quad \text{(Boundary constraint)}}
+ \addConstraint{L(w)+r(x)}{=Kw+p,}{ \quad \text{(Random constraint)}}
+ \addConstraint{h(x)}{=0,}{ \quad \text{(Path constraint).}}
\end{mini*}
\end{verbatim}
@@ -284,10 +392,10 @@ Adding the fourth optional alignment to add constraint names:
\begin{mini*}
{w}{f(w)+ R(w+6x)}
{}{}
- \addConstraint{g(w)}{=0, \quad && \text{(Dynamic constraint)}}
- \addConstraint{n(w)}{= 6, \quad && \text{(Boundary constraint)}}
- \addConstraint{L(w)+r(x)}{=Kw+p, \quad && \text{(Random constraint)}}
- \addConstraint{h(x)}{=0. \quad && \text{(Path constraint).}}
+ \addConstraint{g(w)}{=0,}{ \quad \text{(Dynamic constraint)}}
+ \addConstraint{n(w)}{= 6,}{ \quad \text{(Boundary constraint)}}
+ \addConstraint{L(w)+r(x)}{=Kw+p,}{ \quad \text{(Random constraint)}}
+ \addConstraint{h(x)}{=0,}{ \quad \text{(Path constraint).}}
\end{mini*}
@@ -407,59 +515,131 @@ One current limitation is that the size of the optimization variables must be sm
\section{Code definition}
\begin{verbatim}
-% optidef - Version 08/06/2016
-%
+%optidef - Version 1.1
%Copyright 2016 J. Lago Garcia
-%
-%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, under the supervision of Prof. Dr. Moritz Diehl and Prof. Dr. Sebastien Gross.
-%
+
+%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, under the supervision of Prof. Dr. Moritz Diehl
+%and Prof. Dr. Sebastien Gross.
+
%E-mail: jesus.lago.garcia@venus.uni-freiburg.de
-%
+
%This work consists of the file optidef.sty.
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{optidef}[2016/06/06 Package for defining optimization problems]
+\ProvidesPackage{optidef}[2016/06/26 - version=1.1, Package for defining optimization problems]
\RequirePackage{environ}
\RequirePackage{mathtools}
\RequirePackage{xifthen}
\RequirePackage{etoolbox}
+\RequirePackage{xparse}
\newtoggle{bodyCon}
\toggletrue{bodyCon}
% Input minimization evironments
% Macros for objective definition, constraint definition and extra constraint definition
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% % -------- DEFINITION COMMAND OBJECTIVE -----------
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\bodyobj}[4]
{
\ifthenelse{\isempty{#4}}
{
-&\underset{\displaystyle #1}{\mbox{#3}} \quad #2\span\span\span\span
+&\underset{\displaystyle #1}{\mathrm{#3}} \quad #2\span\span\span\span
}
{
-#4 ~~ &\underset{\displaystyle #1}{\mbox{#3}} \quad #2\span\span\span\span
+#4 ~~ &\underset{\displaystyle #1}{\mathrm{#3}} \quad #2\span\span\span\span
+}
+}
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% -------- DEFINITION DIFFERENT TYPE OF BODY CONSTRAINTS --------%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\DeclareDocumentCommand{\bodyconst}{m G{}}
+{ \ifthenelse{\equal{#2}{}}{
+\\ &\mathrm{subject~to} \quad &&#1 #2
+}{
+\\ &\mathrm{subject~to} \quad &#1 & #2
+}
}
+
+% Standard version
+\DeclareDocumentCommand{\bodyconstRight}{m G{}}
+{ \ifthenelse{\equal{#2}{}}{
+\\ &\mathrm{subject~to} \quad &&#1 #2
+}{
+\\ &\mathrm{subject~to} \quad &#1 & #2
+}
+}
+
+% Single alignment point
+\DeclareDocumentCommand{\bodyconstOneAlign}{m G{}}
+{
+\\ &\mathrm{subject~to} \quad &&#1 #2
+}
+
+% Contraints below subject to and with a single alignment point
+\DeclareDocumentCommand{\bodyconstOneAlignBelow}{m G{}}
+{
+\\ &\mathrm{subject~to} \span\span \\
+&&&#1 #2
}
+% Contraints below subject to
+\DeclareDocumentCommand{\bodyconstBelow}{m G{}}
+{ \ifthenelse{\equal{#2}{}}{
+\\ &\mathrm{subject~to} \span\span\span\span \\
+&&&#1 #2
+}{
+\\ &\mathrm{subject~to} \span\span\span\span \\
+&&#1 & #2
+}
+}
-\newcommand{\bodyconst}[2]
-{\\ &\text{subject to} \quad &#1 & #2}
+% Contraints below subject to for the case of having multiple equations
+\DeclareDocumentCommand{\bodyconstBelowMult}{m G{}}
+{ \ifthenelse{\equal{#2}{}}{
+\\ &\mathrm{subject~to} \span\span\span\span \nonumber \\
+&&&#1 #2
+}{
+\\ &\mathrm{subject~to} \span\span\span\span \nonumber \\
+&&#1 & #2
+}
+}
-\newcommand{\bodyconstRight}[2]
-{\\ &\text{subject to} \quad &#1 & #2}
+% Contraints below subject to and with a single alignment point for the case of having several equations
+\DeclareDocumentCommand{\bodyconstOneAlignBelowMult}{m G{}}
+{
+\\ &\mathrm{subject~to} \span\span\span\span \nonumber \\
+&&&#1 #2
+}
-\newcommand{\bodyconstBelow}[2]
-{\\ &\text{subject to} \span\span \\
-&\quad&#1 & #2}
-\newcommand{\bodyconstBelowMult}[2]
-{\\ &\text{subject to} \span\span\span\span \nonumber \\
-&\quad&#1 & #2}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% -------- DEFINITION DIFFERENT TYPE OF ADDING CONSTRAINTS --- --%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\newcommand{\addConstraint}[2]{
+\DeclareDocumentCommand{\addConstraint}{m G{} G{}}{
+\ifthenelse{\equal{#2}{}}{
+\iftoggle{bodyCon}{
+\bodyconst{#1}
+\togglefalse{bodyCon}
+}{
+,\\&\quad &&#1 #2
+\togglefalse{bodyCon}
+}
+}{
\iftoggle{bodyCon}{
\bodyconst{#1}{#2}
\togglefalse{bodyCon}
@@ -468,6 +648,84 @@ One current limitation is that the size of the optimization variables must be sm
\togglefalse{bodyCon}
}
}
+}
+
+% Standard version of adding constraints
+\DeclareDocumentCommand{\standardAddConstraint}{m G{} G{}}{
+\iftoggle{bodyCon}{
+\bodyconstRight{#1}{#2}
+\togglefalse{bodyCon}
+}{
+\ifthenelse{\equal{#2}{}}{
+,\\&\quad &&#1 #2
+}{
+,\\&\quad &#1 & #2
+}
+\togglefalse{bodyCon}
+}
+}
+
+% Adding constraints below subject to
+\DeclareDocumentCommand{\BelowAddConstraint}{m G{} G{}}{
+\iftoggle{bodyCon}{
+\bodyconstBelow{#1}{#2}
+\togglefalse{bodyCon}
+}{
+\ifthenelse{\equal{#2}{}}{
+,\\&&&#1 #2
+}{
+,\\ &&#1 &#2}
+\togglefalse{bodyCon}
+}
+}
+
+% Adding constraints for a single alignment point
+\DeclareDocumentCommand{\oneAlignAddConstraint}{m G{} G{}}{
+\iftoggle{bodyCon}{
+\bodyconstOneAlign{#1}{#2}
+\togglefalse{bodyCon}
+}{
+,\\&\quad &&#1 #2
+\togglefalse{bodyCon}
+}
+}
+
+% Adding constraints for a single alignment point and with the constraints below
+\DeclareDocumentCommand{\oneAlignBelowAddConstraint}{m G{} G{}}{
+\iftoggle{bodyCon}{
+\bodyconstOneAlignBelow{#1}{#2}
+\togglefalse{bodyCon}
+}{
+,\\& &&#1 #2
+\togglefalse{bodyCon}
+}
+}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% ------------- SELECTING TYPE OF FORMAT -----------%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\newcommand{\selectConstraint}[1]{
+\ifthenelse{\equal{#1}{1}}{
+\let\addConstraint\BelowAddConstraint
+}{
+\ifthenelse{\equal{#1}{2}}{
+\let\addConstraint\oneAlignAddConstraint
+}{
+\ifthenelse{\equal{#1}{3}}{
+\let\addConstraint\oneAlignBelowAddConstraint
+}{}
+}
+}
+}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% ------------- SETTING DEFAULT FORMAT -------------%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\newcommand{\setStandardMini}{
+\toggletrue{bodyCon}
+\let\addConstraint\standardAddConstraint
+}
+
\newcommand{\breakObjectiveOneConstraint}[1]{&&&#1\\}
@@ -476,9 +734,7 @@ One current limitation is that the size of the optimization variables must be sm
%MINIMIZATION ENVIRONMENTS
\NewEnviron{mini}[5][]{%
-\ifthenelse{\equal{#1}{1}}{
-\let\bodyconst\bodyconstBelow
-}{}
+\selectConstraint{#1}
\begin{equation}
#4
\begin{alignedat}{4}
@@ -486,14 +742,11 @@ One current limitation is that the size of the optimization variables must be sm
\BODY
\end{alignedat}
\end{equation}
-\toggletrue{bodyCon}
-\let\bodyconst\bodyconstRight
+\setStandardMini
}
\NewEnviron{argmini}[5][]{%
-\ifthenelse{\equal{#1}{1}}{
-\let\bodyconst\bodyconstBelow
-}{}
+\selectConstraint{#1}
\begin{equation}
#4
\begin{alignedat}{4}
@@ -501,12 +754,11 @@ One current limitation is that the size of the optimization variables must be sm
\BODY
\end{alignedat}
\end{equation}
+\setStandardMini
}
\NewEnviron{mini*}[5][]{%
-\ifthenelse{\equal{#1}{1}}{
-\let\bodyconst\bodyconstBelow
-}{}
+\selectConstraint{#1}
\begin{equation*}
#4
\begin{alignedat}{4}
@@ -514,14 +766,11 @@ One current limitation is that the size of the optimization variables must be sm
\BODY
\end{alignedat}
\end{equation*}
-\toggletrue{bodyCon}
-\let\bodyconst\bodyconstRight
+\setStandardMini
}
\NewEnviron{argmini*}[5][]{%
-\ifthenelse{\equal{#1}{1}}{
-\let\bodyconst\bodyconstBelow
-}{}
+\selectConstraint{#1}
\begin{equation*}
#4
\begin{alignedat}{4}
@@ -529,6 +778,7 @@ One current limitation is that the size of the optimization variables must be sm
\BODY
\end{alignedat}
\end{equation*}
+\setStandardMini
}
@@ -543,8 +793,7 @@ One current limitation is that the size of the optimization variables must be sm
\BODY
\end{alignat}
\end{subequations}
-\toggletrue{bodyCon}
-\let\bodyconst\bodyconstRight
+\setStandardMini
}
\NewEnviron{argmini!}[5][]{%
@@ -557,15 +806,14 @@ One current limitation is that the size of the optimization variables must be sm
\bodyobj{#2}{#3}{arg min}{#5}
\BODY
\end{alignat}
-\end{subequations}
+\end{subequations}
+\setStandardMini
}
%MAXIMIZATION ENVIRONMENTS
\NewEnviron{maxi}[5][]{%
-\ifthenelse{\equal{#1}{1}}{
-\let\bodyconst\bodyconstBelow
-}{}
+\selectConstraint{#1}
\begin{equation}
#4
\begin{alignedat}{4}
@@ -573,12 +821,11 @@ One current limitation is that the size of the optimization variables must be sm
\BODY
\end{alignedat}
\end{equation}
+\setStandardMini
}
\NewEnviron{argmaxi}[5][]{%
-\ifthenelse{\equal{#1}{1}}{
-\let\bodyconst\bodyconstBelow
-}{}
+\selectConstraint{#1}
\begin{equation}
#4
\begin{alignedat}{4}
@@ -586,12 +833,11 @@ One current limitation is that the size of the optimization variables must be sm
\BODY
\end{alignedat}
\end{equation}
+\setStandardMini
}
\NewEnviron{maxi*}[5][]{%
-\ifthenelse{\equal{#1}{1}}{
-\let\bodyconst\bodyconstBelow
-}{}
+\selectConstraint{#1}
\begin{equation*}
#4
\begin{alignedat}{4}
@@ -599,12 +845,11 @@ One current limitation is that the size of the optimization variables must be sm
\BODY
\end{alignedat}
\end{equation*}
+\setStandardMini
}
\NewEnviron{argmaxi*}[5][]{%
-\ifthenelse{\equal{#1}{1}}{
-\let\bodyconst\bodyconstBelow
-}{}
+\selectConstraint{#1}
\begin{equation*}
#4
\begin{alignedat}{4}
@@ -612,6 +857,7 @@ One current limitation is that the size of the optimization variables must be sm
\BODY
\end{alignedat}
\end{equation*}
+\setStandardMini
}
@@ -625,7 +871,8 @@ One current limitation is that the size of the optimization variables must be sm
\bodyobj{#2}{#3}{maximize}{#5}
\BODY
\end{alignat}
-\end{subequations}
+\end{subequations}
+\setStandardMini
}
\NewEnviron{argmaxi!}[5][]{%
@@ -638,7 +885,8 @@ One current limitation is that the size of the optimization variables must be sm
\bodyobj{#2}{#3}{arg maxi}{#5}
\BODY
\end{alignat}
-\end{subequations}
+\end{subequations}
+\setStandardMini
}
\end{verbatim}