latex3 / unicode-math

XeLaTeX/LuaLaTeX package for using unicode/OpenType maths fonts
http://ctan.org/pkg/unicode-math
LaTeX Project Public License v1.3c
245 stars 29 forks source link

Unable to redefine \Re and \Im #457

Closed e-kwsm closed 6 years ago

e-kwsm commented 6 years ago

Description

Unable to redefine (\def, \renewcommand, etc) \Re and \Im—real and imaginary parts of a complex number. Fraktur letters (ℜ and ℑ) are always printed.

Check/indicate

Minimal example demonstrating the issue

\documentclass{article}
\usepackage{unicode-math}
\def\Re{\mathrm{Re}~}
\begin{document}
\[
  \Re z  % Fraktur R but not `Re'
\]
\end{document}

My environment: frozen TeX Live 2017

Further details

Commenting out the following lines enables to redefine \Re and \Im.

https://github.com/wspr/unicode-math/blob/2d9705623f340551357ba07d443eb2e442545e18/unicode-math-table.tex#L179

https://github.com/wspr/unicode-math/blob/2d9705623f340551357ba07d443eb2e442545e18/unicode-math-table.tex#L187

eg9 commented 6 years ago

unicode-math does most of its job at begin document, so you should delay such redefinitions.

\documentclass{article}
\usepackage{amsmath}
\usepackage{unicode-math}

\AtBeginDocument{%
  \renewcommand\Re{\operatorname{Re}}%
}

\begin{document}

\[
  \Re z
\]

\end{document}

screen shot 2018-04-18 at 15 09 11

e-kwsm commented 6 years ago

@eg9 Thank you, \AtBeginDocument works.

wspr commented 6 years ago

@eg9 — given this comes up relatively often, I wonder if I should have a more "clever" system in place here to first define all unicode-math symbols to something like

\cs_set:Npn \Re { \__um_placeholder_symbol:N \Re }

and then inside the \AtBeginDocument definition check that the placeholder is as-expected and keep the user definition. I think there would be negligible speed issues, but I'd need to benchmark to be sure.

eg9 commented 6 years ago

The problem is: what's the expected meaning of \Re? Maybe not for \Re, but for other commands the issue might be relevant.

wspr commented 6 years ago

Well there’s the unicode-math version of \Re, and then there’s everything else :) If a user wants to redefine \Re, perhaps unicode-math should have a package option to

(a) silently overwrite the user definition (current behaviour, fastest) (b) allow the user definition with a warning (c) overwrite the user definition with a warning

The warnings could be turned off with the usual l3msg-based process.

e-kwsm commented 6 years ago

It seems hard to select which macros to support user's redefinition. I think it is good enough that a user redefines a macro by \AtBeginDocument (or its wrapper provided by unicode-math) and that the doc­u­men­ta­tion describes it.