9

Problem Statement

I'd like to introduce a new math operator (the divergence operator). Unfortunately the macro I'd like to use is already defined, so I "free" it using

\let\div\undefined

and declare the new operator

\DeclareMathOperator{\div}{div}

If I am using only amsmath everything works fine, but as soon as I add unicode-math everything breaks.

Implementation

Consider the following MWE

\documentclass{scrartcl}\pagestyle{empty}
\usepackage{amsmath}
\usepackage{unicode-math}
\setmathfont{TeX Gyre Pagella Math}
\let\div\undefined
\DeclareMathOperator{\div}{div}
\begin{document}
\[ \int_V \div \vec{F} \, \mathrm{d}V = \oint_A \vec{F} \cdot \vec{n} \, \mathrm{d}A \]
\end{document}

Output

The output I get contains the output of the original \div macro.

real

Expected Output

expected

11

unicode-math does most of its work at \begin{document}, so you have to delay your declarations too:

\documentclass{scrartcl}

\usepackage{amsmath}
\usepackage{unicode-math}
\setmathfont{TeX Gyre Pagella Math}

\newcommand{\diff}{\mathop{}\!\mathrm{d}} % better than using \,\mathrm{d}

\AtBeginDocument{
  \let\div\relax
  \DeclareMathOperator{\div}{div}
}

\begin{document}
\[
\int_V \div \vec{F} \diff V = \oint_A \vec{F} \cdot \vec{n} \diff A
\]
\end{document}

enter image description here

Note that this is only needed because you want to override a command defined by unicode-math. Using \DeclareMathOperator{\Div}{div} wouldn't need special precautions.

  • A little note: It only works if the \AtBeginDocument{…} block appears after \usepackage{unicode-math}. (Why?!) – Henri Menke Jun 6 '13 at 20:07
  • Thanks for pointing out the \diff thing. BTW: What is the difference between \let\x\undefined and \let\x\relax? – Henri Menke Jun 6 '13 at 20:08
  • 3
    @HenriMenke LaTeX executes code declared in \AtBeginDocument in order. If you issue it before loading unicode-math it would be the same situation as you had before. In general I recommend loading packages first and then adding code. – egreg Jun 6 '13 at 20:09
  • the \diff is a little farther from the V than it really needs to be. \mathrm{d} by itself doesn't have that effect. – barbara beeton Jun 6 '13 at 20:37
  • 1
    @barbarabeeton The output is exactly the same with \,\mathrm{d}V and \diff V: it's the same as in Henri's original picture. The leftmost serif of "V" is at the start of the rightmost serif of the "d". Of course the problem would not show with a proper italic "d". ;-) – egreg Jun 6 '13 at 20:55
8
\documentclass{scrartcl}\pagestyle{empty}
\usepackage{amsmath}
\usepackage{unicode-math}
\setmathfont{TeX Gyre Pagella Math}

\AtBeginDocument{
\let\div\undefined\DeclareMathOperator{\div}{div}
}
\begin{document}


\[ \int_V \div \vec{F} \, \mathrm{d}V = \oint_A \vec{F} \cdot \vec{n} \, \mathrm{d}A \]
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.