[Tex/LaTex] How to write a character overlapping another character

symbols

How can I write two characters in the same place?

In particular, I want to write an arrow $\rightarrow$, and then write a letter such that the arrow strikes through the letter. I found some similar questions (Range symbol over character, Substitute a character by another one (Lualatex), etc.) but they are not exactly the same question.

Best Answer

Not clear if you want it in text or math...

\documentclass{article}
\usepackage{stackengine}
\begin{document}
In te\stackengine{0pt}{x}{$\rightarrow$}{O}{c}{F}{T}{L}t...

$\ensurestackMath{\stackengine{0pt}{y}{\rightarrow}{O}{c}{F}{T}{L}} = mx + b$
\end{document}

enter image description here

Also, it is not clear if you want the arrow's width to be accounted for:

\documentclass{article}
\usepackage{stackengine}
\begin{document}
In te\stackengine{0pt}{x}{$\rightarrow$}{O}{c}{F}{F}{L}t...

$\ensurestackMath{\stackengine{0pt}{y}{\rightarrow\!}{O}{c}{F}{F}{L}} = mx + b$
\end{document}

enter image description here

Other things that can be easily adjusted above include horizontal alignment (currently centered) as well as vertical height of arrow placement (currently placed at its natural height).

Once the specifics are decided on the use case, this can be easily encapsulated in a macro.

Below, keeping up with the egregs, I implement a macro version (\overarrow) for math that preserves the math style:

\documentclass{article}
\usepackage{stackengine,scalerel}
\newcommand\overarrow[1]{\ThisStyle{\ensurestackMath{%
  \stackengine{0pt}{\SavedStyle#1}{\SavedStyle\rightarrow\!}{O}{c}{F}{F}{L}}}}
\begin{document}
$\overarrow{y} = mx_{\overarrow{z}} + b$
\end{document}

enter image description here