2

I have to define a new environment doing something like that.

\documentclass[12pt]{article}
\usepackage{tcolorbox,empheq}
\begin{document}
\begin{tcolorbox}
\begin{empheq}{align}
a=b
\end{empheq}
\end{tcolorbox}
\end{document}

screenshot

This code works fine, but if I try something like testa or testb, I get errors.

\documentclass[12pt]{article}
\usepackage{tcolorbox,empheq}

\newenvironment{testa}{\tcolorbox\empheq{align}}{\endempheq\endtcolorbox}
\newenvironment{testb}{\tcolorbox\setkeys{EmphEqEnv}{align}\EmphEqMainEnv}{\endEmphEqMainEnv\endtcolorbox}

\begin{document}
\begin{testa}
a=b
\end{testa}
\end{document}

Is there a solution ?

2

I suggest to use a temporary wrapper environment for empheq and then 'wrap' \tcolorboxenvironment around it:

\documentclass[12pt]{article}
\usepackage[most]{tcolorbox}
\usepackage{empheq}

\newenvironment{testa}{%
  \empheq{align}
}{\endempheq}

\tcolorboxenvironment{testa}{colback=yellow!40!white}


\begin{document}


\begin{testa}
a=b
\end{testa}
\end{document}
  • Yes, this is working, but in fact I need something like \begin{testa}{gather*}a=b\end{testa} so the empheq parameter has to be new environment parameter. The method using \tcolorboxenvironment does not seem to work for that. – MB4E Mar 8 '18 at 21:25
  • @MB4E: Did you ask for that argument in your question? No, you didn't. By your comment you are changing the initial question... – user31729 Mar 8 '18 at 21:29
  • I know, it was an MCV example and your answer is working in this case. I was hoping to adapt the solution to a more general situation but unfortunately it does not seem possible like that. But you right, the initial question is solved. – MB4E Mar 8 '18 at 21:37
3

I understand you want to combine tcolorbox with empheq. Instead of a tcolorbox which contains an empheq environment, you should declare an empheq environment with an optional parameter which defines the colorbox aspect. This combination can be declared as a newenvironment

\documentclass{article}

\usepackage{amsmath}
\usepackage{empheq}
\usepackage[most]{tcolorbox}

\newtcbox{\mymath}[1][]{%
    nobeforeafter, math upper, tcbox raise base,
    enhanced, colframe=blue!30!black,
    colback=blue!30, boxrule=1pt,
    #1}

\newenvironment{testa}[1]{%
    \empheq[box={#1}]{align}}{\endempheq}

\begin{document}
\begin{empheq}[box=\mymath]{align}
    c_i &= \langle\psi|\phi\rangle \\
    d_i &= \sqrt{x^2-1}
\end{empheq}

\begin{testa}{\mymath[colback=red!30]}
    c_i &= \langle\psi|\phi\rangle \\
    d_i &= \sqrt{x^2-1}
\end{testa}

\end{document}

enter image description here

Some other examples in Attractive Boxed Equations

  • Yes, I know this method but I really have to do things the other way. – MB4E Mar 8 '18 at 18:14
  • @MB4E Could you explain it better? What's the result you want to obtain? – Ignasi Mar 8 '18 at 18:16
  • Just the same result as in my first code example. – MB4E Mar 8 '18 at 18:42
  • I just add a screenshot. – MB4E Mar 8 '18 at 18:48
  • Something like this? \begin{tcolorbox}[ams align]a=b\end{tcolorbox} – Ignasi Mar 8 '18 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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