10

I want to use the closing bracket in a \newcommand definition. I can give more explanation as to why, but this seems unnecessary at the moment. Obviously the MWE does not work, but how to make this work?

MWE

\documentclass{minimal}
\newcommand{\test}{somecommand}}

\begin{document}
Hi 
\end{document}

which gives the error

! Too many }'s.
3
  • Do you want to end a group, or do you want to display the }? Oct 17, 2014 at 13:07
  • End a group. I have another command with an opening bracket, some text in between and then a command with a closing bracket (the one I am asking about now).
    – Ritz
    Oct 17, 2014 at 13:09
  • 2
    then why not use \begingroup and \endgroup?
    – cgnieder
    Oct 17, 2014 at 13:11

1 Answer 1

12

You can use \bgroup and \egroup to begin and end groups in such circumstances.

\documentclass[11pt,a4paper]{article}
\newcommand\test{sheep \egroup}
\begin{document}
Pig \bgroup\Huge\test goat
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .