TransWikia.com

how can I create q bar symbol in math mode just like hbar?

TeX - LaTeX Asked on August 7, 2021

I need create a new math symbol a q with a bar just like command hbar (h with a bar)

Thanks for your help, this is an example

documentclass[]{article}
usepackage{polyglossia}
setmainlanguage{spanish}
usepackage[dvipsnames,svgnames,x11names,]{xcolor}

usepackage{graphicx}
usepackage{amsmath,mathtools,calculator}
usepackage{commath}
usepackage{xfrac}
usepackage{fancybox}
usepackage{multicol}
usepackage{nicefrac}% UNIDADES SI
usepackage{units}% UNIDADES SI
usepackage{pgf,tikz,tikz-3dplot}
usepackage{pgfplots}
usepackage[american]{circuitikz}

usetikzlibrary{arrows,patterns}
usetikzlibrary{decorations.text,bending}
usepgfplotslibrary{fillbetween}
usepgfplotslibrary{groupplots,polar} %
usepgflibrary{arrows.meta}
usetikzlibrary{arrows.meta}
usetikzlibrary{decorations.markings}
usetikzlibrary{decorations.text}
usepgfplotslibrary{fillbetween}
usepgfplotslibrary{groupplots,polar}


usepackage{cancel}
usepackage{wasysym}
usepackage{txfonts}
usepackage{smartdiagram}
usepackage{siunitx}

usepackage{fourier} % math font

usepackage{fontspec}
%defaultfontfeatures{Mapping=tex-text}
setmainfont{Arial}


begin{document}
    

This is the document

$left(x+aright)^2$, I need a $q$ command with bar 



end{document}

One Answer

It depends on the math font you're using.

With Computer Modern, taking the cue from https://tex.stackexchange.com/a/551356/4427, but also from the fact that the bar is at a different position, namely mathchar '26, we can do

documentclass{article}
usepackage{amsmath}

makeatletter

newcommand{addbar@}[2]{%
  makebox[0pt][l]{%
    raisebox{#1}[0pt][0pt]{%
      kern#2
      $m@thmathchar'26$%
    }%
  }%
}

DeclareRobustCommand{qbar}{text{addbar@{-1.5ex}{0.01em}}q}

makeatother

begin{document}

Normal size $qne qbar$ and subscript $X_{q}ne X_{qbar}$

end{document}

enter image description here

For the fourier math fonts, the code should be modified, because they don't have the required bar in the expected place. I'll solve this by horizontally scaling a minus sign.

documentclass{article}
usepackage{amsmath}
usepackage{fourier}
usepackage{graphicx}

makeatletter

newcommand{addbar@}[3]{%
  makebox[0pt][l]{%
    raisebox{#1}[0pt][0pt]{%
      kern#2
      scalebox{0.6}[1]{$m@th-$}%
    }%
  }%
}

DeclareRobustCommand{qbar}{text{addbar@{-0.8ex}{0.2em}{1}}q}

makeatother

begin{document}

Normal size $qne qbar$ and subscript $X_{q}ne X_{qbar}$

end{document}

enter image description here

Correct answer by egreg on August 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP