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..

  • Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Jul 16 '14 at 22:08
  • Erhm, it is definitely not clear what it is you are asking – daleif Jul 16 '14 at 22:27
  • I want to get rid of the \begin{gather*} and \end{gather*} by somehow putting it into \subsection by \renewcommand – hirsch Jul 16 '14 at 22:31
  • Do you want the entire gather math content to form part of the sectional title? If so, why? – Werner Jul 16 '14 at 22:38
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 :)

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

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.