GeneralShortning commands such as \begin{gathered}

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
railfan1975
Posts: 3
Joined: Mon Apr 07, 2008 1:02 am

Shortning commands such as \begin{gathered}

Post by railfan1975 »

I use some commands, such as \begin{gathered} a lot. I would like to replace them with shorter commands. I tried using \newcommand{\bg}{\begin{gathered}}, but it gave me an error.

Is there any way of doing this short of creating a package?

Thanks!

JT

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Shortning commands such as \begin{gathered}

Post by gmedina »

Many of the commands and environments provided by the amsmath package are fragile so shortcuts as the one you defined are a recipe for disaster, as you have already experienced.

You can define a synonym for those environments using something like

Code: Select all

\documentclass{article}
\usepackage{amsmath}

\newenvironment{gatd}{\gathered}{\endgathered}

\begin{document}

\begin{equation}
  \begin{gatd}
    (a+b)(a-b)=a^2-b^2\\
    (a+b)(a+b)=a^2+2ab+b^2
  \end{gatd}
  \begin{gatd}
    (a-b)(a-b)=a^2-2ab+b^2\\
    (a-b)(a+b)=(a+b)(a-b)
  \end{gatd}
\end{equation}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Shortning commands such as \begin{gathered}

Post by Juanjo »

Try

Code: Select all

\let\bg\gathered
\let\eg\endgathered
So you can write something like

Code: Select all

\[
\bg
 a+b+c=d+e \\
 f+g+h=i
\eg
\]
Anyway, I think doing that is a bad practice, since the internal checks for environments that remain open are then disabled. Suppose you forget \eg. Compile and look at the error. Now, replace \bg by \begin{gathered} and compile. Which error is easier to debug?
balf
Posts: 158
Joined: Sat Jan 12, 2008 1:11 am

Re: Shortning commands such as \begin{gathered}

Post by balf »

The best solution, I think, is a good editor that lets you have shorthands to typeset in a stroke the whole environment, then have the cursor at the right place. It is important that the source code remains readable .

B.A.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Shortning commands such as \begin{gathered}

Post by Stefan Kottwitz »

Hi JT,

short workaround:

Code: Select all

\def\bg#1\eg{\gathered#1\endgathered}
Or:

Code: Select all

\newcommand\gath[1]{\gathered#1\endgathered}
You can read something about the problem with abbreviating amsmath environments in the amsmath technical notes.

Stefan
Post Reply