# Background

Looking to adjust the location of the first letter in a word based on its width.

# Problem

The calculation resembles:

\define[1]\StyleChapterChar{%
\cldcontext{string.sub("#1",1,1)}%
}

% Use a nested frame to keep the overlain large letter together with
% the chapter title.
\define[1]\StyleChapter{%
\StyleChapterFramed{%
\framed[align=right, frame=off]{%
\startoverlay
\color[blue]{%
\StyleChapterChar{#1}%
}
\vskip-1.9em\hskip\dimexpr\averagecharwidth*33/10#1
\stopoverlay
}
}
}


Here, 3.3 * \averagecharwidth is used to offset the text. This causes the horizontal offset of the emphasized first character in the word to vary wildly between an A and an I. What I would like is to replace this calculation (3.3 * \averagecharwidth) with one that uses the character width (e.g., 3.3 * \charwidth{\StyleChapterChar})

# Question

How do you get the width of a single character, when you don't know what that character is?

# Ideas

I've tried a few things so far:

\define[1]\StyleChapterCharWidth{
\dimexpr\fontcharwd\font#1
}

\define[1]\StyleChapterCharWidth{
\fontcharwd\font#1
}


It seems like the back-tick () character indicates that the next character should be treated literally.

# Related

• Typeset the character in a box, and measure its width. \setbox\scratchbox\hbox{C}\wd\scratchbox. – Aditya Sep 23 '13 at 2:41

\define[1]\StyleChapterChar{%
\cldcontext{string.sub("#1",1,1)}%
}

\define[1]\StyleChapter{%
\StyleChapterFramed{%
\framed[align=right, frame=off]{%
\startoverlay
% Calculate the offset of the large letter based on the width of
% the character. This allows the font to change without significantly
% affecting the distance between the emphasized first character of the
% chapter title and the complete chapter title.
\setbox\scratchbox\hbox{%
\StyleFontChapterCharacter\StyleChapterChar{#1}}%
% Shift the first character back relative to the chapter title.
\hskip-.55\wd\scratchbox%
\color[blue]{%
\StyleFontChapterCharacter%
\StyleChapterChar{#1}%
}
\vskip-1.9em
#1
\stopoverlay
}
}
}
`