# \underbrace{} choppy

Why are my underbraces so ugly? I've tried a few different fonts for the document and it appears it is font that determines the underbraces appearance. I however don't want to change my font. How can I make my underbraces not look so ugly?

I use the following packages (Edit by Caramdir: I removed all non-relevant packages from the list).

\usepackage{amssymb}
\usepackage{amsmath}


• I included the image for you. Please just add a direct link to it next time. A minimal example which shows the used packages and font would be very helpful. – Martin Scharrer Feb 26 '11 at 19:29
• what is ugly? – user2478 Feb 26 '11 at 19:34
• @Martin: I replaced the image by a link, so that Anthony can edit the question. – Caramdir Feb 26 '11 at 20:09
• @Caramdir: Does the included image prevent Anthony from editing his question as long as he hasn't got >10 rep, or will he just fall back to the link? If it's the latter, then I like it with the included image. – Hendrik Vogt Feb 27 '11 at 16:17
• @Hendrik: It will prevent him from saving until he changes it to a link. – Caramdir Feb 27 '11 at 17:13

I can answer the first part of the question: Why are the underbraces choppy? The reason is that latex constructs the underbrace (also overbraces) from glyphs from a font (for the curly parts) and TeX rules (for the straight parts). The TeX rules translate into PDF filled rectangles, so you are correct that it is not a piece of type. Due to some tricky aspects of how the PDF format works, it's not really possible to ensure that these different parts meet seamlessly in all PDF viewers at all zoom levels.

Large vertical delimiters in TeX avoid this problem by using repeated glyphs also for the straight parts, so that the whole brace is constructed from only glyphs (there can be some slight glitches at the joins, but it is usually much less noticeable).

As for your second question: There are a few ways to deal with this, but none are really satisfactory.

1. Use a different PDF viewer. Some of them use different drawing algorithms that make these glitches less obvious;
2. Use different setting for your current PDF viewer. For example in Adobe reader go to the "Page Display" preferences page and under "Rendering" set "Smooth line art"=ON and "Enhance thin lines"=OFF. (This will have other effects that you may or may not appreciate);
3. Program a different way to generate horizontal braces, more similar to how vertical braces are constructed. Maybe take a look at how latex builds horizontal arrows, for inspiration. This is also how MnSymbol makes underbraces:

