7

I'm using Win10, TeXLive 2020. When I use XeLaTeX to compile code below

\documentclass{article}
\usepackage{unicode-math}
\newenvironment{Question}{\textbf{envname}}{}
\begin{document}
    \begin{Question}
        test
    \end{Question}
\end{document}

load <code>unicode-math</code> 宏包

When I change environment name or unload unicode-math package, I can get the correct output

\documentclass{article}
\usepackage{unicode-math}
\newenvironment{question}{\textbf{envname}}{}
\begin{document}
    \begin{question}
        test
    \end{question}
\end{document}

I can get

change environment name

Why did that happen and how to fix it without changing the environment name?

Syvshc
  • 1,328

2 Answers2

9

The command \Question is defined to represent the double question mark character, along with a whole bunch of other unicode character mapping definitions ("mathtable"), done at begin document. You should choose a non-clashing environment name.

I agree it is annoying that \Question isn't defined immediately by unicode-math, so it would be detected by the \newcommand; and unicode-math issues no warning about the changed definition when it does get defined. (The command that fails to give warning is \__um_sym:nnn.)

But why is there no double-question character in the output?? There WILL be a warning in the log file explaining that:

Missing character: There is no ⁇ in font [lmroman10-regular]:mapping=tex-text;!
  • 2
    Will Robertson is active here and can speak to this if he feels like it, but I’m guessing the reason for silently redefining many commands after the preamble is that people often load unicode-math over another package whose commands it redefines, such as mathtools. – Davislor May 21 '20 at 08:40
  • ...kind of active... – Will Robertson May 21 '20 at 11:40
  • both your answers are excellent. And I give the acceptance to @muzimuzhi for giving out the solution. ;) Thanks a lot. – Syvshc May 21 '20 at 14:22
  • @Davislor, you are probably right about the command overwrites. – Donald Arseneau May 22 '20 at 04:40
  • Excuse me: you need to use \tracinglostchars = 2 to get TeX engines to complain when a glyph is missing from a font, instead of silently putting a warning in the middle of the log file. – Davislor May 22 '20 at 09:25
7

Explanation

\Question is one of math symbol commands unicode-math provides. Therefore after your \newenvivonment{Question}..., \Question is redefined to the double question mark (U+2047) at the beginning of document (\begin{document}) by unicode-math. Since the default unicode math font Latin Modern Math font does not provide this symbol, XeLaTeX (or LuaLaTeX) writes

Missing character: There is no ⁇ in font [lmroman10-regular]:mapping=tex-text;!

to the log and leaves a blank before environment content test in the output. It is a pity that this error is not filtered by most editors.

If you move \newenvivonment{Question}... after \begin{document}, you will get

! LaTeX Error: Command \Question already defined.
               Or name \end... illegal, see p.192 of the manual.

which reminds you that \Question is already defined.

Workaround

Probably you need to use another environment name, or redefine \Question at the beginning of document like

\usepackage{unicode-math}

% this must appear after unicode-math
\AtBeginDocument{
  \renewenvironment{Question}{\textbf{envname}}{}
  % or let \Question to undefined, then \newenvironment{Question}
}
``
muzimuzhi Z
  • 26,474