0

This question already has an answer here:

I am trying to create two new macros:

  • braces: compiles some text between curly brackets
  • squakets: compiles text between two square brackets

I defined as follows.

\documentclass{article}

\newcommand{\braces}[2]{$\left\{\begin{tabular}{@{}c@{}}
    #1\\
    #2\\
    \end{tabular}\right\}$}    


\newcommand{\squakets}[1]{$\Big[ #1 \Big]$}

\begin{document}

\squakets{\squakets{\braces{$\sqrt{}$}{$\alpha$} \braces{$x$}{$\beta$}} \braces{$y$}{$\gamma$}} $\rightarrow$ \braces{$\sqrt{}$}{$\alpha$} -- \braces{$x$}{$\beta$} -- \braces{$y$}{$\gamma$}

\end{document}

Console still compiles, even though it warns me that:

Missing $ inserted.

I was curious of understanding how to fix this. I guess it is something related to the fact I am embedding multiple squakets command in one another, but can someone help figure that out?

marked as duplicate by Werner macros Jan 28 '18 at 4:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    I'd call the second macro squaces ;o) – Bernard Jan 28 '18 at 1:22
  • 3
    You are using the wrong approach here. What solves your problem is \ensuremath{..} rather than $..$. But still, if it's math, it should be in math mode, and not (ab)use \ensuremath. – Manuel Jan 28 '18 at 1:22
  • 2
    You cannot nest $...$. You should either change them to \ensuremath{} or, preferably, remove them. Then use your macro inside math mode only. – Phelype Oleinik Jan 28 '18 at 1:24
  • Why not use array instead of tabular? – Bernard Jan 28 '18 at 1:24
  • @Manuel And if it isn't maths .... – cfr Jan 28 '18 at 1:26
1
\documentclass{article}

\usepackage{mleftright}

\newcommand*\braces[2]{\mleft\{{\begingroup#1\endgroup\atop#2}\mright\}}
\newcommand*\squakets[1]{\Bigl[#1\Bigr]}

\begin{document}

\[
  \squakets{\squakets{\braces{\sqrt{}}{\alpha} \braces{x}{\beta}} \braces{y}{\gamma}}
  \to
  \braces{\sqrt{}}{\alpha} - \braces{x}{\beta} - \braces{y}{\gamma}
\]

\end{document}
  • Thank you, @Manuel! However, your solution compiles something a bit different from what I had in mind. – RobertP. Jan 28 '18 at 3:05
0

Thank you for all of your help!

This is the solution I came up with:

\newcommand*{\braces}[2]{\ensuremath{\left\{\begin{tabular}{@{}c@{}}
        #1\\
        #2\\
        \end{tabular}\right\}}} 

As suggested in the comments above, \ensuremath{} instead of $...$ solves the issue.

Not the answer you're looking for? Browse other questions tagged or ask your own question.