0

I have tried to follow optidef.tex to make the constraint names aligned. Here is the code:

\begin{mini*}|s|
    {\substack{\mathbf{x},\mathbf{u}}}{J = \phi\left(\mathbf{x}\left(t_f\right),t_f\right) + \int_{t_0}^{t_f}\mathcal{L}\left(\mathbf{x},\mathbf{u},t\right)dt}{}{}
            \addConstraint{\dot{\mathbf{x}} =}{\mathbf{f}\left(\mathbf{x},\mathbf{u},t\right)}
            \addConstraint{\mathbf{x}\left(0\right)}{= \mathbf{x}_0,}{\quad\text{(Initial condition)}}
            \addConstraint{\Psi\left(\mathbf{x}_f,t_f\right) }{= 0,} {\quad\text{(Terminal constraints)}}
    \end{mini*}

And here is the corresponding output that is circled: enter image description here

Can some explain what is going on? I am writing this out in TeXpad.

  • You just need to move the position of the = sign in \addConstraint{\dot{\mathbf{x}} =}{\mathbf{f}\left(\mathbf{x},\mathbf{u},t\right)} to become \addConstraint{\dot{\mathbf{x}}}{ =\mathbf{f}\left(\mathbf{x},\mathbf{u},t\right)}. – Schrödinger's cat Feb 11 at 6:57
  • I tried, but it didn’t work – Superman Feb 11 at 7:39
  • Do the provided answers solve your problem? If yes, then consider upvoting and accepting one of the answers. – Dr. Manuel Kuehner Mar 8 at 8:39
2

I'll be happy to remove this post. According to what I find, you just need to move the position of the = sign in

\addConstraint{\dot{\mathbf{x}} =}{\mathbf{f}\left(\mathbf{x},\mathbf{u},t\right)}

to become

\addConstraint{\dot{\mathbf{x}}}{ =\mathbf{f}\left(\mathbf{x},\mathbf{u},t\right)}

Full example:

\documentclass{article}
\usepackage{optidef}
\begin{document}
\begin{mini*}|s|
    {\substack{\mathbf{x},\mathbf{u}}}{J = \phi\left(\mathbf{x}\left(t_f\right),t_f\right) + \int_{t_0}^{t_f}\mathcal{L}\left(\mathbf{x},\mathbf{u},t\right)dt}{}{}
            \addConstraint{\dot{\mathbf{x}} }{=\mathbf{f}\left(\mathbf{x},\mathbf{u},t\right)}
            \addConstraint{\mathbf{x}\left(0\right)}{= \mathbf{x}_0,}{\quad\text{(Initial condition)}}
            \addConstraint{\Psi\left(\mathbf{x}_f,t_f\right) }{= 0,} {\quad\text{(Terminal constraints)}}
\end{mini*}
\end{document}

enter image description here

There are many things one could improve like the \substack or the differential d.

