# \underbrace symbol is wrong

Hey guys, I tried to google the solution, but I didn't find any solution to this. I am using beamer,xelatex to prepare a slide. When I use \underbrace, the brace doesn't show, instead, a crappy symbol is out there. As I am a new user, the image is here:

the package I used here is

\usepackage{lastpage}
\usepackage{graphicx,graphics}
\usepackage{hyperref}
\usepackage{amssymb}
\usepackage{url}
\usepackage{fancyhdr}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{fontspec,xltxtra,xunicode}
\usepackage{unicode-math}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{mathtools}
%\defaultfontfeatures{Mapping=tex-text}
\setromanfont[Mapping=tex-text]{Hoefler Text}
\setsansfont[Scale=MatchLowercase,Mapping=tex-text]{Gill Sans}
\setmonofont[Scale=MatchLowercase]{Andale Mono}
\setmathfont{Cambria Math}

Thank you in advance. I think the problem might be the font.

@Matthew, The minimal file is here: The buggy page

The version of XeLaTeX is,

XeTeX 3.1415926-2.2-0.9997.4 (TeX Live 2010)
kpathsea version 6.0.0
Copyright 2010 SIL International and Jonathan Kew.
There is NO warranty.  Redistribution of this software is
covered by the terms of both the XeTeX copyright and
the Lesser GNU General Public License.
named COPYING and the XeTeX source.
Primary author of XeTeX: Jonathan Kew.
Compiled with ICU version 4.4 [with modifications for XeTeX]
Compiled with zlib version 1.2.3; using 1.2.3
Compiled with FreeType2 version 2.3.11; using 2.3.11
Using Mac OS X Carbon, Cocoa & QuickTime frameworks
-
You really ought to trim your package list a bit to remove all the duplicates. I trimmed your package list a bit, and inserted the image. If you need to edit the text of the question, since you don't have enough rep, you won't be able to save the question with the image included. To fix that, just remove the ! from in front of the square brackets of the image link. Then you will be able to save the edits and someone else can re-insert the image. –  Willie Wong Mar 25 '11 at 13:46
Thank you...I will keep in mind. I asked some of my colleagues about this issue, and they still don't know. It's weird... –  Hotloo Xiranood Mar 25 '11 at 13:52
That's weird: I use xelatex and beamer every day and I haven't noticed this problem with underbrace. Could you post a complete, minimal example that demonstrates the problem? That would be a beamer latex file with the fewest number of packages and the code for your sample? –  Matthew Leingang Mar 25 '11 at 16:09
@Matthew: This is a unicode-math bug, not a beamer bug (or maybe a XeTeX bug that only surfaces with unicode-math, ask Will). –  Caramdir Mar 25 '11 at 17:18
@Caramdir: I see. That makes sense since I haven't been using unicode-math. –  Matthew Leingang Mar 25 '11 at 19:11

I'm afraid this is a known problem and I don't have a workaround for you at the moment. Would it be possible for you to use LuaLaTeX instead of XeLaTeX?

-
Are they gonna fix in the future release? Ahhh...I can perhaps send a bug to somewhere, right? Well, I don't think I am gonna use LuaLaTeX because I don't have time to reformulate it to that format, but anyway, I will tell my audience about this bug...Thank you So much! –  Hotloo Xiranood Mar 25 '11 at 15:26
@Hotloo: As long as you don't use polyglossia (or any other XeTeX-specific package), compiling with lualatex should work fine. Of course LuaTeX+unicode-math has its own set of annoying issuses. :( –  Caramdir Mar 25 '11 at 17:25
What about the plain XeTeX solution you mention on the bug tracker? –  Caramdir Mar 25 '11 at 17:27
@Caramdir — No time, no time! –  Will Robertson Mar 28 '11 at 10:22

As you're already using so many packages (!), perhaps you wouldn't mind adding one more to the list as a temporary fix to get you an underbrace whilst the experts work on squashing the bug. The package in question is TikZ. Here's a drop-in replacement for \underbrace:

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\makeatletter
\def\underbrace#1{\@ifnextchar_{\tikz@@underbrace{#1}}{\tikz@@underbrace{#1}_{}}}
\def\tikz@@underbrace#1_#2{\tikz[baseline=(a.east)] {\node (a) {$$#1$$}; \draw[ultra thick,line cap=round,decorate,decoration={brace,amplitude=5pt}] (a.south east) -- node[below,inner sep=7pt] {$$\scriptstyle #2$$} (a.south west);}}
\makeatother

And here is the result:

(When testing this, I commented out a load of your packages, and I had to use a different maths font; hopefully none of that will have made a difference to this command. The thickness can be customised.)

Here's the command "live" in your code:

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{fontspec,xltxtra,xunicode}
\usepackage{unicode-math}
\usepackage{mathtools}
\setmathfont{xits-math.otf}

\makeatletter
\def\underbrace#1{\@ifnextchar_{\tikz@@underbrace{#1}}{\tikz@@underbrace{#1}_{}}}
\def\tikz@@underbrace#1_#2{\tikz[baseline=(a.east)] {\node (a) {$$#1$$}; \draw[ultra thick,line cap=round,decorate,decoration={brace,amplitude=5pt}] (a.south east) -- node[below,inner sep=7pt] {$$\scriptstyle #2$$} (a.south west);}}
\makeatother

\begin{document}

\begin{frame}

\frametitle{Problem}

if we assume $g(x) = -k'(x)$, that is $G(\mathbf{x}) = c_{g,d}g(||\mathbf{x}||^2)$
$\hat{\nabla} f_{h,k}(\mathbf{x}) = \underbrace{\frac{2c_{k,d}}{nh^{d+2}} \left[ \sum_{i=1}^n g\left( \left|\left| \frac{\mathbf{x-x_i}}{h}\right|\right|^2\right)\right]}_{\mbox{\color{red} \hat{f}_{h,G}(\mathbf{x})}}\underbrace{\left[ \frac{\sum_{i=1}^n \mathbf{x_i} g\left( \left|\left| \frac{\mathbf{x-x_i}}{h}\right|\right|^2\right)}{ \sum_{i=1}^n g\left( \left|\left| \frac{\mathbf{x-x_i}}{h}\right|\right|^2\right)} - \mathbf{x}\right]}_{\color{red} \emph{\mbox{Mean Shift, \mathbf{m}_{h,G}(\mathbf{x})}}}$
which yields the mean shift update rule,
$\mathbf{m}_{h,G}(\mathbf{x}) = \frac{1}{2}h^2c \frac{\hat{\nabla}f_{h,K}(\mathbf{x})}{\hat{f}_{h,G}(\mathbf{x})} = \mathbf{y}_{j+1} - \mathbf{y}_j$
\end{frame}

\end{document}
-
Oh, I guess it should include a \displaystyle to set the correct mathematical environment inside. –  Andrew Stacey Mar 25 '11 at 20:15
Two small improvements: It should be baseline=(a.base) and I think it looks better with inner sep=0 for a (at least in normal-size mathematics). –  Caramdir Apr 3 '11 at 23:23
Hey Andrew, Good stuff! If you have a chance, would you mind explaining how the two definitions work? I really like how it results in a simple \underbrace command for the main document code. If I knew how this worked, I could also create braces on the right or left side of text I think. –  macmadness86 Jul 1 '12 at 8:07