When working with custom defined environments using \@startsection I found, after switching to newunicodechar for defining my unicode characters, that the sectioning headings give this peculiar output:

Here is the code:
\documentclass{article}
\usepackage[colorlinks]{hyperref}
\newcounter{lemma}
\makeatletter
\def\lemmamark{\@gobble}
\newenvironment{lemma}[1]{\@startsection{lemma}{3}{-1em}{\baselineskip}{.1\baselineskip}{\bfseries}{Lemma: #1}}{}
\makeatother
\usepackage{newunicodechar}
\def\textomega{ω} \newunicodechar{ω}{\ifmmode \omega \else \textomega \fi}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{STIXGeneral}
\begin{document}
\begin{lemma}{Properties of ω text}
Some Test
\end{lemma}
\section{Properties of ω}
More Testing
\end{document}
The following changes do not have any influence:
- Using standard sectioning commands instead of
\@startsection(as shown in the example output) - Removing the
\ifmmodeconditional (I just left it here, so that you can see the reason for using\newunicodecharat all) - Using
\protectinside of\def\textomega - Using
\renewcommandor\DeclareRobustCommandto define\textomega - Using the predefined
\textomega
I know that I could probably use unicode-math here, but I'm still on TeX Live 2011 and didn't find it usable enough in the general situation.
I'll just post a self-answer on how to circumvent this problem, but what I'm much more interested in, is: Why does this happen? Is this maybe a bug in hyperref or newunicodechar?
It gets stranger still! With other, similar characters there is no such problem. For example ψ instead of ω will work with
\def\textpsi{ψ} \newunicodechar{ψ}{\ifmmode \psi \else \textpsi \fi}
\newunicodechar. The input will work also in math without any redefinition. – egreg Jul 29 '12 at 16:29fontspec's\setmainfontand compile withxelatextheωwill not be printed out in math mode. Tracing givesMissing character: There is no ω in font cmmi10!– bodo Jul 29 '12 at 16:35hyperrefas late as possible. Are you sure you don't want to loadunicode-mathand XITS Math? – egreg Jul 29 '12 at 21:19