Explicit space character?

Nothing special is needed here; standard LaTeX provides \textvisiblespace:

\documentclass{article}

\begin{document}

An explicit space: a\textvisiblespace b

\end{document}

enter image description here

A simple variation of the original definition:

\DeclareTextCommandDefault{\textvisiblespace}{%
  \mbox{\kern.06em\vrule \@height.3ex}%
  \vbox{\hrule \@width.3em}%
  \hbox{\vrule \@height.3ex}}

allows to control the width using an optional argument:

\documentclass{article}

\newcommand\Vtextvisiblespace[1][.3em]{%
  \mbox{\kern.06em\vrule height.3ex}%
  \vbox{\hrule width#1}%
  \hbox{\vrule height.3ex}}

\begin{document}

An explicit space: a\textvisiblespace b

An explicit space: a\Vtextvisiblespace b

An explicit 1em space: a\Vtextvisiblespace[1em]b

An explicit 1cm space: a\Vtextvisiblespace[1cm]b

\end{document}

enter image description here


The simplest way to get it is by printing character 32 in typewriter font:

 \texttt{\char32}

You can store that character (a squat-u) inside a box and use it as necessary:

enter image description here

\documentclass{article}
\newsavebox{\spacebox}
\begin{lrbox}{\spacebox}
\verb*! !
\end{lrbox}
\newcommand{\aspace}{\usebox{\spacebox}}%
\begin{document}
Hi\aspace there!
\end{document}

You cannot directly store it in a macro, since verbatim content cannot be passed as an argument. However, boxing it via an lrbox environment works. Use the squat-u via \aspace.

Another option using fancyvrb:

\documentclass{article}
\usepackage{fancyvrb}
\fvset{showspaces=true}
\SaveVerb{verbspace}! !
\newcommand{\aspace}{\UseVerb{verbspace}}%
\begin{document}
Hi\aspace there!
\end{document}

Tags:

Symbols