# Why is unicode-math not working with TikZ?

\documentclass{article}

\usepackage{unicode-math} % This causes the question mark bug
% This code requises unicode-math
% How can you use the code without unicode-math -package?
\setmathfont[BoldFont={latinmodern-math.otf}]{latinmodern-math.otf}
\setmathfont[range=\mathscr,Scale=MatchUppercase]{Asana-Math.otf}
\usepackage{tikz}
\usetikzlibrary{tikzmark,decorations.pathreplacing,calc}
\newcommand\MyText[4][0pt]{%
\begin{tikzpicture}[overlay, remember picture]
\draw [decoration={brace},decorate,thick]
( $({pic cs:#3}|-{pic cs:#2}) + (#1,1.3ex)$ ) --
node[anchor=west,xshift=5pt,text width=5cm] {#4}
( $(pic cs:#3) + (#1,0)$ );
\end{tikzpicture}%
}

% I have defined question like this
\usepackage[framemethod=tikz]{mdframed}
\newtheorem{question}{Question}
\mdfdefinestyle{que}{
linecolor=cyan,
backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{question}

\begin{document}
\begin{question}
Lorem ipsum?
\end{question}
\end{document}


I am thinking why you need the unicode-math package for the TikZ code.

Why does the TikZ code require unicode-math package?

-
The question mark has nothing to do with tikz (and tikz doesn't require unicode-math). unicode-math defines a \question command and this clash with the name of your environment. Use a different name. –  Ulrike Fischer Feb 22 '14 at 15:09
@Ulrike The problem is not in the question command, I think. There was mistake in the example code here. I had commented those lines out in my code. –  Masi Feb 22 '14 at 15:39
@Masi You can't, of course, use the question environment without defining it, because there's no predefined one; so this code is wrong in the first place. Without unicode-math it wouldn't compile; with unicode-math it's using the \question command that is completely unsuitable for this usage. –  egreg Feb 22 '14 at 16:00
That's the same problem as here tex.stackexchange.com/q/146516/5049 just as @Ulrike said –  clemens Feb 22 '14 at 17:04

It's a very unfortunate state of affairs.

The problem is that unicode-math does most of its work during processing of \AtBeginDocument tokens, that is, when \begin{document} is scanned. Part of this is to define \question as a math symbol producing a question mark.

So, when you define the question environment with \newtheorem, no error is raised. But afterwards unicode-math redefines \question (which is the macro executed when \begin{question} is processed.

Minimal example:

\documentclass{article}

\usepackage{unicode-math} % This causes the question mark bug

\newtheorem{question}{Question}

\begin{document}
\begin{question}
Lorem ipsum?
\end{question}
\end{document}


You can either change the environment's name, or restore the definition; the second strategy can be implemented with

\documentclass{article}

\usepackage{unicode-math} % This causes the question mark bug

\newtheorem{question}{Question}
\let\masiquestion\question
\AtBeginDocument{%
\let\umquestion\question
\let\question\masiquestion
}

\begin{document}
\begin{question}
Lorem ipsum?
\end{question}
\end{document}


In my opinion, unicode-math ought to issue at least a warning when redefining a command.

-
Hmm, issuing warnings would be a problem since it shares 100s of symbols with LaTeX and amssymb. (I could omit the warning for the standard names, I guess.) But there are a few symbols in the lower slots that shouldn't be taking such generic names; I'll update them shortly. –  Will Robertson Jun 22 '14 at 11:33

As I already wrote in the comments: unicode-math defines \question. So you can't use "question" as the name of your environment. Replace it by e.g. questionX:

\documentclass{article}

\usepackage{unicode-math} % This causes the question mark bug

\newtheorem{theorem}{Theorem}
\newtheorem{question}[theorem]{Question}
\newtheorem{questionX}[theorem]{Question}

\begin{document}
\question \question \question %defined by unicode math.

\begin{question} %fails
Lorem ipsum?
\end{question}

\begin{questionX} %works
Lorem ipsum?
\end{questionX}
\end{document}

-