TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am getting some strange behaviour using luaLaTeX and a rather simple command definition. I am using TeXLive 2012, Linux x86_64.

When \settowidth is used in the preamble to compute the width of some characters in the following example, the width is terribly underestimated, and when that width is used to negatively indent some text, it does not line up.

If the \settowidth operating is moved inside the document environment, the calculation is just fine.

Here is a minimum working example:


\settowidth{\arrowwidth}{$\rightarrow$\ }
\newcommand{\note}[1]{\noindent\hskip-\arrowwidth{$\rightarrow$\ }{#1}}

%\settowidth{\arrowwidth}{$\rightarrow$\ }



If you uncomment the line above the \note{HELLO WORLD}, everything works as expected.

Changing the 12pt option also changes the issue somewhat drastically.

The character isn't the problem. You can substitute roman text for the right arrow and it will still give problems.

Does anyone have any idea what causes this? Can anyone else reproduce it?

share|improve this question
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. – Kurt Nov 1 '12 at 15:34
Before using \settowidth in the preamble set issue the command \rmfamily. This forces your font choices to take effect at that point rather than being delayed to the \begin{document} command. – Andrew Swann Nov 1 '12 at 15:50
up vote 6 down vote accepted

For technical reasons, fontspec delays some font settings after the preamble has been completely read in. In particular, the font size is still 10pt when you do the \settowidth command. You can solve the issue by forcing \normalsize in the command:

\settowidth{\arrowwidth}{\normalsize$\rightarrow$\ }

But there's a slicker way to define your \note command:

\newcommand{\note}[1]{\noindent\makebox[0pt][r]{$\rightarrow$\ }#1}

that doesn't require any measuring.

share|improve this answer
Thanks! That zero-width box trick is quite brilliant. I could have sworn I tried the \normalsize, but it didn't work. Perhaps I'm mistaken. – Timtro Nov 1 '12 at 15:48
I'm wondering if this isn't a bug. fontspec doesn't really delay the size setting but changes it: before loading fontspec \f@size is 12pt and afterwards it is 10pt. – Ulrike Fischer Nov 1 '12 at 16:06
@Timtro Ulrike (she's a Mrs, by the way) is right. I remember that this has been discussed somewhere. – egreg Nov 1 '12 at 16:26

Your Answer


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.