1

I've created a command \newcommand{\br}[1]{$\left\{{#1}\right\}$} to provide left and right curly braces surrounding an input.

The usage \br{g \in G : \theta(g) = M/N} works perfectly until I try to use it in alignment as follows:

\begin{align*}
\ker\theta &= \br{g \in G : \theta(g) = M/N} \\
&= \br{g \in G : (M/N)Ng = M/N}
\end{align*}
  1. Is there a better macro for enclosing {}?

  2. Is there a way to use this or a better macro within alignment?


Update:

There is an alternative to the macro I defined called \Set in the braket package. This is due to a comment in How to automatically resize the vertical bar in a set comprehension? commented by ShreevatsaR.

\usepackage{braket}
\begin{align*}
\ker\theta &= \Set{g \in G \colon \theta(g) = M/N} \\
&= \Set{g \in G \colon (M/N)Ng = M/N}
\end{align*}

Equation alignment using Set

  • 1
    the problem here is that you're including $...$ in the definition of the command. the align* environment puts you into math mode, so the $ signs are redundant, and cause an error. it would be better to omit the $ signs from the command definition, and instead enter them around the command when you use it. – barbara beeton Feb 21 '17 at 3:20
  • \newcommand{\brr}[1]{\left\{{#1}\right\}} Works like a charm. If you care to drop that as an answer I'll accept it. Thx! – Athena Widget Feb 21 '17 at 3:49
  • I'd suggest to use \newcommand{\brr}[1]{\ensuremath{\left\{#1\right\}}} ... – marmot Feb 21 '17 at 3:59
  • In the long run it is probably not a good idea to use auto scaling as they have a tendency to become too large in certain cases. I'd suggest building \br using \DeclarePairedDelimiter from mathtools. – daleif Feb 21 '17 at 8:01
3

the problem here is that align* (and all the display math environments) put you automatically into math mode, so including $...$ in a definition that will be used in such an environment will result in an error if you use it there.

omit $ signs from the definition. if it's then used in text, it's better to explicitly include them in the input stream -- it will make it obvious that what is there is math, and thus easier to find when you are looking for something in your file.

an alternative possibility is to use \ensuremath in the definition, so that it will work equally well whether in or not in math mode. however, this is not really recommended, as it obscures the nature of the command. some additional reasons for not using it are given here: When not to use \ensuremath for math macro?.

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.