1

I want to write an X with a bar on top. The X should be upright, but in headings it should be italics. The bar should be in the correct position. So my question is a variant of Aligning \overline to "italics" font. I started to play with jfbu's solution but cannot get the original upshape position to work.

enter image description here

\documentclass{article}

\usepackage{xspace}

\newbox\usefulbox

\makeatletter
\def\getslant #1{\strip@pt\fontdimen1 #1}

\def\skoverline #1{\mathchoice
 {{\setbox\usefulbox=\hbox{$\m@th\displaystyle #1$}%
    \dimen@ \getslant\the\textfont\symletters \ht\usefulbox
    \divide\dimen@ \tw@ 
    \kern\dimen@ 
    \overline{\kern-\dimen@ \box\usefulbox\kern\dimen@ }\kern-\dimen@ }}
 {{\setbox\usefulbox=\hbox{$\m@th\textstyle #1$}%
    \dimen@ \getslant\the\textfont\symletters \ht\usefulbox
    \divide\dimen@ \tw@ 
    \kern\dimen@ 
    \overline{\kern-\dimen@ \box\usefulbox\kern\dimen@ }\kern-\dimen@ }}
 {{\setbox\usefulbox=\hbox{$\m@th\scriptstyle #1$}%
    \dimen@ \getslant\the\scriptfont\symletters \ht\usefulbox
    \divide\dimen@ \tw@ 
    \kern\dimen@ 
    \overline{\kern-\dimen@ \box\usefulbox\kern\dimen@ }\kern-\dimen@ }}
 {{\setbox\usefulbox=\hbox{$\m@th\scriptscriptstyle #1$}%
    \dimen@ \getslant\the\scriptscriptfont\symletters \ht\usefulbox
    \divide\dimen@ \tw@ 
    \kern\dimen@ 
    \overline{\kern-\dimen@ \box\usefulbox\kern\dimen@ }\kern-\dimen@ }}%
 {}}
\makeatother


\newcommand{\xbar}{$\skoverline{X}$\xspace}
\newcommand{\xbarup}{\mbox{$\overline{\mbox{X}}$}\xspace}

\newcommand{\xbarupsk}{\mbox{$\skoverline{\mbox{X}}$}\xspace}


\begin{document}\thispagestyle{empty}

\xbar-Theory
\emph{\xbar-Theory} (correct)

\xbarup-Theory (correct)
\emph{\xbarup-Theory}

\xbarupsk-Theory
\emph{\xbarupsk-Theory}





\end{document}
Stefan Müller
  • 6,901
  • 3
  • 29
  • 61

0 Answers0