The "proper" way to do this would, I suppose, be to turn on the numbering of the equations you want to number. You can do this by right clicking the equation and selecting Number this formula. There is also a keyboard shortcut, Alt + M N (hold down Alt, press M, release both, press N), which will work if the cursor is inside in equation.
Of course this is tedious work if you have a lot of equations, so it is better to number as you go. Either by adding a normal displayed equation and numbering as mentioned above, or inserting a numbered equation directly, with Insert --> Math --> Numbered formula.
This is also quite tedious, Ctrl+Shift+M is much easier. What one can do is to modify this shortcut to insert a numbered formula instead, or add a new shortcut for this purpose. Changing keyboard shortcuts are done in Tools --> Preferences --> Editing --> Shortcuts, see e.g. Shortcuts for Lemma, Claim, Theorem etc for details. A function you can use for such a shortcut is
command-sequence math-mode on; math-mutate equation;math-number-toggle
Again though, this doesn't help if one already has written the entire document with unnumbered equations. Then the trick mentioned in the LyX wiki, that you seem to have found, is more convenient: go to Document --> Settings --> LyX preamble and add the following two lines:
\renewcommand\[{\begin{equation}}
\renewcommand\]{\end{equation}}
This won't add numbering of the equations within LyX, but in the PDF they will be numbered.
I've taken some liberties in interpreting what you're trying to accomplish here. For example, I assume that you will manually create the tag names for the LP blocks. Also, I think my solution lacks a certain elegance: in particular, each such block has to be created separately. I don't really like that.
Here's the general idea: create two adjacent boxes centered on the baseline with one containing a dummy equation to create the label for the entire block. Spacing after the boxes is a bit wonky. So, I add ~
after the last flalign
environment. (Short coming: you also have to manually adjust the width of the first parbox
to get the label to be positioned correctly.)
You seemed to want the first line to somehow align with the LP. I've got two solutions to that. The first puts the first line into a box of zero width. (Short coming: you have to re-enter math mode within this box.) The second puts this first line in its own flalign
environment. (Short coming: you have to adjust the vertical spacing between the two environments.)
\documentclass{article}
\usepackage{amsmath,calc}
\newlength{\LPlhbox}
\begin{document}
\settowidth{\LPlhbox}{(P.1)}%
\noindent%
\parbox{\LPlhbox}{\begin{align}
\tag{P.1}\label{My first LP Block}
\end{align}}%
\hspace*{\fill}%
\begin{minipage}{\linewidth-2cm}
\begin{flalign}\notag
& \makebox[0pt][l]{$\displaystyle{}\max \sum\limits_{v \in V} x_v + \sum\limits_{e \in E} y_e + 10000\gamma$} \\
\label{this line can be referenced}
& \text{s.t.} & x_v + x_w & \geq 0 && \forall \{v,w\} \in E && \\
& & y_3 & \geq 0 && \forall e\in E && \\
& & (\delta(U)) & \geq \frac{1}{2}(|U|-1) && \forall U \subseteq V
\end{flalign}~
\end{minipage}
\settowidth{\LPlhbox}{(P.2)}%
\noindent%
\parbox{\LPlhbox}{\begin{align}
\tag{P.2}\label{My second LP Block}
\end{align}}%
\hspace*{\fill}%
\begin{minipage}{\linewidth-2cm}
\begin{flalign}\notag
\max \sum\limits_{v \in V} x_v + \sum\limits_{e \in E} y_e + 10000\gamma &&
\end{flalign}
\vspace{-1.5\baselineskip}
\begin{flalign}
& \text{s.t.} & x_v + x_w & \geq 0 && \forall \{v,w\} \in E && \\
& & y_3 & \geq 0 && \forall e\in E && \\
& & (\delta(U)) & \geq \frac{1}{2}(|U|-1) && \forall U \subseteq V
\end{flalign}~
\end{minipage}
Notice that we can reference line~\ref{this line can be referenced}
and both block~\ref{My first LP Block} and block~\ref{My second LP Block}
\end{document}
What would be nice is if there were a commands \lefttag
and \righttag
to temporarily override document defaults.
You can also easily create a command to do the work of the left-hand box.
\newcommand{\LPblocktag}[2]{\settowidth{\LPlhbox}{(#1)}%
\parbox{\LPlhbox}{\begin{align}\tag{#1}#2\end{align}}%
\hspace*{\fill}}
I've written the second argument as I have because I don't want to assume you'll be referencing every such block.
So the first block above can be written as
\noindent%
\LPblocktag{P.3}{\label{My third LP Block}}%
\begin{minipage}{\linewidth-2cm}
\begin{flalign}\notag
& \makebox[0pt][l]{$\displaystyle{}\max \sum\limits_{v \in V} x_v + \sum\limits_{e \in E} y_e + 10000\gamma$} \\
\label{this line can be referenced}
& \text{s.t.} & x_v + x_w & \geq 0 && \forall \{v,w\} \in E && \\
& & y_3 & \geq 0 && \forall e\in E && \\
& & (\delta(U)) & \geq \frac{1}{2}(|U|-1) && \forall U \subseteq V
\end{flalign}~
\end{minipage}
I can reference \ref{My third LP Block}
Best Answer
Use
empheq
to style your equation set, together withsubequations
to achieve your numbering objective:The default numbering within
subequations
has the form (Xy). Theetoolbox
patch is applied in the preamble to change this to (X.y) for allsubequations
.