1

My goal is for the enca command below to use color blue for math and text mode. What's the best way to do this?

\documentclass{scrartcl}
\usepackage[skins,breakable,xparse,many]{tcolorbox}
\usepackage{xcolor}

%BOX
\NewDocumentCommand{\enca}{ O{black} m }{%
    \ifmmode\tcboxmath[standard jigsaw, tcbox raise base,opacityback=0,tcbox width=auto limited,extras={colupper={tcbcolback}},colframe=#1,size=fbox]{#2}\else
     \tcbox[standard jigsaw, tcbox raise base,tcbox width=auto limited,opacityback=0,extras={colupper={tcbcolback}},colframe=#1,size=fbox,nobeforeafter]{#2}\fi%
    }
%
\begin{document}

{\color{blue}

ABCEE \enca{ABCDE}, 
\[ 1 +\enca{\int_1^2 x^2 \mathrm{d} x}.\]
}

\end{document}

enter image description here

1

Perhaps you can save the current color and apply to the color box, for example:

\NewDocumentCommand{\enca}{ O{black} m }{%
    \colorlet{temp}{.}% Save the current color to temp
    \ifmmode\tcboxmath[standard jigsaw, tcbox raise base,opacityback=0,tcbox width=auto limited,colupper=temp,colframe=#1,size=fbox]{#2}\else
     \tcbox[standard jigsaw, tcbox raise base,tcbox width=auto limited,opacityback=0,colupper=temp,colframe=#1,size=fbox,nobeforeafter]{#2}\fi%
    }

Complete example:

\documentclass{scrartcl}
\usepackage[skins,breakable,xparse,many]{tcolorbox}
\usepackage{xcolor}

%BOX
\NewDocumentCommand{\enca}{ O{black} m }{%
    \colorlet{temp}{.}%
    \ifmmode\tcboxmath[standard jigsaw, tcbox raise base,opacityback=0,tcbox width=auto limited,colupper=temp,colframe=#1,size=fbox]{#2}\else
     \tcbox[standard jigsaw, tcbox raise base,tcbox width=auto limited,opacityback=0,colupper=temp,colframe=#1,size=fbox,nobeforeafter]{#2}\fi%
    }
%
\begin{document}

{\color{blue}

ABCEE \enca[red]{ABCDE}, 
\[ 1 +\enca[red]{\int_1^2 x^2 \mathrm{d} x}.\]
}

\end{document}

which produces:

enter image description here

1
  • Thank's ! it works perfectly. I also used temp as an optional argument (O{temp}) to make the box color match as well.
    – jowe_19
    Mar 5 '21 at 8:39

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.