125

Following the question "The \bar and \overline commands" which is simply about the lengths of both, I'd like to know when to use \bar and when to use \overline from a semantically viewpoint.

I always used \bar, because up until now I only had single letter mean values to type. But now I came to a problem where I needed a wider "bar".

Then I just tried

\documentclass{article}

\begin{document}
  \[ \bar{a} \overline{a} \]
  \[ \bar{abc} \overline{abc} \]
\end{document}

where one can see that they also differ in position (\overline is lower), and also in thickness (\overline is thicker).

So, the question here is:

What does \bar represent semantically? And when to choose it over \overline and vice versa?

1

4 Answers 4

130

Semantically, don't use either. Use \conj, or \mean, or \variant or whatever the overline is meant to mean. Then in your preamble, do:

\newcommand*\conj[1]{\bar{#1}}
\newcommand*\mean[1]{\bar{#1}}

Then:

  1. Your document source becomes readable: you can determine the meaning right there and then.
  2. Your document becomes more flexible: if you decide to denote complex conjugation by a star instead you can simply redefine \conj without worrying about changing what \mean does.
  3. You can change from \bar to \overline on a whim and don't have to make that crucial decision now.
8
  • 37
    while the suggestion to use a "meaningful" command is excellent, the expansion would have to be more complicated to allow for single or multiple-letter arguments. since the original question mentioned both, that should be addressed in your answer. Commented Feb 13, 2013 at 22:22
  • 40
    "All problems in computer science can be solved by another level of indirection"
    – Mats
    Commented Sep 11, 2016 at 16:28
  • 1
    as mentioned by @barbarabeeton, this fails for a term like $B^d_D(0)$, overline does well on the other hand
    – ZirconCode
    Commented Dec 29, 2018 at 1:14
  • 4
    Ok, but after making this new command, which should I use for mean, \bar or \overline?
    – endolith
    Commented Feb 13, 2021 at 14:48
  • 1
    Which implies that if you type some else's text without fully understanding it (e.g., because you're just a typist or the text is junk), DO use \bar or \overline, and DON'T try anything semantic from the beginning.
    – user224332
    Commented Sep 1, 2022 at 19:09
23

\bar{a} can mean just "another thing" like if you used a' or \tilde{a} or \diamondclub. You never use \overline for this.

However, if you denote an operation like complex conjugation, reversal, set closure or whatever, you can use whichever you want. You found out that somehow (to some people) \bar{a} seems "too subtle" for this purpose, and you can use the reasonable solution proposed in the other question. This goes along the fact that in this case, things like \overline{x+y}, \overline{2U+V}, \overline{a_1, a_2 \cdots, a_n} have their meaning as well.

21

I have indeed observed a difference between \overline and \bar: Having 3 lines of formula in one \align environment, using overline in combination with a 3rd power like this:

\overline{b}^3

causes the 3rd equation to need more vertical space and the 3rd equation was shifted down a bit, which looked quite disturbing. Using

\bar{b}^3

solved the Problem, so all three equations have the same vertical distance now.

The following code produces a little sheet of pdf which illustrates some differences between bar and overline:

\documentclass{standalone}

\usepackage{amsmath}

\begin{document}
  $\begin{array}{r}
    a+b+c\\
    a+b^3+c\\
    a+\overline{b}+c\\
    a+\overline{b}^3+c\\
    a+\bar{b}+c\\
    a+\bar{b}^3+c\\
    a+\overline{b^3}+c\\
    a+\bar{b^3}+c\\
    a+b+c
  \end{array}$
\end{document}

enter image description here

Note the different distances of equations and the different commutation behavior of the \bar and \overline commands with the power command.

Finally, I recommend always using \bar for single numbers for example. For complex conjugation of many numbers \overline of course is the appropriate choice.

14

The accepted answer is great. The major practical considerations I’ve run into are when I’ve wanted to either put a bar over multiple symbols or put wide bars over two distinct adjacent symbols that do not run together.

When you need a single bar over multiple symbols, \bar does not work, and you want \overline. Unicode introduces a third bar-above accent, which in most math fonts is between the two in width. This is available in unicode-math as \overbar.

If I want a wide bar that does not run into consecutive symbols, I’ve had success with:

\documentclass[varwidth]{standalone}
\usepackage{unicode-math}

\newcommand\widebar[1]{\mathop{\overline{#1}}}

\begin{document}
  \( \widebar{\mathbb{A}} \widebar{\mathbb{B}} \widebar{\mathbb{AB}} \)
\end{document}

Wide bar example

If this fouls up superscripts and subscripts, making them appear above and below, change to \mathop{\overline{#1}}\nolimits.

This does not require unicode-math, by the way.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .