Why does the \widehat mathematical symbol show up as follows in the MWE below? enter image description here


\newcommand*\lettergroupDefault[1]{\textbf{\sffamily Symbols}}

  E=mc^2\index{. xv@$\widehat{\xv}_n$}
  • 2
    \protect\widehat The contents of \index are written to an external file which always triggers full expansion and \widehat is not protected. – Henri Menke Nov 16 '18 at 1:24
  • That solved the problem, Henri, thanks. Do you want to provide it as answer? – Marius Hofert Nov 16 '18 at 3:24

If you look in the .idx file, you will find

\indexentry{. xv@$\mathaccent "0362\relax {\xv  }_n$}{1}

which fails because " is a quoting character in .idx files, so this is interpreted as if it were \mathaccent 362 changing hexadecimal into decimal.

A way out could be \protect\widehat, but I'd not recommend this. The problem is that


does not behave as an operator as far as spacing is concerned, because it ends up being an Acc atom, which is later treated as an ordinary one. Try with

  \xv A &= 2 \\
  \hxv A &= 2 \\
  \widehat{\xv} A &= 2

where \xv and \hxv are properly defined by


The output is

enter image description here

and you can immediately see the problem.

Using \hxv in the \index command will write \hxv (and similarly \xv will write itself) instead of doing nasty expansions. The proposed definition of \xv is to be preferred to \newcommand{\xv}{\operatorname{xv}} also for this reason.

Beware that the same problem with " will appear with delimiters: protect also things such as \lbrace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.