9

Usually when I apply kerning to a pair of characters, I undo the kerning by adding the negative of the kerning afterwards, i.e. {x}\kern1em\{y}\kern-1em (cf. Move a combining character with both \raisebox and \kern).

But in this case, I cannot undo the kerning. If I add the negative of the kerning afterwards, the following character is pushed away, but if I don't add it, the following character is drawn towards the previous character.

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Times New Roman}

\newcommand{\longa}{\char"0101}
\newcommand{\myacute}{\char"00B4}
\newcommand{\stressedlonga}{\longa\kern-.35em\raisebox{.35ex}{\myacute}\kern.35em}
\newcommand{\newstressedlonga}{\longa\kern-.35em\raisebox{.35ex}{\myacute}}
\begin{document}
\noindent{\stressedlonga}a\\ % characters are too far apart
aa\\ % this is the correct spacing between two characters
{\newstressedlonga}a % characters are too close together
\end{document}

enter image description here

EDIT


egreg is suggesting what I first attempted here, which was to add the combining acute accent U+0301 rather than the full-width character U+00B4. For reasons I fail to understand, however, as soon as I attempt to modify the placement of U+0301 (which I want to do in order to match U+1E53), the accent shifts rightwards, and nothing I do will make it move back. In the example below, I'm not kerning the accent at all, yet it shifts rightwards.

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Times New Roman}

\newcommand{\longa}{\char"0101}
\newcommand{\combiningacute}{\char"0301}
\newcommand{\stressedlonga}{\longa\raisebox{-.1ex}{\combiningacute}}

\begin{document}
\noindent{\stressedlonga}{\char"1E53}\\
{\longa\combiningacute}{\char"1E53}
\end{document}

enter image description here

2
  • The placement of combining characters is decided by the font designer.
    – egreg
    Nov 12, 2013 at 20:50
  • Sure. That default placement is seen in the lower example. But why does it shift rightwards when I try to lower it with raisebox- and why can't I move it leftwards again by adding kerning? In the question I link to, the default placement of the combining characters is off, but I have no difficulties modifying it with \kern and \raisebox - so what's going on in this case?
    – Sverre
    Nov 12, 2013 at 20:53

2 Answers 2

8

The problem is quite difficult. You can avoid adding manual kerning for compensating the superimposed accent, but you'll lose the normal kerning anyway.

TeX (like other typesetting systems) automatically applies kern between pairs of characters such as o and v; with Computer Modern fonts the width resulting from ov is 10pt, while the sum of the widths of the characters is 10.27782pt.

Solving the problem in full generality would mean doing a lookahead after each character in order to see whether \stressedlonga follows and, after this constructed character, a lookahead to see what letter follows, all in order to apply the kern that would be applied if the simple a were to be typeset.

Leaving the general problem alone, here's a solution for \stressedlonga that doesn't require knowing the width of the glyphs.

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Times New Roman}

\newcommand{\longa}{\char"0101}
\newcommand{\myacute}{\char"00B4}
\newcommand{\stressedlonga}{%
  \leavevmode\vbox{\offinterlineskip
    \ialign{##\cr
            \hidewidth\char"00B4\hidewidth\cr
            \noalign{\kern-1ex}
            \char"0101\cr}%
  }%
}


\begin{document}
\noindent
\stressedlonga a\\
aa
\end{document}

enter image description here

You can fine tune the placement of the accent by adding some kern: if you change the line

\hidewidth\char"00B4\hidewidth\cr

into

\hidewidth\kern0.05em\char"00B4\hidewidth\cr

you get

enter image description here

Of course there's always the possibility of using combining characters; I'll use the ^^^^ convention for inputting U+0301 COMBINING ACUTE ACCENT:

ā^^^^0301

produces

enter image description here


Some words on \ialign

The basic TeX function for alignments is \halign which of course is available also in LaTeX, being a primitive. Like LaTeX uses \tabcolsep for adding intercolumn space, \halign uses the value of \tabskip. Both Plain TeX and LaTeX define a wrapper around \halign to ensure \tabskip is zero:

% latex.ltx, line 494:
\def\ialign{\everycr{}\tabskip\z@skip\halign} % initialized \halign

The token parameter \everycr can contain material that's added between every row of the alignment (also before the first and after the last rows), so it's reset to empty. Of course, \ialign should be used in a group.

The syntax of \halign is rather complex: it must be followed by { and the material up to the first \cr is a list of &-separated templates. For instance, when one specifies a c column in a tabular, LaTeX basically inserts the template \hfil#\hfil, where # represents the cell's contents.

In our case the template is the minimal one, just # (that must be doubled because it appears in a definition). This means that we have only one row; no filling is necessary, because we'll have just two rows and the second one will determine the column width.

The first row of the alignment contains

\hidewidth\char"00B4\hidewidth\cr

that is, an acute accent that will be centered with respect to the column width; \hidewidth is a big negative skip with infinite stretchability, so it will never influece the computation of the widest cell. The \cr ends the row.

Next comes

\noalign{\vskip-1ex}

which means: “between the rows backup by 1ex”, which normally is the distance from the base of the accent to the baseline (minus some clearance). This length should be adjusted on a font basis, but it's easy to examine the result and act consequently.

The next row contains only the “long a” and the alignment ends.

We place the \ialign inside a \vbox, so that the baseline of the last row in the alignment will be the baseline of the box. This box is necessary because \halign is illegal in horizontal mode. The width of the \vbox will be the same as the width of the \halign inside it. In the \vbox we set \offinterlineskip to turn off TeX's usual computation of the interline space, so nothing will be added and we can control the spacing between the rows with \noalign{\vskip...}.

The initial \leavevmode is necessary for making sure TeX starts a paragraph in case \stressedlonga comes first.

9
  • I actually tried to use the combining accent U+0301 first, but I ran into a weird problem I wasn't able to solve. See my updated question.
    – Sverre
    Nov 12, 2013 at 20:49
  • @Sverre If you don't like the combining character placement, use the \ialign macro.
    – egreg
    Nov 12, 2013 at 21:16
  • A google search for "latex ialign" didn't give me anything I was able to use for knowing how to use that macro, and it's not in the official latex2e reference folder. Any pointers?
    – Sverre
    Nov 12, 2013 at 21:21
  • @Sverre That's low level TeX. Matter for wizards and gurus. ;-)
    – egreg
    Nov 12, 2013 at 21:24
  • But didn't you just advice me to use it? :P Now I feel like you're warning me against it ...
    – Sverre
    Nov 12, 2013 at 21:29
6

add \showoutput and you will see

....\kern -3.50006
....\hbox(8.35255+0.0)x3.33008
.....\hbox(6.78711+0.0)x3.33008, shifted -1.56544
......\EU1/TimesNewRoman(0)/m/n/10 ´
....\EU1/TimesNewRoman(0)/m/n/10 a

you are back spacing -3.5pt but the box is only 3.33pt wide

As noted in comments you want something like

\newcommand{\stressedlonga}{\longa\llap{\raisebox{.35ex}{\myacute}\kern.1em}}
15
  • And what does that mean?
    – Sverre
    Nov 12, 2013 at 20:00
  • @Sverre it means where did you get the value of .35em from? Nov 12, 2013 at 20:01
  • By manually exploring what kerning value would put the acute accent in the middle of the macron.
    – Sverre
    Nov 12, 2013 at 20:02
  • @Sverre try \newcommand{\stressedlonga}{\longa\llap{\raisebox{.35ex}{\myacute}}} Nov 12, 2013 at 20:03
  • 1
    @Sverre inside the llap you can add additinonal kerns before or after the raisebox, they'll move the accent without moving anything else \newcommand{\stressedlonga}{\longa\llap{\raisebox{.35ex}{\myacute}\kern.1em}} Nov 12, 2013 at 20:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .