# correcting kerning for tikz shapes as accents in mid-word

I'm trying to place arrow shapes above certain letters in a text. I tried compensating for the extra space of the tikzpicture in mid-word, using execute at begin picture and its end pair.

The results aren't very good, is there a better way of doing this?

\documentclass{minimal}
\makeatletter

\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{TeX Gyre Pagella}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.arrows}

\newcommand\toneUp[1]{%
\def\mychar{#1}%
\begin{tikzpicture}[
execute at begin picture={
\pgfmathparse{0.5*(1.6mm-\widthof{\mychar})}
\hspace*{-\pgfmathresult mm}
},
execute at end picture={
\pgfmathparse{0.5*(1.6mm-\widthof{\mychar})}
\hspace*{-\pgfmathresult mm}
}]
\node[inner sep=0pt, outer sep=0pt] (mychar) {\mychar};
\node[single arrow, minimum height=5mm, minimum width=7mm, single arrow head extend=3mm, single arrow head indent=1mm, scale=0.3, red, fill=red, rotate=90, above=0.3mm of mychar.north, anchor=west] {};
\end{tikzpicture}
}

\setlength{\parindent}{0pt}
\makeatother

\begin{document}

ārop\toneUp{i}tehi\\
paṇṇ\toneUp{ā}kār\toneUp{a}\\
bh\toneUp{ū}te

\end{document}

-
some of your white space comes from the word space after the picture you are missing a %, you need \end{tikzpicture}%. I can't help with the tikz, but probably I would set the character normally, ie just start (or end) your macro with #1 and then use a zero-sized tikzpicture to overlay the arrow. –  David Carlisle Sep 8 '12 at 9:57

Edit: better arrows but the kerning is not completely perfect because \mychar is draw alone in this node.

You can use overlay option to remove your arrow from automatic bounding box calculation of tikzpicture.

You cans use em or ex dimension to adapt automatically the dimension of your arrow to the current font dimension.

\documentclass{minimal}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{TeX Gyre Pagella}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.arrows}

\newcommand\toneUp[1]{%
\def\mychar{#1}%
\begin{tikzpicture}[inner sep=0,outer sep=0]
\node (mychar) {\mychar};
\node[
overlay,
single arrow,
inner sep=.05em,
minimum height=.25em,
minimum width=.35em,
single arrow head extend=.15em,
single arrow head indent=.05em,
red,
fill=red,
rotate=90,
above=0.3mm of mychar.north,
anchor=west] {};
\end{tikzpicture}%
}

\setlength{\parindent}{0pt}

\begin{document}

ārop\toneUp{i}tehi

paṇṇ\toneUp{ā}kār\toneUp{a}

bh\toneUp{ū}te

\end{document}

-
Excellent, thanks for the overlay example! –  Nyiti Sep 8 '12 at 12:09

I don't have the fonts installed properly but you need to cancel the bounding box update due to the arrow. So you can use pgfinterruptpicture environment that allows you to avoid the bounding box updates.

\documentclass{article}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{TeX Gyre Pagella}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.arrows}

\newcommand\toneUp[1]{%
\begin{tikzpicture}
\node[inner sep=0pt, outer sep=0pt] (mychar) {#1};
\begin{pgfinterruptpicture}
\node[single arrow, minimum height=5mm,
minimum width=7mm, single arrow head extend=3mm,
single arrow head indent=1mm, scale=0.3, red, fill=red,
rotate=90, above=0.3mm of mychar.north, anchor=west] {};
\end{pgfinterruptpicture}
\end{tikzpicture}%
}

\setlength{\parindent}{0pt}

\begin{document}

ārop\toneUp{i}tehi\\
paṇṇ\toneUp{ā}kār\toneUp{a}\\
bh\toneUp{ū}te

\end{document}


-
It seems to me that the overlay option is easier. –  Paul Gaborit Sep 8 '12 at 10:22
@PaulGaborit You are right, I keep forgetting that. It maps to pgfinterruptpicture anyway (if you do a lot of things adding overlay to each might become laborious though). –  percusse Sep 8 '12 at 10:23
I believe that you can apply overlay to a scope. –  Paul Gaborit Sep 8 '12 at 10:33