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

Problems with \renewcommand{\vec}[1]{\mathbf{#1}} #463

Open ghost opened 6 years ago

ghost commented 6 years ago

Description

I tried to redefine the vector definition with \usepackage{unicode-math} statement in the preamble but I could not get it working.

Check/indicate

A not working minimal example (CaseA.tex) demonstrating the issue

\documentclass{scrartcl}

\usepackage{fontspec}
\usepackage{unicode-math}

\renewcommand{\vec}[1]{\mathbf{#1}}

\begin{document}

$ \vec{a} $

\end{document}

A working minimal example (CaseB.tex) demonstrating the issue

\documentclass{scrartcl}

\usepackage{fontspec}
% \usepackage{unicode-math}

\renewcommand{\vec}[1]{\mathbf{#1}}

\begin{document}

$ \vec{a} $

\end{document}

Further details

As the two files only differ in the import of the unicode-math I would suspect the error within the unicode-math error. Also newcommand work as expected:

\newcommand{\op}[1]{\hat{#1}}
\newcommand{\ham}{\mathcal{H}}
\newcommand{\hamop}{\op{\ham}}

Log and PDF files are attached below

CaseA.log CaseA.pdf CaseB.log CaseB.pdf

ghost commented 6 years ago

I looked further into it and I turned out that explicitly setting Latin Modern Math by

\setmathfont{Latin Modern Math}

as the math font solves the issue as can be shown by the following two test cases.

CaseC (not working)

\documentclass{scrartcl}

\usepackage{fontspec}
\usepackage{unicode-math}
% \setmathfont{Latin Modern Math}

\renewcommand{\vec}[1]{\mathbf{#1}}

\begin{document}

$ \vec{a} $

\end{document}

CaseD (working)

\documentclass{scrartcl}

\usepackage{fontspec}
\usepackage{unicode-math}
\setmathfont{Latin Modern Math}

\renewcommand{\vec}[1]{\mathbf{#1}}

\begin{document}

$ \vec{a} $

\end{document}

Attached files

CaseC.log CaseC.pdf CaseD.log CaseD.pdf

ghost commented 6 years ago

I forgot the mention that all files were compiled by LuaTeX-1.0.4.

u-fischer commented 6 years ago

unicode-math waits until \begin{document} to setup the default font and the default definitions. So if you don't use \setmathfont, you should delay your redefinition. I would also recommend to use \symbf instead of \mathbf:

\documentclass{scrartcl}

\usepackage{fontspec}
\usepackage{unicode-math}

\AtBeginDocument{\renewcommand{\vec}[1]{\symbf{#1}}}

\begin{document}

$ \vec{a} $

\end{document}
ghost commented 6 years ago

Thanks for the fast response. I couldn't find the information that the definitions were defined with the \begin{document} command so that really got me on the wrong foot, I have to admit. It still seems a bit odd to me, so perhaps you could mention it for future users in your manual. But as the issue is solved for me, I think you could close the issue now.