Although they do not seem related to me, I am having trouble using the xcolor package with a savebox and bgroup.
\documentclass{article}
\usepackage{xcolor}
\newsavebox{\mybox}
\savebox{\mybox}\bgroup hello world \egroup
\begin{document}
\usebox{\mybox}
\bgroup good bye world \egroup
\end{document}
gives me a missing "}" error with texlive 2010. If I do not use the package xcolor, I do not get an error. If I replace:
\savebox{\mybox}\bgroup hello world \egroup
with:
\savebox{\mybox}{hello world}
I do not get an error.
What am I doing wrong?
General ⇒ xcolor, savebox, bgroup problem
NEW: TikZ book now 40% off at Amazon.com for a short time.

- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
xcolor, savebox, bgroup problem
Usually the argument for the \savebox command needs to be grouped with curly braces.
Best regards and welcome to the board
Thorsten
Code: Select all
\documentclass{article}
\usepackage{xcolor}
\newsavebox{\mybox}
\savebox{\mybox}{\bgroup hello world \egroup}
\begin{document}
\usebox{\mybox}
\bgroup good bye world \egroup
\end{document}
Best regards and welcome to the board
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
xcolor, savebox, bgroup problem
Thank you, I have now read the rules.
which results in:
! Missing } inserted.
<inserted text>
}
l.6 \begin{myenv}
hello world\end{myenv}
?
! Emergency stop.
when the xcolor package is used, but no error when the xcolor package is not used.
Yes, I know. A slightly less minimal example that I think requires \bgroup and \egroup instead of curly braces is:localghost wrote:Usually the argument for the \savebox command needs to be grouped with curly braces.
Code: Select all
\documentclass{article}
\usepackage{xcolor}
\newsavebox{\mybox}
\newenvironment{myenv}{\savebox{\mybox}\bgroup}{\egroup\usebox{\mybox}}
\begin{document}
\begin{myenv}hello world\end{myenv}
\bgroup good bye world \egroup
\end{document}
! Missing } inserted.
<inserted text>
}
l.6 \begin{myenv}
hello world\end{myenv}
?
! Emergency stop.
when the xcolor package is used, but no error when the xcolor package is not used.
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
xcolor, savebox, bgroup problem
I don't see any sense in your definition of the new environment.
The additional grouping is superfluous since an environment itself already represents a group.
Code: Select all
\newenvironment{myenv}{\savebox{\mybox}\bgroup}{\egroup\usebox{\mybox}
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
xcolor, savebox, bgroup problem
I was trying to add some text in an environment and then use that text elsewhere. The environ package lets me do this pretty easily, but before I found that package my solution involved:
which worked fine until I loaded the xcolor package. While I understand that this solution is potentially flawed and that one might not ever want to make a \savebox with \bgroup and \egroup, I am really just curious why the xcolor package breaks my solution.
localghost, thanks for the help so far.
Code: Select all
\savebox{\mybox}\bgroup hello world \egroup
localghost, thanks for the help so far.