Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm wondering about the best way to do an explicit space character (I don't even know what it's properly called), like the ones you get in the \begin{verbatim*} environment. The closest I've found is

\sqcup

in math mode, but it seems like a bit of a hack to me. Is there any text symbol for what I'm looking for?

share|improve this question
add comment

3 Answers 3

up vote 22 down vote accepted

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

share|improve this answer
    
that's pretty cool. Is there an easy way to control the amount of space to its left and right? I use this in monospace, and it gets too close to its right neighbour. –  lenz Jun 20 '13 at 13:03
    
@lenz please feel free to open a new question. –  Gonzalo Medina Jun 20 '13 at 13:49
add comment

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

 \texttt{\char32}
share|improve this answer
    
This relies imho to much on the font encoding. E.g. it won't work if you use xetex/fontspec or if you type in greek (LGR-encoding). –  Ulrike Fischer Apr 5 '12 at 9:01
add comment

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.

share|improve this answer
    
Thanks for that! –  Josh Chen Apr 5 '12 at 5:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.