# Border color only on boxed equation

Starting from this question \boxed border color I wanted to color only the box, but I also have number colored. Without to use mdframed, tcolorbox, or other package is there a very simple alternative (without macro) to have the color of the box? My MWE is:

\documentclass[12pt]{article}
\usepackage{amsmath,amssymb,xcolor}
\begin{document}
$$\colorlet{oldcolor}{.} \color{magenta} \boxed{\color{oldcolor}{F(x)=\int_{0}^{x}f(t)dt}}$$
\end{document}

• Just add \color{oldcolor} after the box, $$\colorlet{oldcolor}{.} \color{magenta} \boxed{\color{oldcolor} F(x)=\int_{0}^{x}f(t)\,\mathrm{d}t}\color{oldcolor}$$. – user194703 Dec 30 '19 at 20:36
• @Schrödinger'scat No no :-((( a comment please. Put an answer thus I vote it. :)))) I have only 4 votes for today. – Sebastiano Dec 30 '19 at 20:38

For reference, here's a version that uses tcolorbox's tcbhighmath command:

\documentclass{article}
\usepackage[many]{tcolorbox}
\tcbset{
every box/.style={
highlight math style={sharp corners,colback=white,colframe=magenta},
}
}
\begin{document}
$$\tcbhighmath{F(x)=\int_{0}^{x}f(t)dt}$$
\end{document}


You might like to see Section 17.1 of the tcolorbox documentation for further reading; in particular, you might like to see \tcboxmath.

• I always wish you and all those who give their knowledge to improve our society with little culture and respect. – Sebastiano Dec 31 '19 at 16:05

I propose to define a colorboxed command, based on \fcolorbox, which has two mandatory argument – the colour of the frame and the content of the frame, and the background of the frame as an optional argument:

\documentclass[12pt]{article}
\usepackage{amsmath,amssymb}

\usepackage[svgnames]{xcolor}
\makeatletter
\newcommand{\colorboxed}[3][white]{\fcolorbox{#2}{#1}{\m@th$\displaystyle#3$}}
\makeatother

\begin{document}

$$\colorboxed{IndianRed}{F(x)=\int_{0}^{x}f(t)dt}$$
$$\colorboxed[LavenderBlush!30]{IndianRed}{F(x)=\int_{0}^{x}f(t)dt}$$

\end{document}


OK, per request. You most likely want to switch back to the normal color anyway, so

\documentclass[12pt]{article}
\usepackage{amsmath,amssymb,xcolor}
\begin{document}
$$\colorlet{oldcolor}{.} \color{magenta} \boxed{\color{oldcolor} F(x)=\int_{0}^{x}f(t)\,\mathrm{d}t}\color{oldcolor}$$
\end{document}


Needless to say that there are packages like empheq, tcolorbox and in particular the combination of the two which take care of these things automatically.