5

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.

enter image description here

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!

2 Answers2

4

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}

enter image description here

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

enter image description here

egreg
  • 1,121,712
3

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}

enter image description here

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}

enter image description here

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}

enter image description here

LaRiFaRi
  • 43,807
  • 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: http://www.fileformat.info/info/unicode/font/fontlist.htm?text=%EA%9D%97+-+LATIN+SMALL+LETTER+Q+WITH+STROKE+THROUGH+DESCENDER+%28U%2BA757%29 – LaRiFaRi Oct 28 '14 at 11:30