# Redefine hbar to work in super- or subscripts

I can redefine the \hbar command to use the "h" from the current math font as follows

\renewcommand{\hbar}{\raisebox{.5ex}{\rotatebox{15}{--}}\hspace{-0.5em}h}


For example in Times New Roman this gives

However, this breaks in super- or subscripts:

Is there a better way to achieve the same result, or is the a way to define \hbar differently when it appears as super- or subscript?

Use \text:

\documentclass{article}
\usepackage{amsmath,graphicx}

\renewcommand{\hbar}{%
\text{\raisebox{.45ex}{\rotatebox{15}{--}}\hspace{-0.5em}$h$}%
}

\begin{document}

$\hbar+e^{\hbar}+e^{\frac{i}{\hbar}}$

\end{document}