# Move a combining character with both \raisebox and \kern

The font I'm using, Linux Libertine O, is not able to properly combine a circumflex (U+0302) with a preceding vowel symbol that has a macron (e.g. U+014D):

\documentclass[17pt]{extarticle}
\usepackage{fontspec,xunicode,xltxtra}
\defaultfontfeatures{Mapping=tex-text}
\setmainfont{Linux Libertine O}
\newcommand{\schleifton}{\char"014D\char"0302}

\begin{document}
\textit{*-{\schleifton}z}.
\end{document}


I try to raise the circumflex with \raisebox:

\documentclass[17pt]{extarticle}
\usepackage{fontspec,xunicode,xltxtra}
\defaultfontfeatures{Mapping=tex-text}
\setmainfont{Linux Libertine O}
\newcommand{\schleifton}{\char"014D\raisebox{.3ex}{\char"0302}}

\begin{document}
\textit{*-{\schleifton}z}.
\end{document}


The circumflex is too far to the right, so I try to move it closer to the preceding character with \kern. The problem, as you can see, is that it also moves the following character (the 'z') to the left. How should I fix this?

\documentclass[17pt]{extarticle}
\usepackage{fontspec,xunicode,xltxtra}
\defaultfontfeatures{Mapping=tex-text}
\setmainfont{Linux Libertine O}
\newcommand{\schleifton}{\char"014D\kern-.1em\raisebox{.3ex}{\char"0302}}

\begin{document}
\textit{*-{\schleifton}z}.
\end{document}


As egreg points out in his answer, it is necessary to use \kern a second time to undo the leftward shifting of characters. He also points out, however, that using these commands will have slightly different outcomes for regular and slanted fonts. He suggests one way of taking care of that. Below, I have decided to just specify the regular and the slanted character separately:

\documentclass[17pt]{extarticle}
\usepackage{fontspec, xunicode, xltxtra}
\defaultfontfeatures{Mapping = tex-text}
\setmainfont{Linux Libertine O}
\newcommand{\schleifton}{\char"014D\kern-.11em\raisebox{.15ex}{\char"0302}\kern.11em}
\newcommand{\schleiftonitalic}{\char"014D\kern-.08em\raisebox{.25ex}{\char"0302}\kern.08em}

\begin{document}
\Huge{*-{\schleifton}z}.
\Huge\textit{*-{\schleiftonitalic}z}.
\end{document}


-
It seems to be a bug in Libertine, since with Junicode it's perfect. Add a kern also after the \raisebox. –  egreg Nov 22 '12 at 14:41
@egreg I know that the failure to add a circumflex to a preceding character with a macron is a feature of Libertine - I said that in the very first sentence of my post. But that doesn't address my question. I don't know what you mean by "add a kern also after the \raisebox". Where exactly? –  Sverre Nov 22 '12 at 14:50

## 1 Answer

You need to kern also after the inserted accent:

\newcommand{\schleifton}{%
\char"014D\kern-.1em\raisebox{.3ex}{\char"0302}\kern.1em }


However, by using a more complex definition, you can get a kern that takes into account also the slant of the current font. Here it is, with some samples.

\documentclass[17pt]{extarticle}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX}
\setmainfont{Linux Libertine O}
\makeatletter
\def\schkern#1{\kern#1\dimexpr0.11em-\strip@pt\fontdimen1\font\dimexpr0.1em\relax\relax}
\makeatother
\newcommand{\schleifton}{\char"014D\schkern{-}\raisebox{.3ex}{\char"0302}\schkern{+}}

\begin{document}
\textit{*-oz}.

\textit{*-{\schleifton}z}.

\schleifton

\Large

\textit{*-{\schleifton}z}.

\schleifton

\end{document}


What do we do? The idea is the same you had, but refined.

In \fontdimen1\font (Xe)TeX keeps the slant factor of the current font as a dimension in unit points, so with \strip@pt\fontdimen1\font we get the slant factor, let's simply call it σ.

We need to back up a bit, but then to advance a smaller bit, in order to take the slant into account. Thus the amount of the main backing up (found by trial and error) is 0.11em; the smaller amount turns out to be good as 0.1em multiplied by σ. Thus we back up by

0.11em - σ * 0.1em


In order to perform the second multiplication, we need to transform 0.1em into a TeX dimension, which is obtained by \dimexpr0.1em\relax. Thus we can write

0.11em - σ\dimexpr0.1em\relax


but in order to feed \kern with it we need another \dimexpr:

\kern\dimexpr 0.11em - σ\dimexpr0.1em\relax\relax


But we need also to undo the kerning after the accent, so \schkern is defined with an argument which is either + or -, the latter for backing up:

\def\schkern#1{\kern#1\dimexpr0.11em-\strip@pt\fontdimen1\font\dimexpr0.1em\relax\relax}


Thus \schkern{-} backs up, while \schkern{+} pushes forward.

-
I notice that if I don't include your more complex definition (using \kern-.1em), then the circumflex is a tiiiny bit further to the left in the \LARGE\textit example. Yours looks better. But I have no idea what your complex definition does. I'm especially interested in your dimexpr0.11em and dimexpr0.1em definitions. Are these standard/default measures, or are they the result of trial and error and need to be tweaked when used with other characters? –  Sverre Nov 22 '12 at 15:11
@Sverre I added some explanations. Do you need the circumflex also over other characters? –  egreg Nov 22 '12 at 15:24
+1 it's easier to tweak these things when you have the font:-) Actually I think I'll delete my answer. –  David Carlisle Nov 22 '12 at 15:25
@egreg I partly understood your explanation above. So you figure out how much you need to back up a character in the regular font (which you determined to be 0.11em), and then how much you need to do it with a slanted font (σ * 0.1em). All this through trial and error? So if I need to back up (or push forward) another character somewhere else, I can just slot in the two measures I determine to be appropriate into your command (and reverse \schkern{-} and \schkern{+} if I want to push forward instead)? –  Sverre Nov 22 '12 at 15:42