[Tex/LaTex] Warning “Command \underbar has changed”

warnings

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}

Best Answer

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.