# Barred q symbol doesn't scale properly

Using the answer to the question moving the bar on hbar (copy/paste and tweaking the parameters, and replacing mathchar'26 by the shorter mathchar'55), I was able to create a barred q. Unfortunately, this symbol behaves badly when I use \qbar as an index.

I use the font package eulervm:

\documentclass[11pt]{scrartcl}
\usepackage{eulervm}
\usepackage{mathtools}
\makeatletter
\newcommand{\raisemath}[1]{\mathpalette{\raisem@th{#1}}}
\newcommand{\raisem@th}[3]{\raisebox{#1}{$#2#3$}}
\makeatother
\newcommand{\qbar}{\ensuremath{\mathrlap{\raisemath{-3.2}{\hspace*{3.2pt}
{\mathchar'55\mkern-9mu}}}q}}

\begin{document}
{\Huge$\qbar$} \qquad $\qbar$ \qquad $U_{\qbar}$
\end{document}


What code should I use to get the same symbol in both cases? I also noticed that I had to reconfigure the paramters in the definition of \qbar for this question, presumably there was some interaction with the other packages or options... This is first time I'm attempting to create a symbol in this fashion. If you know of better ways, or can provide me with a resource that explains how to do this in general, that would be great too!

• Could someone include a picture of the output please? – Olivier Bégassat Oct 27 '14 at 21:59
• No, because the example doesn't compile – egreg Oct 27 '14 at 22:06
• @egreg It compiles on my end... – Olivier Bégassat Oct 27 '14 at 22:08
• I agree with egreg: your code didn't compile. I have edited it and it does now but all of the bars on the q's are out. – Andrew Oct 27 '14 at 22:12
• @egreg thanks! I guess the package was already loaded from my main document (?) – Olivier Bégassat Oct 27 '14 at 22:13

I'd use a different approach; the absolute measures like 3.2pt can work just for one size.

\documentclass[11pt]{scrartcl}
\usepackage{eulervm,mathtools}

\makeatletter
\newcommand{\qbar}{\text{\q@bar}}
\newcommand{\q@bar}{%
\vphantom{$\m@th q$}%
\ooalign{%
$\m@th q$\cr
\hidewidth\smash{\raisebox{-0.7ex}{$\m@th\mathchar'55$}}\hidewidth\cr}%
}
\makeatother

\begin{document}
\fbox{\Huge $q$}\,\fbox{\Huge$\qbar$} \quad $\qbar$ \quad $U_{\qbar}\ne U_{q}$
\end{document}


The two \fbox command show that the bounding box of \qbar is the same as for q.

If you want that the bar crosses the descender, then add some horizontal space, changing the definition of \q@bar into

\newcommand{\q@bar}{%
\vphantom{$\m@th q$}%
\ooalign{%
$\m@th q$\cr
\hidewidth\kern.3em\smash{\raisebox{-0.7ex}{$\m@th\mathchar'55$}}\hidewidth\cr}%
}


The above input would give

• How would you move the bar to the right? So that it sticks out equally to both sides of the vertical bar? – Olivier Bégassat Oct 27 '14 at 22:25
• Thank you very much, this solves it : ) Where can I learn how to write this properly, as opposed to copy/pasting answers form TSE? – Olivier Bégassat Oct 27 '14 at 22:27
• @OlivierBégassat Maybe 0.33em is better; adjust to suit. – egreg Oct 27 '14 at 22:27

If you are able to use Lua- or XeLaTeX, you might want to use the unicode U+A757 for this. Just look for a font which supports this symbol and load it like in my MWE:

% arara: lualatex

\documentclass{article}
\usepackage{fontspec}
\setmainfont{EB Garamond}
\usepackage{mathtools}
\newcommand*{\qbar}{\ensuremath{\text{\symbol{"A757}}}}

\begin{document}
A test for EB Garamond in math mode \fbox{$\qbar$} \fbox{$\mathrm{q}$} and text mode \fbox{\qbar} \fbox{q}.
\end{document}


Unluckily I can't find a slanted or italic version.

You may also define a symbol with another font as your surrounding text:

% arara: lualatex

\documentclass{article}
\usepackage{fontspec}
\usepackage{mathtools}
\newcommand*{\qbar}{\ensuremath{\text{{\setmainfont{quivira.otf}\symbol{"A757}}}}}

\begin{document}
$\qbar_{\qbar_\qbar}$
\end{document}


Here are some different symbols I could find on my system:

% arara: lualatex

\documentclass{article}
\usepackage{fontspec}

\begin{document}
\setmainfont{EB Garamond}\symbol{"A757}
\setmainfont{dejavusans.ttf}\symbol{"A757}
\setmainfont{freeserif.otf}\symbol{"A757}
\setmainfont{quivira.otf}\symbol{"A757}

%\setmainfont{EB Garamond}\symbol{"A756} % not available in upper case
\setmainfont{dejavusans.ttf}\symbol{"A756}
\setmainfont{freeserif.otf}\symbol{"A756}
\setmainfont{quivira.otf}\symbol{"A756}
\end{document}


• Is there some quick (scriptable?) way in which you searched your fonts for a particular symbol? A note on how you did that would be generally useful. – dedded Oct 28 '14 at 11:28
• @dedded Just use the "Local Font List" which is linked in the second link in my answer. Here it is for this very character: fileformat.info/info/unicode/font/… – LaRiFaRi Oct 28 '14 at 11:30