0

I've seen somewhere such a shape of a highlight.

enter image description here

I am trying to repeat this using xcolor package, but I managed to get only rectangular shape of the box. enter image description here

\colorbox{red!10}{$\displaystyle\int xe^{-x}dx$}
1
  • \colorbox is always rectangular, look at packages such as tcolorbox which has many many options for fancier boxes May 14, 2020 at 17:54

1 Answer 1

3

One can combine tcolorbox and empheq. With \tcbhighmath you can highlight individual subexpressions.

\documentclass{article}
\usepackage[theorems,skins]{tcolorbox}
\usepackage{empheq}
\tcbset{red eqbox/.style={enhanced,top=0.2ex, bottom=0.2ex, 
left=0.1ex,right=0.1ex,
overlay={\fill[red!10] (frame.south west) to[bend left] 
 (frame.north west) --  (frame.north east) to[bend left]
  (frame.south east) -- cycle;},
boxrule=0pt},
blue eqbox/.style={enhanced,top=0.2ex, bottom=0.2ex, 
left=0.1ex,right=0.1ex,
overlay={\fill[blue!10] (frame.south west) to[bend left] 
 (frame.north west) --  (frame.north east) to[bend left]
  (frame.south east) -- cycle;},
boxrule=0pt},
highlight math style=red eqbox}
\newcommand{\diff}{\mathop{}\!\mathrm{d}}
\begin{document}
\begin{empheq}[box=\tcbhighmath]{equation}
\int x \,e^{-x}\,\diff x
\end{empheq}

\begin{align}
\tcbhighmath{\int x \,e^{-x}\,\diff x}~&=
\left.\int x \,e^{-ax}\,\diff x\right|_{a=1}
\notag\\
&=
\left[-\frac{\diff}{\diff a}
\int e^{-ax}\,\diff x\right]_{a=1}
=\left[\frac{\diff}{\diff a}\frac{e^{-ax}}{a}\right]_{a=1}
\notag\\
&=~\tcbhighmath[blue eqbox]{-(1+x)e^{-x}}
\end{align}
\end{document}

enter image description here

You can always change highlight math style to change the appearance.

9
  • 1
    @antshar Sure. I added an example.
    – user194703
    May 14, 2020 at 18:08
  • 1
    @antshar Sure, the top padding is stored in top and so on. I used these keys to make the boxes tighter. You can change the dimensions as you like.
    – user194703
    May 14, 2020 at 18:23
  • 1
    @antshar\tcbhighmath[.style={top=5ex}] is not a working syntax, yes. You need to say something like \tcbhighmath[blue eqbox,{top=2ex}]{-(1+x)e^{-x}}. Please also consider the fact that I really tried to answer your original question, which I think I did. Comments are not meant to be a chat.
    – user194703
    May 14, 2020 at 18:37
  • 1
    Yes, perfect now! Thank you so much. You really did answer the original question and I really appreciate the help with additional questions. I understand that it isn't a chat, by the way where can I contact you?
    – antshar
    May 14, 2020 at 18:40
  • 1
    @antshar I am about to go to a meeting. (And it is the choice of many users like myself not to provide any contact information. That way we can decouple whenever we think it is necessary.)
    – user194703
    May 14, 2020 at 20:35

You must log in to answer this question.

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