Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

With a recent TeX distribution, the easy answer to this question is "load the sansmathaccent package" (which is Ariel's implementation of my answer). Actually, the corrected font should be loaded automatically by beamer, but somehow this doesn't work at the moment.


I just went to a math conference where I saw lots of slides prepared with the beamer class that contained badly positioned math accents like these: . The LaTeX file is

\documentclass{beamer}
\begin{document}
\begin{frame}{}
$\tilde M$ $\dot u$ $\hat T$
\end{frame}
\end{document}

As you can see, the accents are centered over the bases of the corresponding letters, i.e., the skew of the letters isn't taken into account. I'm pretty sure that the reason for this is missing entries in the kerning table of the standard math font; see also the discussion of the \skewchar in this post.

I know that one option would be to try other fonts, but I don't like this for two reasons: Firstly, I otherwise do like the appearance of the standard fonts, and secondly, if I use different fonts, then I'll still have to live with looking at the slides of all the others who use the standard fonts. So my questions are: Does there exist a fix that gives me well-behaved standard fonts with beamer, and is there hope that the above LaTeX file will yield correctly positioned accents in some future version of beamer? (I think it wouldn't be a problem to make such a change in the fonts of the class as it won't affect the bounding box of, e.g. \dot u, so it wouldn't lead to any changes in spacing, line breaks and page breaks.)

share|improve this question
1  
+1 Yeah! That also annoys me to no end. My personal "solution" to it has been to avoid math accents as much as possible when using Beamer. I would love it if someone has an answer. –  Willie Wong Oct 16 '10 at 14:09
1  
@Willie Wong: Since avoiding math talks as much as possible is not a viable solution, I'll probably notify the beamer maintainers, as proposed by Khaled. –  Hendrik Vogt Oct 17 '10 at 7:59
    
@Willie: I went ahead and talked to Joseph Wright; you can find a preliminary result below. –  Hendrik Vogt Dec 22 '10 at 14:40
    
@Willie: I recently saw the first beamer talk with properly placed accents! –  Hendrik Vogt Sep 9 '12 at 14:32
    
@HendrikVogt With TeXLive 2012 and the latest version of beamer, should we still use the package sansmathaccent? –  Paul Gaborit Sep 9 '12 at 15:48
show 10 more comments

6 Answers

You can use the \skew macro:

\skew{shift}{accent}{character}

Specifically, I would define macros for the symbols. So they can easily be adjusted later, especially if a font change occurs.

\newcommand*{\Mtilde}{\skew{5}{\tilde}{M}}
\newcommand*{\That}{\skew{3}{\hat}{T}}
\newcommand*{\udot}{\skew{3}{\dot}{u}}

Gives in beamer:

alt text

share|improve this answer
    
Thanks, that's not a bad workaround. I'll still have to guess the amount of the skew, but at least the macro is easy to use. What a pity that other people won't use the workaround and I'll still have to see all these talks with misaligned accents. –  Hendrik Vogt Dec 21 '10 at 16:10
add comment
up vote 16 down vote accepted

OK, after talking to Joseph Wright I went ahead and wrote a patch for cmssi, which is the standard math font in beamer. The problem is that this font (computer modern sans serif italics) is designed as a text font, so it doesn't contain any information about positioning of accents. Compare these for before and after patching:

Now the answer (hopefully) is in its final version and ready for use. However, what I'm going to write will only work on Unix type systems. Strangely enough, the patch I initially wrote for 10pt works also great for the other sizes.

Here's what you have to do in order to obtain nicely positioned accents. No change to the actual TeX files is needed, and nothing in the output will change except the accent positions. OK, create some testing directory and run the following script. (If you have root rights on your system, you probably want to replace the updmap command with updmap-sys; thanks, Herbert! Moreover, the map file that gets deleted in the end should probably be stored at some proper location, but I'm not sure where.)

# Create the patch file:
echo '17a18,61
>    (LABEL C E)
>    (LABEL C H)
>    (LABEL C M)
>    (LABEL C N)
>    (LABEL C Q)
>    (LABEL C i)
>    (LABEL C j)
>    (KRN O 177 R 0.1)
>    (STOP)
>    (LABEL C J)
>    (KRN O 177 R 0.22)
>    (STOP)
>    (LABEL C e)
>    (LABEL C m)
>    (LABEL C n)
>    (LABEL C r)
>    (LABEL C B)
>    (LABEL C R)
>    (LABEL C S)
>    (LABEL C Z)
>    (KRN O 177 R 0.08)
>    (STOP)
>    (LABEL C c)
>    (LABEL C q)
>    (LABEL C s)
>    (LABEL C z)
>    (KRN O 177 R 0.06)
>    (STOP)
>    (LABEL C v)
>    (LABEL C x)
>    (KRN O 177 R 0.04)
>    (STOP)
>    (LABEL C h)
>    (KRN O 177 R 0.02)
>    (STOP)
>    (LABEL C l)
>    (LABEL C U)
>    (KRN O 177 R 0.11)
>    (STOP)
>    (LABEL C d)
>    (LABEL C C)
>    (LABEL C G)
>    (KRN O 177 R 0.12)
>    (STOP)
25a70
>    (KRN O 177 R 0.1)
61a107
>    (KRN O 177 R 0.04)
62a109
>    (KRN O 177 R 0.03)
68a116
>    (KRN O 177 R 0.08)
70a119
>    (KRN O 177 R 0.04)
77a127
>    (KRN O 177 R 0.1)
79a130
>    (KRN O 177 R 0.07)
86a138
>    (KRN O 177 R 0.08)
87a140
>    (KRN O 177 R 0.06)
93a147
>    (KRN O 177 R 0.09)
95a150
>    (KRN O 177 R 0.06)
103a159
>    (KRN O 177 R 0.08)
104a161
>    (KRN O 177 R 0.1)
111a169
>    (KRN O 177 R 0.05)
112a171
>    (KRN O 177 R 0.06)
120a180
>    (KRN O 177 R 0.08)
122a183
>    (KRN O 177 R 0.07)
124a186
>    (KRN O 177 R 0.08)
127a190
>    (KRN O 177 R 0.14)
134a198
>    (KRN O 177 R 0.05)
140a205
>    (KRN O 177 R 0.01)
143a209
>    (KRN O 177 R 0.1)' > cmssi.patch
# Patch the font metrics of cmssi8, 9, 10, 12 and 17:
for i in 8 9 10 12 17; do
tftopl $(kpsewhich cmssi$i.tfm) > cmssmi$i.pl
patch cmssmi$i.pl cmssi.patch
pltotf cmssmi$i.pl
done
# Include the patched font in beamerbasefont.sty and define its \skewchar:
cp $(kpsewhich beamerbasefont.sty) newbeamerbasefont.sty
sed '
/{OT1}{cmss}{m}{it}/,/{}/{
s|cmssi|cmssmi|g
s|{}|{\\skewchar\\font=127}|}
' newbeamerbasefont.sty > beamerbasefont.sty
# Make the font metric available to the system:
echo 'cmssmi8 cmssmi8 <cmssi8.pfb
cmssmi9 cmssmi9 <cmssi9.pfb
cmssmi10 cmssmi10 <cmssi10.pfb
cmssmi12 cmssmi12 <cmssi12.pfb
cmssmi17 cmssmi17 <cmssi17.pfb' > cmssmi.map
updmap --enable Map=cmssmi.map
# clean up:
rm cmssi.patch cmssmi{8,9,10,12,17}.pl newbeamerbasefont.sty cmssmi.map

This creates six files: five tfm files named cmssmi<n>.tfm , which contain the patched font metrics, and beamerbasefont.sty, which will be used instead of the original beamerbasefont.sty. (I thought that cmssmi is nice for "computer modern sans serif math italics".) Now you're ready to go and test the following example TeX file. This should go into the same testing directory since the above six files are only available there. Feedback is highly appreciated!

\documentclass{beamer}
\newcommand\test{}
\newcommand\testframe[1]{
\renewcommand\test[1]{{$#1 ##1_{{#1 ##1_{#1 ##1}}}$} }
\begin{frame}{}
\test a
\test b
\test c
\test d
\test e
\test f
\test g
\test h
\test i
\test j
\test k
\test l
\test m
\test n
\test o
\test p
\test q
\test r
\test s
\test t
\test u
\test v
\test w
\test x
\test y
\test z
\test A
\test B
\test C
\test D
\test E
\test F
\test G
\test H
\test I
\test J
\test K
\test L
\test M
\test N
\test O
\test P
\test Q
\test R
\test S
\test T
\test U
\test V
\test W
\test X
\test Y
\test Z
\end{frame}
}

\begin{document}
\renewcommand{\baselinestretch}{1.4}\normalsize
\testframe{\dot}
\testframe{\hat}
\testframe{\tilde}
\testframe{\bar}
\end{document}
share|improve this answer
    
Hendrik: Your solution works beautifully on UNIX-type systems. Would you mind if I turned it into a fonts package and uploaded it to CTAN? –  user13668 Apr 25 '12 at 23:53
    
@Ariel: I'd be happy if you do that. My original hope had been that this would just be included into the standard beamer package, but my report on the beamer issue tracker has been unresolved for more than a year now. So please go ahead and upload it to CTAN, that would be a great step in the right direction! –  Hendrik Vogt Apr 26 '12 at 11:07
    
Done; it is on CTAN under the name "sansmathaccent" (ctan.org/pkg/sansmathaccent). (I apologize for posting this in the wrong place, but as far as I can tell, I haven't been using stackexchange long enough to actually make comments.) –  user13668 Apr 29 '12 at 16:56
    
Thanks, @Ariel. –  Hendrik Vogt May 3 '12 at 11:06
add comment

Apparently the default beamer font is not suitable font for quality math typesetting (lacking proper accent positioning is one aspect, but I suspect there are more).

There is no way to fix this except by using a proper math font, see this for samples of different math fonts with beamer. Of course, it would be much better if beamer maintainers were notified to set a better font by default.

share|improve this answer
1  
I don't think Beamer does set a particular font. It just sets the font family to sans serif, so you get CMSS. I'm not sure it's good practice for a general-use document class to pick a nonstandard (and hence, not guaranteed to exist) font for the user. The class does offer an option \usefonttheme[onlymath]{serif} to revert to normal math. –  frabjous Oct 16 '10 at 14:20
    
This is a "particular font" in my book, CM is the default LaTeX font, so CMSS is the default sans serif font; it is not just a random sans serif font. And since the question is about the default behaviour, which is a legitimate request IMO, I think some one have to discuss this beamer maintainers. Of course fixing the actual font is much better, but I don't think one is allowed to touch CM and keep calling it CM. –  Khaled Hosny Oct 16 '10 at 14:36
    
@frabjous: I think I was in some talks where people did use \usefonttheme[onlymath]{serif}, and I would say that the normal serif math font does not go well with the sans serif text font. –  Hendrik Vogt Oct 16 '10 at 16:58
    
The pdf file you give in your link has an interesting list of fonts, but the only sans serif math font with proper accent positioning I found there is CMBright, which seems too thin to me (as also mentioned on page 6 of the pdf file). What a pity! –  Hendrik Vogt Oct 16 '10 at 17:32
add comment

I suggest using

\usefonttheme{professionalfonts}

in the preamble. This turns the math-fonts into serif ones, so that you have a better visual separation between math and normal text. And it gives you proper math fonts.

share|improve this answer
    
Thanks for your answer, but see my comment to dan's answer. –  Hendrik Vogt Jan 5 '11 at 15:29
add comment

I find sans-serif fonts ugly for talks. They are hard to read in books, so I don't see any reason to use them in talks, either. The following looks reasonably good to me. (I also slightly adjusted the accenting commands.)

\documentclass[serif]{beamer}
\usepackage{mathptmx}
\usepackage{helvet}
\usepackage{courier}
\begin{document}
\begin{frame}{}
$\widetilde{M}$ $\dot u$ $\widehat{T}$
\end{frame}
\end{document}
share|improve this answer
1  
In the moment I can't give a particular reason for using sans serif fonts in talks, but that's what people recommend, and I like it. By the way, the positioning of the accents in your example file is only slightly better than in mine. (Regarding adjusted accenting commands: I used \tilde and \hat above since this is what I saw in the talks.) –  Hendrik Vogt Oct 18 '10 at 5:36
    
Sans-serif are recommended (by some) for short texts, like headlines, logos etc. So it makes sense to use them for presentations, which don't have much running text usually. –  Martin Scharrer Apr 26 '12 at 6:32
add comment

I use

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usefonttheme[stillsansserifsmall]{serif}

and also experience bad positioning of math accents. I use a quick and dirty hack to make some corrections which in most cases work:

\let\oldtilde\tilde
\renewcommand{\tilde}[1]{\,\oldtilde{\!#1}}

\let\oldoverline\overline
\renewcommand{\overline}[1]{\hspace{1pt}\oldoverline{\hspace{-1pt}#1}}

\let\olddot\dot
\renewcommand{\dot}[1]{\,\olddot{\!#1}}

\let\oldhat\hat
\renewcommand{\hat}[1]{\,\oldhat{\!#1}}

Disclaimer: I know that this is not a good idea.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.