4. Use a font that provides large horizontal braces (I know you didn't want to change fonts, but...). For example the (commercial) MathTime Professional 2 fonts have individually designed glyphs for braces up to 4inches wide. For example (taken from this webpage):

5. Don't worry about it: it will look absolutely fine when printed -- the problems with making the pieces match only apply to antialiased rendering at low resolution such as on a monitor (which PDF was not really designed for, originally). On the printed page (which PDF was designed for) they will match perfectly.
6. Construct the braces using something like TikZ. I'm sure this is easy enough, but I'm not a TikZ expert so I'll let someone else write this.

You may want to read what the mathtools manual has to say about LaTeX's implementation of \underbrace. Try \usepackage{mathtools} and see if you think the result is better.

• I still have some "ugly" output on some PDF readers. – Colas May 24 '16 at 15:22

If you only want the \underbrace command from the MnSymbol package but use the amsmath symbols otherwise, you can edit MnSymbol.sty to that effect. Copy the code below and paste it into a new text file. Save the file as MyMnSymbol.sty into the folder where your TeX document lives. In the preamble of your document, type \usepackage{MyMnSymbol} which then only redefines the \underbrace command.

\ProvidesPackage{MyMnSymbol}[2007/01/21 v1.4 Underbraces from MnSymbol]

\DeclareFontFamily{OMX}{MnSymbolE}{}
\DeclareSymbolFont{largesymbolsX}{OMX}{MnSymbolE}{m}{n}
\DeclareFontShape{OMX}{MnSymbolE}{m}{n}{
<-6>  MnSymbolE5
<6-7>  MnSymbolE6
<7-8>  MnSymbolE7
<8-9>  MnSymbolE8
<9-10> MnSymbolE9
<10-12> MnSymbolE10
<12->   MnSymbolE12}{}

\DeclareMathSymbol{\upbrace}      {\mathord}{largesymbolsX}{'256}
\DeclareMathSymbol{\upbraceg}     {\mathord}{largesymbolsX}{'257}
\DeclareMathSymbol{\upbracegg}    {\mathord}{largesymbolsX}{'260}
\DeclareMathSymbol{\upbraceggg}   {\mathord}{largesymbolsX}{'261}
\DeclareMathSymbol{\upbracegggg}  {\mathord}{largesymbolsX}{'262}
\DeclareMathSymbol{\bracelu}      {\mathord}{largesymbolsX}{'264}
\DeclareMathSymbol{\braceru}      {\mathord}{largesymbolsX}{'266}
\DeclareMathSymbol{\bracemu}      {\mathord}{largesymbolsX}{'270}
\DeclareMathSymbol{\bracemid}     {\mathord}{largesymbolsX}{'271}

\def\horiz@expandable#1#2#3#4#5#6#7#8{%
\@mathmeasure\z@#7{#8}%
\@tempdima=\wd\z@
\@mathmeasure\z@#7{#1}%
\ifdim\noexpand\wd\z@>\@tempdima
$\m@th#7#1$%
\else
\@mathmeasure\z@#7{#2}%
\ifdim\noexpand\wd\z@>\@tempdima
$\m@th#7#2$%
\else
\@mathmeasure\z@#7{#3}%
\ifdim\noexpand\wd\z@>\@tempdima
$\m@th#7#3$%
\else
\@mathmeasure\z@#7{#4}%
\ifdim\noexpand\wd\z@>\@tempdima
$\m@th#7#4$%
\else
\@mathmeasure\z@#7{#5}%
\ifdim\noexpand\wd\z@>\@tempdima
$\m@th#7#5$%
\else
#6#7%
\fi
\fi
\fi
\fi
\fi}

\def\underbrace@expandable#1#2#3{\vtop{\m@th\ialign{##\crcr
$\m@th\hfil#2#3\hfil$\crcr
\noalign{\kern2\p@\nointerlineskip}%
#1#2{#3}\crcr}}}

\def\underbrace@#1#2#3{\vtop{\m@th\ialign{##\crcr
$\m@th\hfil#2#3\hfil$\crcr
\noalign{\kern2\p@\nointerlineskip}%
#1#2\crcr}}}

\def\bracefill@#1#2#3#4#5{$\m@th#5#1\leaders\hbox{$#4$}\hfill#2\leaders\hbox{$#4$}\hfill#3$}
\def\upbracefill@{\bracefill@\bracelu\bracemu\braceru\bracemid}

\def\upbrace@expandable{%
\horiz@expandable
\upbrace
\upbraceg
\upbracegg
\upbraceggg
\upbracegggg
\upbracefill@}

\DeclareRobustCommand{\underbrace}[1]{\mathop{\mathpalette{\underbrace@expandable\upbrace@expandable}{#1}}\limits}

• I really like your answer, but would it be possible to provide the way to include also the overbrace please ? Thank you ! – tobiasBora Jan 6 '17 at 3:01

I use tikz for this. In addition, I made my own edition of “brace” decoration to be plain without sharp middle part

\pgfdeclaredecoration{plain brace}{brace}
{%
\state{brace}[width=+\pgfdecoratedremainingdistance, next state=final]
{%
\pgfpathmoveto{\pgfpointorigin}%
{%
\pgfpathcurveto%
{\pgfqpoint{.15\pgfdecorationsegmentamplitude}{.3\pgfdecorationsegmentamplitude}}%
{\pgfqpoint{.5\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}%
{\pgfqpoint{\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}%
}%
\pgftransformxshift{+\pgfdecoratedremainingdistance}%
\pgfpathlineto{\pgfqpoint{-\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}%
{%
\pgfpathcurveto%
{\pgfqpoint{-.5\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}%
{\pgfqpoint{-.15\pgfdecorationsegmentamplitude}{.3\pgfdecorationsegmentamplitude}}%
{\pgfqpoint{0\pgfdecorationsegmentamplitude}{0\pgfdecorationsegmentamplitude}}%
}%
}%
\state{final}{}%
}


That’s how it looks with aoverbrace & aunderbrace from package abraces

And that’s how it looks with tikz

Much nicer, isn’t it?

Plus for tikz braces you may specify any width of line, various styles of line like dashing [line cap=round, dash pattern=on 0pt off 1.6\pgflinewidth], color of line, color of text, and many more

Full code follows

\documentclass[11pt,twoside]{book}

\usepackage[utf8]{inputenc}

\usepackage{geometry}
\geometry{papersize={145mm,200mm}} % 60x84/16 is 145 mm x 200 mm
\geometry{tmargin=1.5cm,bmargin=1.5cm,lmargin=1.5cm,rmargin=1.5cm}

\usepackage{bm} % bold math symbols

\usepackage{amsmath}

\usepackage{accents}
\makeatletter
\newcommand{\sdotabove}{%
\hbox{\fontfamily{lmr}\fontsize{.5\dimexpr(\f@size pt)}{0}\selectfont$\,\bullet$}}
\DeclareRobustCommand{\mathdotabove}{\accentset{\sdotabove}}
\newcommand{\sdotdotabove}{%
\hbox{\fontfamily{lmr}\fontsize{.5\dimexpr(\f@size pt)}{0}\selectfont$\,\bullet\hspace{-0.25ex}\bullet$}}
\DeclareRobustCommand{\mathdotdotabove}{\accentset{\sdotdotabove}}
\makeatother

\usepackage{xargs}
\usepackage{xparse}

\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing,decorations.markings}

\pgfdeclaredecoration{plain brace}{brace}
{%
\state{brace}[width=+\pgfdecoratedremainingdistance, next state=final]
{%
\pgfpathmoveto{\pgfpointorigin}%
{%
\pgfpathcurveto%
{\pgfqpoint{.15\pgfdecorationsegmentamplitude}{.3\pgfdecorationsegmentamplitude}}%
{\pgfqpoint{.5\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}%
{\pgfqpoint{\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}%
}%
\pgftransformxshift{+\pgfdecoratedremainingdistance}%
\pgfpathlineto{\pgfqpoint{-\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}%
{%
\pgfpathcurveto%
{\pgfqpoint{-.5\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}%
{\pgfqpoint{-.15\pgfdecorationsegmentamplitude}{.3\pgfdecorationsegmentamplitude}}%
{\pgfqpoint{0\pgfdecorationsegmentamplitude}{0\pgfdecorationsegmentamplitude}}%
}%
}%
\state{final}{}%
}

\newcommand{\tikzmark}[1]{\tikz[overlay, remember picture] \node (#1) {};}

% tweak these if you wish
\newcommand*{\BraceAmplitude}{0.4em}%
\newcommand*{\VerticalOffset}{0.64ex}%
\newcommand*{\HorizontalOffset}{0em}%
\newcommand*{\TextOffset}{0.5ex}%

O{} % #1 = draw options
O{} % #2 = optional brace options
m   % #3 = left tikzmark
m   % #4 = right tikzmark
m   % #5 = text to place underbrace
}{%
\begin{tikzpicture}[overlay, remember picture]
\draw [decoration={plain brace, amplitude=\BraceAmplitude, #2}, decorate, thick, draw=black!80, text=black, #1]
($(#4.base) + (\HorizontalOffset,-\VerticalOffset)$) --
($(#3.base) + (-\HorizontalOffset,-\VerticalOffset)$)
node [below=\TextOffset, midway] {#5};
\end{tikzpicture}%
}

O{} % #1 = draw options
O{} % #2 = optional brace options
m   % #3 = left tikzmark
m   % #4 = right tikzmark
m   % #5 = text to place underbrace
}{%
\begin{tikzpicture}[overlay, remember picture]
\draw [decoration={plain brace, amplitude=\BraceAmplitude, mirror, #2}, decorate, thick, draw=black!80, text=black, #1]
($(#4.north) + (\HorizontalOffset,\VerticalOffset+0.25em)$) --
($(#3.north) + (-\HorizontalOffset,\VerticalOffset+0.25em)$)
node [above=\TextOffset, midway] {#5};
\end{tikzpicture}%
}

\newcommandx*{\tikzcancel}[2][1=black]{%
\tikz[baseline=(tocancel.base)]{%
\node[inner sep=-1pt,outer sep=0pt] (tocancel) {#2};
\draw[line width=0.25mm,#1] (tocancel.south west) -- (tocancel.north east);
}%
}

\newcommandx*{\tikzbackcancel}[2][1=black]{%
\tikz[baseline=(tocancel.base)]{%
\node[inner sep=-1pt,outer sep=0pt] (tocancel) {#2};
\draw[line width=0.25mm,#1] (tocancel.south east) -- (tocancel.north west);
}%
}

\newcommandx*{\tikzcrosscancel}[2][1=black]{%
\tikz[baseline=(tocancel.base)]{%
\node[inner sep=-1pt,outer sep=0pt] (tocancel) {#2};
\draw[line width=0.25mm,#1] (tocancel.south west) -- (tocancel.north east);
\draw[line width=0.25mm,#1] (tocancel.south east) -- (tocancel.north west);
}%
}

\usepackage{abraces}

\usepackage{verbatim}

\pagestyle{empty}

\begin{document}

$\begin{array}{r@{\hspace{0.33em}}c@{\hspace{0.25em}}l} \mathdotabove{\bm{P}} \hspace{0.2em} & = & \hspace{0.1em} \{\bm{P}^{\mathsf{\hspace{0.12ex}S}} \hspace{-0.2ex} + \bm{P}^{\mathsf{\hspace{0.12ex}A}}\}^{\hspace{-0.1ex}\tikz[baseline=-0.9ex]\draw[black,fill=black] (0,0) circle (.32ex);} \hspace{0.1em} = \hspace{0.1em} \{{\hspace{0.2ex} \aoverbrace[L1R]{\bm{E} \operatorname{cos} \vartheta + \bm{k} \bm{k} \left({1 \!-\! \operatorname{cos} \vartheta}\right)}^{\bm{P}^{\mathsf{\hspace{0.12ex}S}}} \,+\, \aoverbrace[L1R]{\bm{k} \hspace{-0.24ex}\times\hspace{-0.4ex} \bm{E} \operatorname{sin} \vartheta \hspace{0.2ex}}^{\bm{P}^{\mathsf{\hspace{0.12ex}A}}} \hspace{0.1ex}}\}^{\hspace{-0.1ex}\tikz[baseline=-0.9ex]\draw[black,fill=black] (0,0) circle (.32ex);} \hspace{0.1em} = \\[0.5em] % & = & \hspace{0.2em} \aunderbrace[l1r]{\left( \hspace{0.1ex} \bm{k} \bm{k} \hspace{-0.1ex} - \hspace{-0.2ex} \bm{E} \hspace{0.1ex} \right) \hspace{-0.1ex} \mathdotabove{\vartheta} \operatorname{sin} \vartheta + \hspace{-0.2ex} ( \bm{k} \mathdotabove{\bm{k}} + \mathdotabove{\bm{k}} \bm{k} ) \hspace{-0.2ex} \left({1 \!-\! \operatorname{cos} \vartheta}\right)}_{\mathdotabove{\bm{P}}^{\mathsf{\hspace{0.12ex}S}}} \hspace{0.32ex} + \\[-0.8em] & & \hspace{12.5em} + \hspace{0.5ex} \aunderbrace[l1r]{\hspace{0.12ex} \bm{k} \hspace{-0.24ex}\times\hspace{-0.4ex} \bm{E} \hspace{0.4ex} \mathdotabove{\vartheta} \operatorname{cos} \vartheta + \mathdotabove{\bm{k}} \hspace{-0.24ex}\times\hspace{-0.4ex} \bm{E} \operatorname{sin} \vartheta}_{\mathdotabove{\bm{P}}^{\mathsf{\hspace{0.12ex}A}}} \hspace{-0.1em}. \end{array}$

\vspace{-0.5em}

$\begin{array}{r@{\hspace{0.33em}}c@{\hspace{0.25em}}l} \mathdotabove{\bm{P}} \hspace{0.2em} & = & \hspace{0.1em} \{\bm{P}^{\mathsf{\hspace{0.12ex}S}} \hspace{-0.2ex} + \bm{P}^{\mathsf{\hspace{0.12ex}A}}\}^{\hspace{-0.1ex}\tikz[baseline=-0.9ex]\draw[black,fill=black] (0,0) circle (.32ex);} \hspace{0.1em} = \hspace{0.1em} \{{\hspace{0.2ex} \tikzmark{StartBracePs} {\bm{E} \operatorname{cos} \vartheta + \bm{k} \bm{k} \left({1 \!-\! \operatorname{cos} \vartheta}\right)} \tikzmark{EndBracePs} \hspace{0.2ex} + \hspace{0.2ex} \tikzmark{StartBracePa} {\bm{k} \hspace{-0.24ex}\times\hspace{-0.4ex} \bm{E} \operatorname{sin} \vartheta \hspace{0.2ex}} \tikzmark{EndBracePa} {} \hspace{0.1ex}}\}^{\hspace{-0.1ex}\tikz[baseline=-0.9ex]\draw[black,fill=black] (0,0) circle (.32ex);} \hspace{0.1em} = \\[0.4em] % & = & \hspace{0.2em} \tikzmark{StartBraceDotPs} {\left( \hspace{0.1ex} \bm{k} \bm{k} \hspace{-0.1ex} - \hspace{-0.2ex} \bm{E} \hspace{0.1ex} \right) \hspace{-0.1ex} \mathdotabove{\vartheta} \operatorname{sin} \vartheta + \hspace{-0.2ex} ( \bm{k} \mathdotabove{\bm{k}} + \mathdotabove{\bm{k}} \bm{k} ) \hspace{-0.2ex} \left({1 \!-\! \operatorname{cos} \vartheta}\right)} \tikzmark{EndBraceDotPs} \hspace{0.64ex} + \\[0.64em] & & \hspace{12.5em} + \hspace{0.72ex} \tikzmark{StartBraceDotPa} {\hspace{0.12ex} \bm{k} \hspace{-0.24ex}\times\hspace{-0.4ex} \bm{E} \hspace{0.4ex} \mathdotabove{\vartheta} \operatorname{cos} \vartheta + \mathdotabove{\bm{k}} \hspace{-0.24ex}\times\hspace{-0.4ex} \bm{E} \operatorname{sin} \vartheta} \tikzmark{EndBraceDotPa} \hspace{0.1em}. \end{array}$

%%[line cap=round, dash pattern=on 0pt off 1.6\pgflinewidth]
\AddOverBrace[line width=0.75pt]{StartBracePs}{EndBracePs}{${\scriptstyle \bm{P}^{\mathsf{\hspace{0.12ex}S}}}$}
\AddOverBrace[line width=0.75pt]{StartBracePa}{EndBracePa}{${\scriptstyle \bm{P}^{\mathsf{\hspace{0.12ex}A}}}$}

\AddUnderBrace[line width=0.75pt]{StartBraceDotPs}{EndBraceDotPs}{${\scriptstyle \mathdotabove{\bm{P}}^{\mathsf{\hspace{0.12ex}S}}}$}

\AddUnderBrace[line width=0.75pt]{StartBraceDotPa}{EndBraceDotPa}{${\scriptstyle \mathdotabove{\bm{P}}^{\mathsf{\hspace{0.12ex}A}}}$}

\end{document}