3

I would like to produce in report class the following style for numbering subequations:

  • The main equation has its own number, and can be referenced.

  • Each subequations are labelled with lower case letters. These labels are vertically aligned.

  • When referring to the subequations, their full path is shown (e.g., "Equation (1b)...").

Here is an example I found in a paper (The curly bracket is not necessary):

enter image description here

(From: Hans-Georg Beyer, Bernhard Sendhoff, Robust optimization – A comprehensive survey, Computer Methods in Applied Mechanics and Engineering, Volume 196, Issues 33–34, 1 July 2007, Pages 3190-3218)

This code produces the standard style:

\documentclass{report}

\usepackage{amsmath}
\usepackage[colorlinks=true,linkcolor=blue]{hyperref}

\begin{document}
\ldots can be stated as:
\begin{subequations}
\label{main_eq}
\begin{align}
\label{sub_eq1}\text{optimize:}\quad &f(x),\\
\label{sub_eq2}\text{subject to:}\quad &g(x)\leq0,\\
\label{sub_eq3}&h(x)=0,
\end{align}
\end{subequations}
where~\eqref{sub_eq2} represents an inequality constraint and~\eqref{sub_eq3} an equality constraint.

\ldots the optimum of $f(x)$ in~\eqref{main_eq}, like NP-hardness in\ldots

\end{document}
4
  • 6
    Your question leaves all the effort to our community, even typing the essentials of a TeX document such as \documentclass{}...\begin{document} etc. As it is, most of our users will be very reluctant to touch your question, and you are left to the mercy of our procrastination team who are very few in number and very picky about selecting questions. You can improve your question by adding a minimal working example (MWE) that more users can copy/paste onto their systems to work on. If no hero takes the challenge we might have to close your question.
    – Adam Liter
    Apr 9 '14 at 16:45
  • And welcome to TeX.SX!
    – Adam Liter
    Apr 9 '14 at 16:46
  • @Adam thank you for your comments. A MWE is included now.
    – Shaul
    Apr 10 '14 at 10:33
  • In all honesty, I would not confuse the reader by splitting the number: Just number the lines (1a), (1b) and (1c) at the right as in any other equation.
    – yo'
    Apr 14 '14 at 7:59
3

Here's an attempt; note that the constraints are separated from each other with a semicolon.

\documentclass{report}

\usepackage{amsmath,array,xparse}
\usepackage[colorlinks=true,linkcolor=blue]{hyperref}

\newcounter{optproblemline}
\renewcommand{\theoptproblemline}{\alph{optproblemline}}
\makeatletter
\renewcommand{\p@optproblemline}{\theequation}
\makeatother


\ExplSyntaxOn
\NewDocumentCommand{\optproblem}{ m m }
 {
  \shaul_opt_problem:n { #2 }
  \setcounter{optproblemline}{0}%
  \left.
  \cs_set_eq:Nc \label { ltx@label } % in a group, reset \label
  \begin{array}{
    @{}
    l
    @{\quad}
    >{\refstepcounter{optproblemline}}l
    >{\textnormal{(\theoptproblemline)}}l
  }
  \textnormal{optimize:}&#1&\\
  \textnormal{subject~to:} \tl_use:N \l_shaul_constraints_tl
  \end{array}
  \right\rbrace
}

\tl_new:N \l_shaul_constraints_tl
\seq_new:N \l_shaul_constraints_seq

\cs_new_protected:Npn \shaul_opt_problem:n #1
 {
  \tl_clear:N \l_shaul_constraints_tl
  \seq_set_split:Nnn \l_shaul_constraints_seq { ; } { #1 }
  \seq_map_inline:Nn \l_shaul_constraints_seq
   {
    \tl_put_right:Nn \l_shaul_constraints_tl { & ##1 & \\ }
   }
 }
\ExplSyntaxOff

\begin{document}
\ldots can be stated as:
\begin{equation}\label{main_eq}
\optproblem{f(x)\label{sub_eq1}}
 {
  g(x)\leq0, \label{sub_eq2};
  h(x)=0, \label{sub_eq3}
 }
\end{equation}
where~\eqref{sub_eq2} represents an inequality constraint and~\eqref{sub_eq3} 
an equality constraint.

\ldots the optimum of $f(x)$ in~\eqref{main_eq}, like NP-hardness in\ldots

\end{document}

enter image description here

2
  • Thanks @egreg this is exactly what I had in mind. Since I have many types of subequations, I wonder if the code can be made more flexible (i.e., to handle equations that do not include "optimize:" or equations that include "where:" in the left column).
    – Shaul
    Apr 17 '14 at 8:20
  • @Shaul This is surely possible; can you make a followup question, specifying your needs?
    – egreg
    Apr 17 '14 at 8:46
2

Working notes

For now, I can present you solution without amsmath loaded. It has protection of \label and I haven't figured out yet how to evade that.

\documentclass{report}
\pagestyle{empty}
%\usepackage{amsmath} % Not working for now...
\usepackage[colorlinks=true,linkcolor=blue]{hyperref}
\usepackage{refcount}
\usepackage{alphalph}
%\let\oldlabel=\label
%\let\oldref=\ref
%\let\oldpageref=\pageref
%\let\label=\oldlabel
%\let\ref=\oldref
%\let\pageref=\oldpageref
\newcounter{malsubeqn}[equation]
\def\mallabel#1{%
  \refstepcounter{malsubeqn}%
  (\alph{malsubeqn})%
  \label{#1}%
  %\typeout{\meaning\label}
  }% End of \mallabel...
\def\malsubeqref#1{(\hyperref[#1]{%
  \theequation\alphalph{\getrefnumber{#1}}%
  })}% End of \maleqref...
\def\maleqref#1{(\ref{#1})}

\begin{document}
%\typeout{\meaning\oldlabel}
\ldots can be stated as:
\begin{equation}
\label{main_eq}
%\begin{subequations}
%\begin{aligned}%{rll}
\left.\begin{array}{rll}
\textrm{optimize:}\quad & f(x),            & \mallabel{sub_eq1}\\
\textrm{subject to:}\quad & g(x)\leq0,& \mallabel{sub_eq2}\\
   & h(x)=0,                                    & \mallabel{sub_eq3}\\
\end{array}\right\}
%\end{align}
%\end{subequations}
\end{equation}
where~\malsubeqref{sub_eq1} is a function to be optimized, \malsubeqref{sub_eq2} represents an inequality constraint and~\malsubeqref{sub_eq3} an equality constraint.\par
\ldots the optimum of $f(x)$ in~\maleqref{main_eq}, like NP-hardness in\ldots
\end{document}

mwe

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.