1

I want to create a small formulary, and for that virtually every line has to be math formulas. I use the gather-environment from the package amsmath, for example:

\documentclass[10pt,a4paper]{article}

\usepackage{amsfonts}
\usepackage[fleqn]{amsmath}%fleqn for align left

\newcommand \ul \underline  %next 3 rows for subsection title underline
\newcommand{\tmpsection}[1]{}
\let\tmpsection=\subsection
\renewcommand{\subsection}[1]{\tmpsection{\underline{#1}}}


\begin{document}

\subsection{PSM}
\begin{gather*}
      \ul{u_s} = r_s\ul{i_s} + \frac{d}{dt}\ul{\Psi_s}
      +j\omega_k\underline{\Psi_s}\\
      \ul{\Psi_s}=l_s\ul{i_s}+\ul{\Psi_m}\\
      \omega_m=\omega_s\\
      \end{gather*}

\end{document}

It seemed a good idea to incorporate the \begin{gather} environment into \subsection, and for that the redefinition of \subsection by \newcommand seemed probable, but I haven't been able to figure out what keywords to search for.

Only found redefinitions of text style so far, but is it possible to include a \begin-\end environment into \subsection?

If not, i could use this environment shorthand i guess, but still..

hirsch
  • 13

2 Answers2

3

You could try something like the following:

\documentclass[10pt,a4paper]{article}

\usepackage{amsfonts}
\usepackage[fleqn]{amsmath}%fleqn for align left
\let\ul=\underline
\newenvironment{Gather}[1]{\subsection{\underline{#1}}%
        \minipage{\textwidth}\csname gather*\endcsname}
        {\csname endgather*\endcsname \endminipage}

\begin{document}

\begin{Gather}{PSM}
      \ul{u_s} = r_s\ul{i_s} + \frac{d}{dt}\ul{\Psi_s}
      +j\omega_k\underline{\Psi_s}\\
      \ul{\Psi_s}=l_s\ul{i_s}+\ul{\Psi_m}\\
      \omega_m=\omega_s\\
\end{Gather}

\end{document}

This produces:

enter image description here

The trick with the nested gather* environment, and an explanation as to why it is necessary, comes from the answer to trouble defining new environment with embedded gather

0

Thanks Andrew, that helped a lot!

My final solution, for reference is (no section numbering, \g as environment shorthand):

\documentclass[10pt,a4paper]{article}

\usepackage{amsfonts}
\usepackage[fleqn]{amsmath}%fleqn for align left
\let\ul=\underline
\newenvironment{Gather}[1]{\subsection*{\underline{#1}}%
    \minipage{\textwidth}\csname gather*\endcsname}
    {\csname endgather*\endcsname \endminipage}

\newcommand{\g}[2]{\begin{Gather}{#1}#2\end{Gather}}

\begin{document}

\g{PSM}{
  \ul{u_s} = r_s\ul{i_s} + \frac{d}{dt}\ul{\Psi_s}
  +j\omega_k\underline{\Psi_s}\\
  \ul{\Psi_s}=l_s\ul{i_s}+\ul{\Psi_m}\\
  \omega_m=\omega_s\\
}


\end{document}

nice code :)

hirsch
  • 13
  • which in turn makes your code harder to read and harder to maintain. The env route is more preferable. – daleif Jul 17 '14 at 08:13