# How does one modify \xoverline for subscripts/superscripts?

The \xoverline command (see the-bar-and-overline-commands) works beautifully except that it assumes normalsize. So it blows up the size of subscripts as in

$A_{\xoverline{K}}$ vs $A_{\overline{K}}$

-
My question is, how do you fix this? The size of the subscript should not be changed by adding an overline to the subscript – Ben G Aug 23 '14 at 0:39

You can try Hendrik Vogt's solution (thanks, Hendrik!), which I have adopted in the form of a small .sty file, widebar.sty:

%%%%%%%%%%%%%%%%%%%%%%%%
% IDENTIFICATION
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{widebar}

%%%%%%%%%%%%%%%%%%%%%%%%
%%% Defines a \widebar command, similar to\widehat.
%%% May have problems with indices
%%% Comes from Hendrik Vogt's answerhere : http://tex.stackexchange.com/questions/16337/can-i-get-a-widebar-without-using-the-mathabx-package/60253#60253
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{amsmath}

\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*\widebar[1]{\@ifnextchar^{{\wide@bar{#1}{0}}}{\wide@bar{#1}{1}}}
%Use a separate algorithm for single symbols:
\newcommand*\wide@bar[2]{\if@single{#1}{\wide@bar@{#1}{#2}{1}}{\wide@bar@{#1}{#2}{2}}}
\newcommand*\wide@bar@[3]{%
\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#32 \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#31
\overline{\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#2%
\ifdim\dimen@<\z@ \let\final@kern1\fi
\if\final@kern1 \kern-\dimen@\fi
\else
\overline{\rel@kern{-0.6}\kern\dimen@#1}%
\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#31
\macc@nested@a\relax111{#1}%
\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#1\endmarker
\ifcat\noexpand\first@char A\else
\def\first@char{}%
\fi
\macc@nested@a\relax111{\first@char}%
\fi
\endgroup
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Here is a minimal test code:

\documentclass{article}

\usepackage{mathtools}
\usepackage{widebar}

\begin{document}

$\widebar{\mathbf A}_{\widebar{K}_{\widebar L}}$%

\end{document}


-
\documentclass{article}

\usepackage{amsmath}

\makeatletter

\newsavebox\myboxA
\newsavebox\myboxB
\newlength\mylenA

\newcommand*\xoverline[2][0.75]{%
\sbox{\myboxA}{$\m@th#2$}%
\setbox\myboxB\null% Phantom box
\ht\myboxB=\ht\myboxA%
\dp\myboxB=\dp\myboxA%
\wd\myboxB=#1\wd\myboxA% Scale phantom
\sbox\myboxB{$\m@th\overline{\copy\myboxB}$}%  Overlined phantom
\setlength\mylenA{\the\wd\myboxA}%   calc width diff
\ifdim\wd\myboxB<\wd\myboxA%
\rlap{\hskip 0.5\mylenA\usebox\myboxB}{\usebox\myboxA}%
\else
\hskip -0.5\mylenA\rlap{\usebox\myboxA}{\hskip 0.5\mylenA\usebox\myboxB}%
\fi}

\makeatother

\begin{document}

$A_{\xoverline{K}}$ vs $A_{\overline{K}}$

$A_{\text{\xoverline{K}}}$ vs $A_{\overline{K}}$

\end{document}

-
This (putting the xoverlined-subscript inside "\text") works well too. Thanks! – Ben G Aug 23 '14 at 1:59