0

Can I replace the begin and end of an environment just with a pair of braces {} where the left brace { will take care of the \begin{} part and right brace } will function like the \end{} part? This is slightly similar to using \centering in place of \begin{center} and \end{center}.

See this MWE with the alignment environment below.

\documentclass{article}
\usepackage{amsmath}

\def\blgn#1\elgn{\begin{align}#1\end{align}}

% I want to define something like \align{} where % the left brace { will take care of the \begin part % and rigth brace } will function like the\end part.

\begin{document} \blgn (a+b)^2 = a^2 + 2ab + b^2. \elgn \end{document}

hbaromega
  • 323
  • 2
    \def\blgn#1{\begin{align}#1\end{align}} but don't do this. – David Carlisle May 02 '23 at 17:33
  • 4
    \centering{} in place of \begin{center} and \end{center} ??? \centering does not have a { } argument and produces different spacing than \begin{center}..\end{center} – David Carlisle May 02 '23 at 17:35
  • Seconding @DavidCarlisle, use an editor you like, which supports LaTeX, like Texmaker etc. where you have and can extend User commands. Saves a lot of typing ... // https://www.xm1math.net/texmaker/ // https://tex.stackexchange.com/questions/339/latex-editors-ides – MS-SPO May 02 '23 at 18:13
  • @DavidCarlisle Are you recommending using \newcommand instead of \def? You're right. I have corrected it. However, hope you've got the essence of the question. – hbaromega May 02 '23 at 20:44
  • 1
    no I am recommending using \begin{align} hiding that in a macro only has disadvantages, but the code in my first comment is the answer to your question if you really need that. I can not see any connection with \centering as that does not take an argument. – David Carlisle May 02 '23 at 20:48
  • 1
    You can wrap environments in commands, as David says: \newcommand{\olist}[1]{\begin{enumerate}#1\end{enumerate}}. Then you would write \olist{\item 1 \item 2}. I think that is harder to maintain, though, because instead of a logical marker for the beginning and the end, you just have the bracket, which could mean a lot of things. This won't work with every environment, as there usually is some reason why an environment was provided instead of a command. – musarithmia May 02 '23 at 21:00
  • 1
    @DavidCarlisle can you maybe post your comments as an answer elaborating on why this is potentially a bad idea? – Toivo Säwén May 24 '23 at 08:19
  • @DavidCarlisle It's unclear what disadvantages you wanted to mean when \def is used. If centering doesn't seem to fit to the analogy, I can recall something from beamer. There both \frame{} and \begin{frame}...\end{frame} serve the same purpose imo. Anyway, following @musarithmia's suggestion I find both \newcommand{\algn}[1]{\begin{align}#1\end{align}} and \def\algn#1{\begin{align}#1\end{align}} resolve my issue. Thanks. – hbaromega Aug 05 '23 at 10:40

0 Answers0