[Tex/LaTex] how to draw a little crown above a math symbol

accents

I'd like to have a command \crown that would draw a little crown above a symbol, e.g. $\crown x$ should show an $x$ with a little crown over it. I know I can use the accents package to declare any symbol as an accent, but how do I create a compatible symbol?

Best Answer

Go out to the web and find a crown image that suits, such as http://images.clipartpanda.com/queen-crown-clipart-black-and-white-black-crown-clipart-nTE8GkyTA.gif. If it is not the proper format (this is a gif), use your graphics software (e.g., MSPaint) to save it as a jpeg.

MATH MODE version

Then, just patch its name into the \crownset macro definition below, adjusting the leading \kern if the image had asymmetric horizontal space about it. Other parameters that can be tweaked include the overset gap, currently set to .7pt, and image width, currently set to 1.2\LMex.

The stack is set up to ignore the width of the crown during the typeset, so that \crownset is does not adversely affect the horizontal spacing.

EDITED to account for slant of math font.

\documentclass{article}
\usepackage{stackengine,graphicx,scalerel}
\usepackage[nopar]{lipsum}
\newcommand\crownset[1]{\ensurestackMath{\ThisStyle{%
  \setbox0=\hbox{$\ThisStyle#1$}%
  \stackengine{.7pt}{\SavedStyle#1}{\kern\dimexpr-.1\LMex+.25\ht0\relax%
  \includegraphics[width=1.2\LMex]%
  {queen-crown-clipart-black-and-white-black-crown-clipart-nTE8GkyTA}}%
  {O}{c}{F}{T}{S}}}}
\begin{document}
\[
y = m \crownset x + \frac{\crownset{f}}{\crownset y^2}
\]
\[
\scriptstyle y = m \crownset x + \frac{\crownset{f}}{\crownset y^2}
\]
\[
\scriptscriptstyle y = m \crownset x + \frac{\crownset{f}}{\crownset y^2}
\]
\end{document}

enter image description here

If I don't like that crown, just find another, such as https://openclipart.org/image/2400px/svg_to_png/242116/Royal-Crown-Silhouette.png and substitute the file name into the macro:

enter image description here

TEXT MODE version

The stack is set up to ignore the width of the crown during the typeset, so that \crownset is does not adversely affect the kerning of the letter i.

The text version is also \smashed to avoid affecting the line spacing.

\documentclass{article}
\usepackage{stackengine,graphicx}
\usepackage[nopar]{lipsum}
\newcommand\crownset[1]{\stackengine{.3pt}{#1}{\kern-.07em%
  \smash{\includegraphics[width=0.5em]%
  {queen-crown-clipart-black-and-white-black-crown-clipart-nTE8GkyTA}}}%
  {O}{c}{F}{T}{S}}
\begin{document}
\lipsum[1]
\crownset A new d\crownset ay \crownset is dawning.
\lipsum[2]
\end{document}

enter image description here

Related Question