optidef icon indicating copy to clipboard operation
optidef copied to clipboard

[Feature Request] \breakConstraint command

Open andreadistefano opened this issue 5 years ago • 7 comments

Hi, first of all thank you for your work on this package, it's really useful! I'm trying to write a really long constraint, and I'd like to split it in 2 lines. I tried using \breakObjective, and it almost works but prints "subject to" again in the next line, which I'd like to avoid. I also tried implementing it by myself, but it's way too hard for a LaTeX noob like me (just started using it last week). Would it be possible for you to do this, please? If you are too busy it's no big deal, thanks anyway!

I attached a screenshot to show you an example of what I'm trying to achieve. screenshot from 2019-02-27 19-49-32

andreadistefano avatar Feb 27 '19 18:02 andreadistefano

When you want to break a constraint, you can just re-use \addConstraint twice (to respectively define the first and second line of the constraint).

Then, you should add the command \nonumber for the line where you don't want the equation number to show up.

But I will leave this issue open to include this functionality within the package.

jeslago avatar Feb 27 '19 20:02 jeslago

Thank you for your reply! It didn't occur to me that I could do that.

Keep up the good work!

andreadistefano avatar Feb 28 '19 09:02 andreadistefano

Thank you for this answer. If I try that I would like to reduce the vertical space between the two constraints but normal commands as \vspace{-0.5pt} don't work. How can I achieved that? Thanks.

AlfaimaSB avatar May 26 '20 16:05 AlfaimaSB

Thank you for your reply! It didn't occur to me that I could do that.

Keep up the good work!

While that works with extra \addConstraint, the problem is that at the end of the first part of the constraint on the first line there appears comma. Is there a way to get rid of that comma? Thanks. Great work anyways!

As an example see:

\begin{maxi!} {\substack{\left{C_{t}^{uc}(i), B_{t+1}^{uc}(i), W_t(i), \right. \ \left. L_t^{uc}(i), {a_{t+1}(i,s)}{s \in S} \right}{t=0}^{\infty}}} {E_0 \sum_{t=0}^{\infty} \beta^t \left{ \psi_t ln(C_t^{uc}(i) - hC_{t-1}^{uc}(i)) - \theta_t \psi \frac{{L_t^{uc}(i)}^{1+\zeta}}{1+\zeta} \right} } {\label{eq:H.1.1}} {} \addConstraint{( 1 + \tau^c ) P_t^c C_t^{uc}(i)+B_{t+1}^{uc}(i) + \int_S q_{t+1}(i,s) a_{t+1}(i,s)}{}{\nonumber} \addConstraint{}{ = (1-\tau^w) W_t(i) L_t^{uc}(i)+R_{t-1} B_t^{uc}(i) + a_t(i)} {\nonumber} \addConstraint{}{ + T_t^{uc} + (1 - \tau^p ) D_t^{uc}(i)} {\nonumber} \addConstraint{L_t^{uc}(i)}{=d(w_t(i))}{} \end{maxi!}

The code above produces the following output. Commas that I am referring to are circled (in the best possible way :) ) on the picture.

Question_marks

giorgi-tsu avatar Jul 19 '20 12:07 giorgi-tsu

This indeed something that has to be corrected in the future. At the moment, the easiest way to solve it is to import the library with the nocomma option:

\usepackage[nocomma ]{ optidef}

But then you need to manually define the commas wherever you need them.

jeslago avatar Jul 20 '20 10:07 jeslago

That works! Thanks. Constraints without commas are also good.

giorgi-tsu avatar Jul 20 '20 11:07 giorgi-tsu

Regarding this issue, I tried the split environment (reference here) but got no luck. It messed up the alignment (to the left side).

image

\addConstraint{\begin{split}
			\PG_i(t)= {}& \sum_{k \in \NPV} I_{ik}\PPV{k}(t) + \sum_{k \in \Nbat} I_{ik}(\Pdisk(t) - \Pchk(t)) \\
		                    & + \sum_{k \in \Ngrid} I_{ik}(\Pbk(t) - \Psk(t)) , \aiN
		\end{split}}{}{}	

ShuhuaGao avatar Jul 27 '21 06:07 ShuhuaGao