0

I'm trying to create a new environment, more specifically using a \newtcolorbox[]{}{}{}. My intention is to create an environment that brings together both the \begin{tcolorbox}[] \end{tcolorbox} and the \begin{equation} \end{equation} in order to make it easier to use. I want to create an environment called answer with the following features from the tcolorbox package:

\newtcolorbox[]{answer}{%
    enhanced,
    center,
    breakable,
    boxrule = 0pt,
    frame hidden,
    hbox,
    colback = myblack!80,
    sharp corners,
    rounded corners = southeast,
    rounded corners = northeast,
    rounded corners = southwest,
    rounded corners = northwest,
    arc is angular,
    arc = 3mm,
    coltext = white,
    math upper,
}

I was able to create the box for it to turn all inputs into mathematical outputs, however, I also wanted to be able to reference the equations within these boxes, so that if I typed:

\begin{answer}\label{eq: 1}
     A random equation
\end{answer}

Could I reference this equation such that the counter follows the same counter from the equation or align environment. I tried to include on the initial options [use counter from = equation], but it doesn`t work.

I have this: enter image description here

but I need something like this (I made it in Photoshop): enter image description here

6
  • Instead of use counter from use use counter=equation, the use counter from is meant to inherit the counter from other tcolorboxes, whereas use counter is meant to use a standard LaTeX counter (like equation).
    – Skillmon
    Commented Mar 6, 2023 at 19:39
  • Still doesn't work.
    – Jimeens
    Commented Mar 6, 2023 at 19:57
  • You also don't specify any place where the counter is output.
    – Skillmon
    Commented Mar 6, 2023 at 20:23
  • And you don't show any minimal example which we can compile...
    – Skillmon
    Commented Mar 6, 2023 at 20:24
  • Now, I specify what I want
    – Jimeens
    Commented Mar 6, 2023 at 20:29

1 Answer 1

2

You could use \tcbhighmath{...} to highlight your formula:

\documentclass{article}

\usepackage[most]{tcolorbox}

\usepackage{environ}

\NewEnviron{answer}{
\begin{equation}
\tcbhighmath[
         boxrule = 0pt,
         frame hidden,
         colback = black!80,
         sharp corners,
         rounded corners = southeast,
         rounded corners = northeast,
         rounded corners = southwest,
         rounded corners = northwest,
         arc is angular,
         arc = 3mm,
         coltext = white,
     ]{\BODY}\end{equation}}

\begin{document}

\begin{answer}\label{eq:1}
A random equation
\end{answer}

A random equation in \eqref{eq:1}


\end{document}

enter image description here

1
  • 1
    Nowadays I'd probably use \NewDocumentEnvironment{answer}{b} (and then #1 instead of \BODY) instead of environ, else good answer.
    – Skillmon
    Commented Mar 7, 2023 at 6:02

You must log in to answer this question.

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