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$}
  • \colorbox is always rectangular, look at packages such as tcolorbox which has many many options for fancier boxes – David Carlisle May 14 '20 at 17:54

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

\tcbset{red eqbox/.style={enhanced,top=0.2ex, bottom=0.2ex, 
overlay={\fill[red!10] (frame.south west) to[bend left] 
 (frame.north west) --  (frame.north east) to[bend left]
  (frame.south east) -- cycle;},
blue eqbox/.style={enhanced,top=0.2ex, bottom=0.2ex, 
overlay={\fill[blue!10] (frame.south west) to[bend left] 
 (frame.north west) --  (frame.north east) to[bend left]
  (frame.south east) -- cycle;},
highlight math style=red eqbox}
\int x \,e^{-x}\,\diff x

\tcbhighmath{\int x \,e^{-x}\,\diff x}~&=
\left.\int x \,e^{-ax}\,\diff x\right|_{a=1}
\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}
&=~\tcbhighmath[blue eqbox]{-(1+x)e^{-x}}

enter image description here

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

  • 1
    @antshar Sure. I added an example. – user194703 May 14 '20 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 '20 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 '20 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 '20 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 '20 at 20:35

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.