Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've been using the mathdesign package (specifically with the garamond font), and whenever I try using \hbar, the bar is much too high and to the left.

In order to fix this, I wanted to know how to redefine \hbar to be an h with a bar that I can move around until it looks aesthetically pleasing.

share|improve this question

1 Answer 1

up vote 10 down vote accepted

LaTeX defines \hbar as \mathchar'26, followed by a backspace of 9 math units (\mkern-9mu), followed by the letter h. Or, more specifically,

\def\hbar{{\mathchar'26\mkern-9muh}% \hbar

In order to provide the flexibility to overlap these two elements (the bar and the letter), we break it into two separate components, focussing on moving the bar in the correct position and then merely typesetting the h afterwards. Moving the bar left/right is obtained by a straight-forward \hspace*. Raising/lowering the bar is performed by the macro \raisemath{<len>}{...}, obtained from How to raise a subscript?:

\makeatletter
\newcommand{\raisemath}[1]{\mathpalette{\raisem@th{#1}}}
\newcommand{\raisem@th}[3]{\raisebox{#1}{$#2#3$}}
\makeatother

Overlap of the bar with the h is obtained by \mathrlap (provided by the mathtools package). Easy macro definition is provided by \NewDocumentCommand from the xparse package.

\documentclass{article}
\usepackage{mathtools}% http://ctan.org/pkg/mathtools
\usepackage{xparse}% http://ctan.org/pkg/xparse
\makeatletter
\newcommand{\raisemath}[1]{\mathpalette{\raisem@th{#1}}}% \raisemath{<len>}{...}
\newcommand{\raisem@th}[3]{\raisebox{#1}{$#2#3$}}
\makeatother
\NewDocumentCommand{\newhbar}{O{0pt} O{0pt}}{% \newhbar[<horz len>][<vert len>]
  \ensuremath{\mathrlap{\raisemath{#2}{\hspace*{#1}{\mathchar'26\mkern-9mu}}}h}%
}
\begin{document}
\[
  \renewcommand{\arraystretch}{2}%
  \begin{array}{rl}
    \verb!\hbar!: & \hbar \\
    \verb!\newhbar!: & \newhbar \\
    \verb!\newhbar[4pt]!: & \newhbar[4pt] \\
    \verb!\newhbar[-1pt][1.5pt]!: & \newhbar[-1pt][1.5pt] \\
    \verb!\newhbar[2pt][-4pt]!: & \newhbar[2pt][-4pt] \\
    \verb!\tfrac{\hbar}{2}!: & \tfrac{\hbar}{2} \\
    \verb!\tfrac{\newhbar}{2}!: & \tfrac{\newhbar}{2} \\
    \verb!\tfrac{\pi}{\newhbar[0pt][-1pt]}!: & \tfrac{\pi}{\newhbar[0pt][-1pt]}
  \end{array}
\]

\end{document}

hbar that can be modified

You can play around with the optional parameters for \newhbar[<horz len>][<vert len>]. The first parameter <horz len> moves the bar left/right, while the second <vert len> moves it up/down. They are optional, but cannot be empty. It would be possible to extend this to accommodate such empty parameters.

share|improve this answer
    
Thanks! This is so close to what I want, I just can't seem to lower it (putting a negative number as the second optional argument isn't changing anything, and 0 is still a bit too high). –  thequark Oct 3 '11 at 2:08
    
@thequark: I've updated the solution to now take regular LaTeX lengths. You should be able to adequately specify negative lengths to move the bar up/down. –  Werner Oct 3 '11 at 2:30
    
@thequark: Sorry, there was a problem in my code - fixed now. –  Werner Oct 3 '11 at 2:42
    
Thanks! I'm certainly accepting this. Just thought I'd add one comment that it looks like the bar changes locations based on where it shows up in math (if it's at the beginning vs. after some other variables or equal sign). It's so subtle that it could just be my eyes... –  thequark Oct 3 '11 at 3:00
1  
@thequark: I've completely revamped the code and added some clarification for the use of certain elements. Hope this serves your needs. –  Werner Oct 3 '11 at 5:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.