1

I'd like to define a new environment called opti that works the same like mini environment but replaces the word 'minimize' into 'optimize'.

1 Answer 1

1

But, you can copy the definition of the mini environment from the package's .sty file to your preamble and modify it accordingly. Note that there are separate definitions for mini*, mini! and minie.

(I don't know whether the abbreviation "opt" makes any sense in this context.)

\documentclass{article}
\usepackage{optidef}

% modification of mini environment
\DeclareDocumentEnvironment{opti}{D||{\defaultProblemFormat} O{\defaultConstraintFormat} D<>{} m m m m}{%
\ifthenelse{\equal{#3}{b}}{%
    \ifthenelse{\equal{#1}{s}}%
    % Short version problem
    {\setFormatShort{opt}{#4}\BaseMiniStar{#2}{#4}{#5}{#7}{opt}{#3}}%
    % Long version problem  
    {\setFormatLong{optimize}{#4}\BaseMiniStar{#2}{#4}{#5}{#7}{optimize}{#3}}%
}{%
    \ifthenelse{\equal{#1}{s}}%
    % Short version problem
    {\setFormatShort{opt}{#4}\BaseMini{#2}{#4}{#5}{#6}{#7}{opt}}%
    % Long version problem  
    {\setFormatLong{optimize}{#4}\BaseMini{#2}{#4}{#5}{#6}{#7}{optimize}}%
}%
}%
{\endBaseMini\toggletrue{bodyCon}}

\begin{document}

\begin{opti}
{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{opti}

\end{document}

enter image description here

5
  • Absolutely beautiful answer. Nov 9, 2021 at 8:14
  • Can you do the same for 'mini!' environment and replace it with 'opti!'? My goal is to label the equations. Nov 11, 2021 at 9:55
  • I found it:\DeclareDocumentEnvironment{opti!}{D||{\defaultProblemFormat} O{\defaultConstraintFormat} D<>{} m m m m}{% \ifthenelse{\equal{#1}{s}}% % Short version problem {\setFormatShort{opt}{#2}\BaseMiniExclam{#2}{#4}{#5}{#6}{#7}{opt}{#3}}% % Long version problem {\setFormatLong{optimize}{#2}\BaseMiniExclam{#2}{#4}{#5}{#6}{#7}{optimize}{#3}}% }{\endBaseMiniExclam\toggletrue{bodyCon}} Nov 11, 2021 at 10:00
  • The definition of the mini! envrionment is right after the defintion of the mini environment in the .sty file. Just copy it from there to your preamble and replace the relevant parts. Nov 11, 2021 at 10:01
  • 1
    Thanks @Jasper Habicht, this is precisely what I did following your previous solution. Nov 11, 2021 at 14:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .