I want to use the double right arrow for some Scala code in listings. I thought I'd use the mathescape option and $\Rightarrow$
. However, this "eats" whitespace around it, e.g. if I have
foo $\Rightarrow$ bar
only one space character is used in front and after the arrow, as if it were
foo $\Rightarrow$ bar
How do I enforce the whitespace? Could I embed the unicode character \u21D2
for the arrow instead of using mathescape?
EDIT: So with the comments I managed to produce a math escaped command that has a width of exactly three space characters in the verbatim font:
\newcommand{\ScalaRA}{{}\hspace{-0.04ex}\Rightarrow\hspace{-0.08ex}{}}
However, the problem of eating the white space is still there:
\begin{lstlisting}
abc d g j
a d $\ScalaRA$g $\ScalaRA$j
a def$\ScalaRA$ghi$\ScalaRA$j
\end{lstlisting}
In the second line, after using $\ScalaRA$
for the first time, subsequent whitespace is contracted: After the g
character there are two spaces but it is rendered only as one space:
So going in an out of the math mode leaves some "garbage" behind somehow. How to clean this up so that all three lines are perfectly aligned and the two space characters after g
in the second line are respected?
${}\Rightarrow{}$
\newcommand{\ScalaRA}{\ \ \Rightarrow\ \ }
and thenfoo$\ScalaRA$bar
. You could even use\quad
instead of two manual spaces.