[Tex/LaTex] Scalebox a maths letter

scaling

I am trying to rescale a letter in the Display. I tried to use the \scalebox{#}[#]{\mathscr{H}} (\mathscr{H} is the letter I am trying to rescale). But I think that only works for non-maths letters?

There are questions on here about resizing symbols etc, but they are for making them bigger or smaller, I want to make it 'thinner'.

Any help would be appreciated.

MWE:

\documentclass[12pt,a4paper]{book} 
\usepackage{geometry} 
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\newcommand{\H}{\scalebox{0.75}[1]{\mathscr{H}}}

\begin{document}

This is the letter that I am trying to make it work for $\H$.

\end{document}

Best Answer

\scalebox like \mbox switches to text mode and \mathscr generates an error because of the missing math mode.

\documentclass[12pt,a4paper]{book}
\usepackage[mathscr]{euscript}
\usepackage{graphicx}

\newcommand{\HScaled}{\scalebox{0.75}[1]{$\mathscr{H}$}}

\begin{document}
  $\HScaled$
\end{document}

Result

The following example uses \mathpalette to detect the current math style. Also, it provides an optional parameter with the horizontal scaling factor.

\documentclass[12pt,a4paper]{book}
\usepackage[mathscr]{euscript}
\usepackage{graphicx}

% \newcommand{\HScaled}{\scalebox{0.75}[1]{$\mathscr{H}$}}

\makeatletter
\newcommand{\HScaled}[1][0.75]{%
  \mathpalette\@HScaled{#1}%
}
\newcommand*{\@HScaled}[2]{%
  % #1: math style
  % #2: horizontal scale factor
  \scalebox{#2}[1]{$#1\mathscr{H}\m@th$}%
}
\makeatother

\begin{document}
  \newcommand{\Test}[1]{%
    \[ #1^{#1^{#1}} \]
  }
  \Test{\HScaled}
  \Test{\HScaled[.5]}
  \Test{\HScaled[1.5]}
\end{document}

Result with \mathpalette