# Warning “Command \underbar has changed”

I am using the following code and I get the warning

Command \underbar has changed.


What does this mean? How do I fix it?

\documentclass{article}

\usepackage{amsmath}

\usepackage{unicode-math}

\usepackage[english,greek]{babel}

\usepackage{fontspec}

\setmainfont
[
UprightFont = *,
BoldFont = *Bold,
ItalicFont = *It,
BoldItalicFont = *BoldIt,
Extension = .otf,
Ligatures = TeX,
Mapping = tex-text
]{GFSArtemisia}

\setsansfont
[
Mapping = tex-text
]{GFSArtemisia.otf}

\setmathfont{latinmodern-math.otf}

\usepackage{sectsty}

\sectionfont{\RaggedRight}

\begin{document}

Text

\end{document}

• It's caused by sectsty. You can load that earlier to avoid that particular warning. – cfr May 23 '16 at 1:48
• $$\underbar$$ why doesn't it work here? is it possible to put it in math exchange somehow? – Charlie Parker Sep 27 '18 at 0:13

The warning is caused by a check sectsty runs on the definition of \underbar. If it doesn't match one of the definitions it expects, it warns you.

You can avoid this warning but I don't recommend it. The warning is telling you something important: that sectsty has found a definition of \underbar which is not what it expects and that things may not work properly.

In truth, I would recommend not using sectsty with LuaTeX/XeTeX. In particular, I wouldn't use it with unicode-math.

If you insist, for LuaTeX, you can avoid that particular warning by loading the package earlier. For XeTeX, you can avoid that warning by loading the package earlier.

For example,

\documentclass{article}
\usepackage{sectsty}
\usepackage{amsmath}
\usepackage{unicode-math}
\usepackage[english,greek]{babel}
\usepackage{fontspec}
\setmainfont
[
UprightFont = *,
BoldFont = *Bold,
ItalicFont = *It,
BoldItalicFont = *BoldIt,
Extension = .otf,
Ligatures = TeX,
]{GFSArtemisia}
\setsansfont
[
Ligatures = TeX,
]{GFSArtemisia.otf}
\setmathfont{latinmodern-math.otf}
\sectionfont{\RaggedRight}
\begin{document}

Text

\end{document}


However, I get other warnings with LuaTeX.

• Thank you but before which packages must generally be loaded? – Adam May 23 '16 at 1:52
• What do you mean? Sorry, but I don't understand what you're asking. – cfr May 23 '16 at 1:53
• You said I must load it earlier. Earlier than which package? – Adam May 23 '16 at 1:54
• I'm not sure. It doesn't know about the new font handling stuff. Probably when to load it depends on the result you want. That is, how do you want the definition of \underbar to end up at the end of the preamble? If you load it after unicode-math, you'll get a warning because unicode-math redefines \underbar. But the real question is: do you want sectsty's or unicode-math's or something else? – cfr May 23 '16 at 2:10
• Please see edit. – cfr May 23 '16 at 2:10

You have really nothing to worry about, provided you don't use sectsty for underlining section titles.

The package does a check on \underbar and on \underline, because it wants to redefine them but it just does so when typesetting those titles.

So, if you don't use underlining (and you're better not to), there should be no problem.

Something actually can be done to fully disable those redefinitions (only risky if you happen to use \underbar in a section title, actually).

\documentclass{article}

\usepackage{amsmath}
\usepackage{unicode-math}
\usepackage[english,greek]{babel}
\usepackage{silence}
\WarningFilter{latex}{Command} % silence the warning
\usepackage{sectsty}

\makeatletter % disable the runtime redefinitions
\let\SS@makeulinesect\relax
\let\SS@makeulinepartchap\relax
\makeatother

\setmainfont[
UprightFont = *,
BoldFont = *Bold,
ItalicFont = *It,
BoldItalicFont = *BoldIt,
Extension = .otf,
Ligatures = TeX,
]{GFSArtemisia}
\setsansfont{GFSArtemisia.otf}
\setmathfont{latinmodern-math.otf}

\sectionfont{\RaggedRight}

\begin{document}

Text

\end{document}