# Problem with font in theorem environment

I use LuaLaTeX, fontspec and XITS maths font. Additionally, I had a problem with theorem environment and long headers so I based my solution on this. My problem is that I now get a different font for the \mathcal{S} when I use optional name. Any ideas why?

\documentclass{article}
\usepackage{fontspec}
\usepackage{amsmath}
\usepackage[math-style=ISO]{unicode-math}
\setmathfont{XITS Math}
\setmathfont[range={\mathcal,\mathbfcal},StylisticSet=1]{XITS Math}

\usepackage[thmmarks,amsmath,amsthm,hyperref]{ntheorem}
\makeatletter
\newtheoremstyle{Myplain}%
\newtheoremstyle{nonumberMyplain}%
\makeatother

\theoremstyle{Myplain}

\usepackage{thmtools}
\declaretheorem[numberwithin=section]{theorem}

\begin{document}

\section{Title}
\begin{theorem}[A a a very very very very long long name theorem theorem name name]
A named theorem $\mathcal{S}$.
\end{theorem}

\begin{theorem}
Unnamed theorem $\mathcal{S}$.
\end{theorem}

\end{document}

-

It seems that ntheorem issues a \mathversion{bold} command for the head, that you don't protect with a group. This is evident if you say $\mathcal{S}=a+b$ in the theorem's body.

Just add braces to the style definition when you use \theorem@headerfont.

\documentclass{article}
\usepackage{fontspec}
\usepackage{amsmath}
\usepackage[math-style=ISO]{unicode-math}
\setmathfont{XITS Math}
\setmathfont[range={\mathcal,\mathbfcal},StylisticSet=1]{XITS Math}

\usepackage[thmmarks,amsmath,amsthm,hyperref]{ntheorem}

\makeatletter
\newtheoremstyle{Myplain}%
\normalfont\itshape}
\newtheoremstyle{nonumberMyplain}%
\theorem@separator\newline\normalfont\itshape}
\makeatother

\usepackage{thmtools}

\declaretheorem[
style=Myplain,
numberwithin=section,
]{theorem}

\begin{document}

\section{Title}
\begin{theorem}[A a a very very very very long long name theorem theorem name name]
A named theorem $\mathcal{S}=a+b$.
\end{theorem}

\begin{theorem}
Unnamed theorem $\mathcal{S}$.
\end{theorem}

\end{document}


-
Small hint: amsmath should be loaded before fontspec – Marco Daniel Mar 30 '13 at 17:49