|improve this answer|||||
  • +1. Another way in which the code could be improved is by omitting all \left and \right auto-sizing instructions, the more so as these instructions don't do anything except insert undesirable horizontal whitespace. – Mico Feb 11 at 9:20
  • 1
    I have a strong feeling that Texpad is being very glitchy. What software did you use, Schrödinger’s cat? – Superman Feb 11 at 16:55
  • @Superman pdflatex. – Schrödinger's cat Feb 11 at 16:56
  • 1
    @Mico Sure. I was just writing this because I was told my suggestion would not work. (If I was you I would make the differential d's upright in your answer. This seems to be some physics problem. Even though there are some claims that some mathematicians would not use upright upright d's (I know and interact with many, and anyone consciously typing uses an upright d), in physics it is unambiguous. – Schrödinger's cat Feb 11 at 16:59
  • 1
    @Mico I had upvoted it already... – Schrödinger's cat Feb 11 at 21:46
2

Just for reference, here's a solution which does not employ the optidef package. Instead, it employs 1 align* environment (for the 4 "outer" blocks) and 1 aligned environment (for the group of 3 "inner" blocks which, together, make up the final "outer" block). align* and aligned are both provided by the amsmath package.

enter image description here

\documentclass{article}
\usepackage{amsmath,amssymb,bm}
\newcommand{\diff}{\mathop{}\!\mathrm{d}} % see https://tex.stackexchange.com/a/385862/5001
\newcommand\tf{t\mkern-1.5mu_f} % snug up the subscript-f to the t

\begin{document}
\begin{align*}
&\text{PM: } \textstyle 
  J=\phi(\mathbf{x}(\tf),\tf)
  +\int_{t_0}^{\tf}\!\mathcal{L}(\mathbf{x},\mathbf{u},t)\diff t \\
&\text{General Problem: } \textstyle 
  \min J=\phi(\mathbf{x}(\tf))
  +\int_{t_0}^{\tf}\! \mathcal{L}(\mathbf{x},\mathbf{u},t)\diff t\\
&{\min_{\mathbf{x},\mathbf{u}}} \quad
  J=\phi(\mathbf{x}(\tf),\tf)
  +\int_{t_0}^{\tf} \!\! \mathcal{L}(\mathbf{x}, \mathbf{u},t)\diff t \\
&\text{s.t.} \quad
  \begin{aligned}[t]
  \dot{\mathbf{x}} &= \mathbf{f}(\mathbf{x},\mathbf{u},t) \\
  \mathbf{x}(0) &= x_0 \qquad\text{(Initial condition)}\\
  \bm{\Psi}(\mathbf{x}_f,\tf) &= 0_{\phantom{0}} \qquad{\text{(Terminal constraint)}}
  \end{aligned}
\end{align*}

\end{document} 
|improve this answer|||||
1

I cannot reproduce the output you get with your code.

Besides moving the = to the second argument to \AddConstraint, as suggested in another answer, I propose a different setting, with constraints left aligned, which seems better to me.

Also I removed all \left/\right pairs, which do nothing besides adding unwanted space. A \, before dt is necessary, instead. Whether you want an upright “d” or not is your choice: conform to what is the usage in your field (or to your personal preference).

\documentclass{article}
\usepackage{amsmath,optidef}

\begin{document}

\subsection*{Original}

\begin{mini*}|s|
    {\substack{\mathbf{x},\mathbf{u}}}{J = \phi\left(\mathbf{x}\left(t_f\right),t_f\right) + \int_{t_0}^{t_f}\mathcal{L}\left(\mathbf{x},\mathbf{u},t\right)dt}{}{}
            \addConstraint{\dot{\mathbf{x}} =}{\mathbf{f}\left(\mathbf{x},\mathbf{u},t\right)}
            \addConstraint{\mathbf{x}\left(0\right)}{= \mathbf{x}_0,}{\quad\text{(Initial condition)}}
            \addConstraint{\Psi\left(\mathbf{x}_f,t_f\right) }{= 0,} {\quad\text{(Terminal constraints)}}
    \end{mini*}

\subsection*{Left alignment}

\begin{mini*}|s|
  {\scriptstyle\mathbf{x},\mathbf{u}}
  {J = \phi(\mathbf{x}(t_f),t_f) + \int_{t_0}^{t_f}\mathcal{L}(\mathbf{x},\mathbf{u},t)\,dt}{}{}
\addConstraint{}{\dot{\mathbf{x}}=\mathbf{f}(\mathbf{x},\mathbf{u},t)}{}
\addConstraint{}{\mathbf{x}(0)= \mathbf{x}_0,}{\quad\text{(Initial condition)}}
\addConstraint{}{\Psi(\mathbf{x}_f,t_f)= 0,}{\quad\text{(Terminal constraints)}}
\end{mini*}

\subsection*{Alignment at equals signs}

\begin{mini*}|s|
  {\scriptstyle\mathbf{x},\mathbf{u}}
  {J = \phi(\mathbf{x}(t_f),t_f) + \int_{t_0}^{t_f}\mathcal{L}(\mathbf{x},\mathbf{u},t)\,dt}{}{}
\addConstraint{\dot{\mathbf{x}}}{=\mathbf{f}(\mathbf{x},\mathbf{u},t)}{}
\addConstraint{\mathbf{x}(0)}{= \mathbf{x}_0,}{\quad\text{(Initial condition)}}
\addConstraint{\Psi(\mathbf{x}_f,t_f)}{= 0,}{\quad\text{(Terminal constraints)}}
\end{mini*}

\end{document}

In my opinion, optidef should have an option to make the subscript variables in script size instead of normal size. I opted for a simpler \scriptstyle declaration in place of the more complicated \substack.

enter image description here

As a further simplification for inputting your formulas, I suggest to add something like

\newcommand{\vectorvariable}[1]{\mathbf{#1}}
\newcommand{\vf}{\vectorvariable{f}}
\newcommand{\vu}{\vectorvariable{u}}
\newcommand{\vx}{\vectorvariable{x}}

so, for instance, the first constraint would become

\addConstraint{}{\dot{\vx}}=\vf(\vx,\vu,t)}{}

In case a reviewer tells you that vector variables should be in bold italic, you'll just have to add

\usepackage{bm}

and change a single line in your code, namely

\newcommand{\vectorvariable}[1]{\bm{#1}}

After this, running LaTeX on your document would yield

enter image description here

(or the other layout, according to the one you prefer, of course). Similarly, adding

\newcommand{\diff}{\mathop{}\!d}

and typing \diff t when you want the differential, will allow you to cope with fussy reviewers or supervisors requiring an upright “d” by just changing a single line of code. Note that if you go this way, the \, in front of the differential in integrals should be removed.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.