I understand from this post that \bgroup
is equivalent to {
and \egroup
is equivalent to }
(Edit: turns out that my understanding was wrong, see @david-carlisle comments for details). I have a scenario where I must replace {}
with \bgroup
and \egroup
(edit: see the reason why I must not use the braces at the end of my post). This is okay with \texttt
and math subscript, but I could not use it with math fractions. With \frac
, the latex file compiles without errors but does not produce the fraction I would expect. Here is a MWE:
\documentclass[12pt]{article}
\usepackage{amsmath}
\begin{document}
% texttt example
texttt example using curly braces as usual:\\
\texttt{hello}
% texttt works with \bgroup and \egroup
The same texttt example using \textbackslash bgroup and \textbackslash egroup:\\
\texttt\bgroup hello\egroup
% math subscript example
A subscript example using curly braces as usual:\\
$ x_{10} = 10 $
% math subscript works with \bgroup and \egroup
The same subscript example using \textbackslash bgroup and \textbackslash egroup:\\
$ x_\bgroup 10\egroup = 10 $
% Reason for the post: A fraction example
A fraction example using curly braces as usual:\\
$ \frac{x}{x-1} $
% Using \bgroup and \egroup, the fraction looks different
The following is supposed to be the same fraction example, only this time
using \textbackslash bgroup and \textbackslash egroup.
However, the result looks different:\\
$ \frac\bgroup x \egroup\bgroup x-1 \egroup $
\end{document}
And the output is
By the way, I have Googled this already and couldn't find any result that shows how to use \bgroup
and \egroup
with \frac
. Therefore, it is likely that I'm the first to ask this question (Apologies for that :).
So my question is: How to use \bgroup
and \egroup
with \frac
instead of the standard usage with the curly braces {}?
Edit: Here is why I must not use the braces with \frac. I'm using RndTexExams, which is a package in R, and it generates multiple and randomized test versions based on examdesign package. One multiple choice question may have different versions, and the versions are surrounded by @ from both sides, separated by pipes, and delimited by braces. Example @{Version 1}|{Version 2}@. If you try to replace Version 1 with something that has braces in it, like \texttt{Version 1}, the R package will fail to parse this question and will produce a faulty output Latex file.
\texttt\bgroup
that is the same as\texttt{\bgroup}
and the argument to the command is just\bgroup
. Anything that happens after that is just untested accidental expansion from bad input.\bgroup
may only be used in some cases as an equivalent token to{
delimiting macro arguments is one case where\bgroup
does not work at all.\def\num{x} \def\denom{x-1} $ \frac\num\denom $
{}
which is prohibited, or the concept of bracing? If the former, you could use\catcode
to make a different set of characters act like braces.