# Double Bar/Overline

I think that most people are familiar with the fact that \bar creates a bar which is much too small, yet \overline creates a bar which is too long. I recently came across this excellent answer where the new command \widebar is defined, which gets the balance perfectly:

Now the problem is, one may want to write \widebar{\widebar{A}} (when writing notes about the closure of a set being idempotent, for example). However when I attempt to do this I get the following:

Any ideas how I can go about a double \widebar which remains the same width? I appreciate any help.

Edit: I do not wish to use \overline{\overline{...}} or \bar{\bar{...}}, because the problems when they are used once are still present: namely that one is too small and the other is too large. I would like to obtain a double \widebar.

• I tried making combinations of the three versions to see if something good would come up. Apparently not, but things do get weird if you do \bar{\widebar{A}}. – Phelype Oleinik Jan 30 '18 at 12:02
• I have retracted my close. – Sebastiano Jan 30 '18 at 12:55
• @PhelypeOleinik I did not try that. I got two A's for some reason. I wonder why that happens. – Luke Collins Jan 30 '18 at 13:23
• @LukeCollins Yes, I didn't get anything good. But as I said, things get pretty weird with \bar{\widebar{A}} :P – Phelype Oleinik Jan 30 '18 at 13:32

Although I do not fully understand the macro \widebar defined in the answer you linked to, I have managed to modify it to work for other accents (including stacked accents).

Here is the code:

\documentclass{article}
\usepackage{amsmath}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This code is a slight modification of Hendrik Vogt's \widebar %%
%% See: https://tex.stackexchange.com/questions/16337            %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\let\save@mathaccent\mathaccent
\newcommand*\if@single[3]{%
\setbox0\hbox{${\mathaccent"0362{#1}}^H$}%
\setbox2\hbox{${\mathaccent"0362{\kern0pt#1}}^H$}%
\ifdim\ht0=\ht2 #3\else #2\fi
}
%The bar will be moved to the right by a half of \macc@kerna, which is computed by amsmath:
\newcommand*\rel@kern[1]{\kern#1\dimexpr\macc@kerna}
%If there's a superscript following the bar, then no negative kern may follow the bar;
%an additional {} makes sure that the superscript is high enough in this case:
\newcommand*\wideaccent[2]{\@ifnextchar^{{\wide@accent{#1}{#2}{0}}}{\wide@accent{#1}{#2}{1}}}
%Use a separate algorithm for single symbols:
\newcommand*\wide@accent[3]{\if@single{#2}{\wide@accent@{#1}{#2}{#3}{1}}{\wide@accent@{#1}{#2}{#3}{2}}}
\newcommand*\wide@accent@[4]{%
\begingroup
\def\mathaccent##1##2{%
%Enable nesting of accents:
\let\mathaccent\save@mathaccent
%If there's more than a single symbol, use the first character instead (see below):
\if#42 \let\macc@nucleus\first@char \fi
%Determine the italic correction:
\setbox\z@\hbox{$\macc@style{\macc@nucleus}_{}$}%
\setbox\tw@\hbox{$\macc@style{\macc@nucleus}{}_{}$}%
\dimen@\wd\tw@
%Now \dimen@ is the italic correction of the symbol.
\divide\dimen@ 3
\@tempdima\wd\tw@
%Now \@tempdima is the width of the symbol.
\divide\@tempdima 10
%Now \dimen@ = (italic correction / 3) - (Breite / 10)
\ifdim\dimen@>\z@ \dimen@0pt\fi
%The bar will be shortened in the case \dimen@<0 !
\rel@kern{0.6}\kern-\dimen@
\if#41
#1{\rel@kern{-0.6}\kern\dimen@\macc@nucleus\rel@kern{0.4}\kern\dimen@}%
%Place the combined final kern (-\dimen@) if it is >0 or if a superscript follows:
\let\final@kern#3%
\ifdim\dimen@<\z@ \let\final@kern1\fi
\if\final@kern1 \kern-\dimen@\fi
\else
#1{\rel@kern{-0.6}\kern\dimen@#2}%
\fi
}%
\macc@depth\@ne
\let\math@bgroup\@empty \let\math@egroup\macc@set@skewchar
\mathsurround\z@ \frozen@everymath{\mathgroup\macc@group\relax}%
\macc@set@skewchar\relax
\let\mathaccentV\macc@nested@a
%The following initialises \macc@kerna and calls \mathaccent:
\if#41
\macc@nested@a\relax111{#2}%
\else
%If the argument consists of more than one symbol, and if the first token is
%a letter, use that letter for the computations:
\def\gobble@till@marker##1\endmarker{}%
\futurelet\first@char\gobble@till@marker#2\endmarker
\ifcat\noexpand\first@char A\else
\def\first@char{}%
\fi
\macc@nested@a\relax111{\first@char}%
\fi
\endgroup
}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand\doubleoverline[1]{\overline{\overline{#1}}}

\newcommand\widebar{\wideaccent\overline}
\newcommand\widebarbar{\wideaccent\doubleoverline}
\begin{document}

\begin{tabular}{cc}
$\widebar{A \cup B}$
&
$\widebarbar{A \cup B}$
\\
\verb$\widebar{A \cup B}$
&
\verb$\widebarbar{A \cup B}$
\end{tabular}

\end{document}


and here is the output:

Note that this also works for other combinations of accents:

\newcommand\hatoverline[1]{\widehat{\overline{#1}}}
\newcommand\widehatbar{\wideaccent\hatoverline}

$\widehat{\widebar{A}} \neq \widehatbar{A}$