The accepted answer in this question shows a neat redefinition of \textvisiblespace
, which I like to use because it doesn't produce a warning in math mode.
However, I use it with monospace in an equation, and it doesn't look perfect: the symbol is too close to its right neighbour. Here's an MWE:
\documentclass{article}
\newcommand\vartextvisiblespace[1][.3em]{%
\mbox{\kern.1em\vrule height.3ex}%
\vbox{\hrule width#1}%
\hbox{\vrule height.3ex}
}
\begin{document}
A formula with visible space in it:
\begin{equation}
s = \mathtt{a\vartextvisiblespace string\vartextvisiblespace sequence}
\end{equation}
\end{document}
What is a clean way to make it look better?
Best Answer
The glyph you're building is wider than letters in a monospaced font; use 0.5em as width and simplify the definition:
You can fine tune the width with
\vartextvisiblespace[.3em]
or similar.