3

I am trying to renew \overline into \bar in a Xelatex document but Xelatex does not compile and I do not understand why I get the error "\bar is already defined".

Here is my Xelatex code :

\documentclass{book}
\usepackage{polyglossia}
\setmainlanguage{french}

\renewcommand{\bar}{\overline}

\begin{document}
$\bar{ABCD}$\\
$\overline{ABCD}$
\end{document}

But when I am in normal Latex mode, this code compiles perfectly :

\documentclass{book}
\usepackage[francais]{babel}
\usepackage[T1]{fontenc}

\renewcommand{\bar}{\overline}

\begin{document}
$\bar{ABCD}$\\
$\overline{ABCD}$
\end{document}

I have been searching a related topic but so far, I have not found any solution.

( The answer here : Problem with renewcommand? did not work for bar )

Thank you for your help.

  • Try \let\bar\overline instead or \AtBeginDocument{\renewcommand{\bar}{\overline}} but I doubt the usefulness of the idea at all – user31729 Apr 18 '17 at 20:33
  • 1
    The problem is that fontspec (loaded by polyglossia) tries to declare the \bar accent at \begin{document}. You must do your redefinition later, or use another name. – Ulrike Fischer Apr 18 '17 at 20:39
  • The first option does not work either, I have already tried it. But the second one is working, thank you very much ! :) – Adrien Meilac Apr 18 '17 at 20:41
  • @AdrienMeilac: Yes, forget the first option. It would work if used in \AtBeginDocument{...} however. – user31729 Apr 18 '17 at 20:41
  • + Ulrike Fische : Ok , Are there other commands like bar that I could not renew with polyglossia ? – Adrien Meilac Apr 18 '17 at 20:42
3

Quite interesting!

What happens is that fontspec (which is loaded by polyglossia) has to redefine \bar using a different math symbol font than in standard LaTeX, so it call (at begin document)

\DeclareMathAccent{\bar}{\mathalpha}{legacymaths}{22}

The working of \DeclareMathAccent is complex, but in essence it checks whether its first argument (here \bar) is either undefined or defined as a math accent; in this case it (re)defines it as requested. If the command is already defined not to be a math accent, it raises an error.

Since you're doing \renewcommand{\bar}{\overline}, we are in the second situation, because \overline is not a math accent (from TeX’s point of view).

Solution:

\AtBeginDocument{\renewcommand{\bar}{\overline}}

which will do the redefinition later than the one performed by fontspec. This will also work in standard LaTeX.

  • Thank you for your help. Do you think like Ulrike Fische that I should not use \bar and choose another name or other errors could appear in the document because of that renewcommand ? – Adrien Meilac Apr 18 '17 at 20:55
  • @AdrienMeilac In my opinion, \overline is no substitute for \bar. It's a necessary evil in case you have to overline several letters, but I usually prefer the shorter \bar. You can look at tex.stackexchange.com/questions/357922 for importing \widebar from mathabx (but it doesn't stretch to cover four letters). – egreg Apr 18 '17 at 21:07

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.