Is there any way in TeX to highlight some part of a formula with a box having colored background and rounded corners?

At present, I need to export such formulas into an image, add those highlight boxes in GIMP, and import back into the document as an image. But this is a mess, and I need to redo all of that every time I change anything in these formulas :/ So it'd be better if I could mark up those fragments of my formulas in LaTeX natively. Is it possible?

I saw one example of boxes made with TikZ package, but I couldn't figure out how does it work and how to assimilate it into my own document. I don't want to make floating boxes inside a document, but just around a fragment of a formula to highlight it. (No, I cannot use text colors for that, because this text already has some colors which means something else, so I need to use background color instead.)

Edit 1
Here's the effect I'd like to achieve:

Edit 2
OK, after suggestions from A.Ellet below, I came out with the following code:

(I marked the line 24 with a comment.)
When I remove the \frac from inside the box and replace it by just x, it starts to work, but apparently from the formatting it seems to treat is as plain text instead of math.

I've just tried, but it creates ugly frame with fake shadow, no background, and no rounded corners, and I don't know how to control its appearance to fit it to my needs. Is there any documentation for this package? Could these boxes be parametrized? (colors, rounded corners, backgrounds, turn off fake shadows etc.)
–
SasQDec 28 '12 at 18:54

1

I believe you should better post a picture of the desired output. Without that, your intentions are not entirely clear.
–
yo'Dec 28 '12 at 19:09

1

@tohecz: I added a picture of what I'd like to get in my question, and a sample of code using fancybox which doesn't work.
–
SasQDec 28 '12 at 19:22

1

First, you should use \[...\] instead of $$...$$. The later is deprecated in LaTeX. Also, if you used some indentation, your code would be a little bit more readable. I've edited your code. The error was that you didn't switch back into mathmode within the \colorbox command.
–
A.EllettDec 28 '12 at 19:32

This looks closest to what I want to achieve. But I don't understand your code at all (what does all those numbers mean?). And it doesn't work with my texlive installation because of missing hf-tikz.sty file (I don't know how to install it correctly under Gentoo without breaking anything in my package manager when messing with the files by hand).
–
SasQDec 28 '12 at 20:42

I just wanted to add some boxy backgrounds, and now I have so many different options to choose, most of them not working at all, and some of them needing fiddling with my installation :-( The code to get it is a mess, I don't understand any single bit of it, and I cannot find any documentation on the Tikz's project page. All of this overwhelms me :-/ and seem to be lot more work than what I was doing so far with re-editing images of those formulas in GIMP, instead of simplifying things. So I'll probably be forced to revert to my old approach :-/ But thanks for all your help anyway.
–
SasQDec 28 '12 at 20:46

@SasQ: the package is quite recent (6 months), so it needs TeXLive 2012. The numbers simply represent the coordinates of the below right and above left corner of the box. If you visit ctan.org/tex-archive/graphics/pgf/contrib/hf-tikz you will find the documentation of the package in a pdf file. Unfortunately I don't know Gentoo, so I don't know how help you in updating the distribution or simply to install a single package.
–
Claudio FiandrinoDec 28 '12 at 20:58

I tried to add those files to a subdir into my texlive installation (/usr/share/texmf-dist/tex/latex) but it still doesn't see them. Do I need to edit some config files to let LaTeX know about them?
–
SasQDec 28 '12 at 21:04

As to the coordinates: This sounds very hacky anyway, because whenever I'll update something in the formula, I'll be required to update those coords I guess, which is not much an advantage over editting the image in GIMP anyway. Better solution would just mark which block of text needs to be surrounded by the box and update the size of the box automatically when I edit its content.
–
SasQDec 28 '12 at 21:07

Notice how I have to re-enter math mode within the various framing boxes. Also for the fraction, I had to declare \displaystyle inside the box to get the fraction to be formatted appropriately for an align environment.

OK, the last one seems quite similar to what I need to achieve. It just lacks the last feature: rounded corners.
–
SasQDec 28 '12 at 18:56

But from some strange reasons, it doesn't work with my LaTeX framework (LiveTex on Gentoo). It says that it cannot recognize my defined color (! LaTeX Error: Undefined color `MySubst!20'). This color is defined and it works for other things.
–
SasQDec 28 '12 at 19:07

Please post a MWE above so we can see what you're doing.
–
A.EllettDec 28 '12 at 19:08

Another problem: It seems to forget that it's in a math mode, because fonts are big and not italic for variables. Also, I cannot use \frac inside of it, because it throws parse errors concerning unpaired braces. Strange...
–
SasQDec 28 '12 at 19:09

This is a nice package, but it doesn't seem to work inside another math environment.
–
A.EllettDec 28 '12 at 19:25

@A.Ellett: You are right...I've just seen the edited question...
–
ThanosDec 28 '12 at 19:30

It also doesn't seem to work for my installation (texlive on Gentoo). It says that the package couldn't be found (! LaTeX Error: File mdframed.sty' not found`), and for now I don't know how to install it. Although I'm not a noob in the LaTeX syntax, I'm a complete noob in the maintaining own installation, packages & use those extensions in my code. I couldn't find any good documentations for the packages you're describing here.
–
SasQDec 28 '12 at 19:32