Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've checked the post here, where the package empheq is used for embedding equations into coloured boxes.

With that idea, I wrote in my file the following:

% in the preambule
\usepackage{empheq}
\newcommand*\mybox[1]{%
  \colorbox{burlywood1}{\hspace{1em}#1\hspace{1em}}}

% in the body
\begin{empheq}[box=\mybox]{align}
  ...equation here...
\end{empheq}

It works nicely. However, I'd like to create a new environment for such a box... I tried something like,

\newenvironment{colbox}{%
  \begin{empheq}[box=\mybox]{align}}{\end{empheq}}

but this doesn't work.

**Questions**

  • Can someone help me to define this environment?
  • Is it possible to define an environment which the colour is an argument? So I can use different colours.

Thank you all.

share|improve this question
add comment

1 Answer 1

up vote 8 down vote accepted

Please always make full documents when asking questions, it makes things a lot easier.

It seems that like a lot of environments that grab the environment body you need to use this form when wrapping in environment definitions (AMS display environments have the same feature):

enter image description here

\documentclass{article}

\usepackage{color,empheq}


\newcommand*\mybox[1]{%
  \colorbox{yellow}{\hspace{1em}#1\hspace{1em}}}

\newenvironment{colbox}{%
  \empheq[box=\mybox]{align}}{\endempheq}



\newenvironment{xcolbox}[1]{%
  \def\mybox##1{\colorbox{#1}{\hspace{1em}##1\hspace{1em}}}%
  \empheq[box=\mybox]{align}}{\endempheq}

\begin{document}
% in the body
\begin{empheq}[box=\mybox]{align}
  ...equation here...
\end{empheq}


\begin{colbox}
  ...equation here...
\end{colbox}


\begin{xcolbox}{red}
  ...equation here...
\end{xcolbox}

\end{document}
share|improve this answer
    
Thank you for the quick response. Next time I'll follow your advise about the whole document. Cheers. –  Dox Aug 16 '12 at 13:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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