# Replace cmtt10 \char32 (visible cup space) with something more gentle?

I'm typesetting source code, and I want to replace cmtt10's \char32 with something easier on the eyes. I came up with something that I like, but I'm not pleased with the implementation. Here's how it looks... Top is standard cup space; bottom is my replacement version:

Is there a simpler or cleaner way to do what I did? (1) I'm having to include the tipa package for \textbottomtiebar. (2) It just so happens, for some reason that seems bizarre to me, that package aeguill modifies this bottom tie bar to make it wider, which happens to be just what I want. But that combination feels kludgey and fragile to me.

As to the core of the implementation, it uses \ooalign, \hss, and \hphantom to center a tiny bottom tie within the standard width of a space character:

\documentclass{article}

\usepackage{tipa} % For \textbottomtiebar
\usepackage[lm]{aeguill} % For some reason, widens the bottom tie

\newcommand{\visp}{%  Acronym for "VIsible SPace"
\ooalign{%
\relax\cr%
\hss{\tiny\textbottomtiebar{\ }}\hss\cr%
\hphantom{~}\cr%
}%
}

\begin{document}

\texttt{Hello,{\char32}world!{\char32}{\char32}I{\char32}am{\char32}a{\char32}string.} ~~~ $\backslash$char32
\vskip 1em
\texttt{Hello,{\visp}world!{\visp}{\visp}I{\visp}am{\visp}a{\visp}string.} ~~~ $\backslash$visp

\end{document}


For me, this is a big improvement over \char32, and I'd be perfectly happy replacing \char32 with this, but I doubt it's possible due to the way TeX's innards work. So I gave it the name \visp in my style preamble.

-
You can always create a virtual font and replace char 32 with a reference to the glyph from the other font. See tex.stackexchange.com/q/25852/243 –  topskip Jan 17 '12 at 12:38
Do you now want a nicer/better implementation or help exchanging the char32 with your macro? The latter can be done by making the space active. –  Martin Scharrer Jan 17 '12 at 14:15
@MartinScharrer — Mostly concerned with simplifying the underlying implementation, but overriding char32 is definitely a bonus. –  Todd Lehman Jan 18 '12 at 3:17

You have to patch the verbatim* environment and the \verb* command:

\documentclass{article}
\usepackage[T3,OT1]{fontenc}
\usepackage{etoolbox}
\usepackage[lm]{aeguill} % is it really needed?

\newcommand{\visp}{%
\makebox[.5em]{\vphantom{Xg}\raisebox{-\height}{\smash{\tiny
\fontencoding{T3}\fontfamily{cmr}\selectfont\textbottomtiebar}}}}

\makeatletter
\def\@space@visp{\begingroup\lccode\~=\ \lowercase{\endgroup\let~}\visp}
\pretocmd\@sverb{\catcode\ =\active\@space@visp}{}{}
\global\@namedef{verbatim*}{\@verbatim\catcode\ =\active\@space@visp\@sxverbatim}
\makeatother

\begin{document}

\begin{verbatim*}
abc def ghi
\end{verbatim*}

\verb*|abc def|

\end{document}


There's no reason to load tipa, as declaring the T3 encoding is sufficient.

It's quite strange to use the aeguill package nowadays, as loading the T1 encoding instead of OT1 is sufficient to get good guillemets with <<guillemets>>.

-
Nice, very nice, @egreg. I worked this back into my earlier solution and am quite happy that I need neither aeguill nor tipa to make this work. Thank you. Questions: (1) Why \makebox[.5em]? It does appear that cmtt10 characters are exactly .5em wide, but having that be hard-coded seems like an empirical derivation to me, which is why I was shooting for something with \hphantom{~}. (2) I really like the \vphantom{Xg} trick, but does it actually make a difference here? Seems not to when I use \ooalign for this. In any case, thank you once again. I have more than enough to go on. –  Todd Lehman Jan 18 '12 at 7:01
\hphantom{~} is as hard-coded as 0.5em; being in a fixed width font context, you can use \fontcharwd\fontA instead. –  egreg Jan 18 '12 at 9:10
[@egreg] Whoa, ok, so using \hphantom{~} here is actually less logically correct than picking a letter like A, even though they both happen to have the same width? I'm curious, why do you suggest \fontcharwd\fontA instead of \hphantom{A}? –  Todd Lehman Jan 18 '12 at 12:12
@ToddLehman I can put \fontcharwd\fontA in the optional argument to \makebox, so I can avoid tricks for centering afterwards. I guess that \widthof{A} with the calc package would do the same. –  egreg Jan 18 '12 at 12:46

You can make the space active and use your \visp macro. You can define a macro like \enablevisp which switches this on for the rest of the current group.

\begingroup
\catcode\ =\active%
\newcommand{\enablevisp}{%
\ttfamily%
\catcode\ =\active%
\def {\visp}%
}%
\endgroup%


This can be used like:

{\enablevisp{}Hello world! How are you?}


It is also possible to define a \textvisp macro:

\makeatletter
\newcommand{\textvisp}{%
\begingroup
\enablevisp
\@textvisp
}
\def\@textvisp#1{%
#1%
\endgroup
}
\makeatother


which then can be used like:

\textvisp{Hello world! How are you?}

-

Hmm, I found two other alternatives to \textbottomtiebar. One is \textvisiblespace and the other is \smile. The latter is a math-mode glyph which was too large to start with so I shrunk it using \scalebox.

I cleaned up the \textbottomtiebar solution thanks to @egreg's tips, and came up with three variants, shown below with \char32:

I want to share the code for these here in case anyone else finds them useful:

\documentclass{article}

\usepackage{graphicx}  % Only needed for the \smile version
\usepackage[T3,OT1]{fontenc}  % Only needed for the \textbottomtiebar version

% (a) \char32 version
\newcommand{\vispa}{%
\char32%
}

% (b) \textvisiblespace version
\newcommand{\vispb}{%
\ooalign{%
\relax\cr%
\noalign{\vskip.2ex}%
\textvisiblespace\cr%
\noalign{\vskip-.2ex}%
\hphantom{~}\cr%   Width of a space character
\vphantom{Xg}\cr%  Height of X, depth of g
}%
}

% (c) \textbottomtiebar version
\newcommand{\vispc}{%
\ooalign{%
\relax\cr%
\hss\smash{\tiny\fontencoding{T3}\fontfamily{cmr}%
\selectfont\textbottomtiebar}\hss\cr%
\hphantom{~}\cr%   Width of a space character
\vphantom{Xg}\cr%  Height of X, depth of g
}%
}

% (d) \smile version
\newcommand{\vispd}{%
\ooalign{%
\relax\cr%
\noalign{\vskip.5ex}%
\hss\scalebox{.4}{$\smile$}\hss\cr%
\noalign{\vskip-.5ex}%
\hphantom{~}\cr%   Width of a space character
\vphantom{Xg}\cr%  Height of X, depth of g
}%
}

% Just for demonstration and testing
\newcommand{\testvisp}[2]{%
\texttt{abc{#1}def{#1#1#1#1}ghi}''%
\quad{\tiny$\backslash$#2}\par
}

\begin{document}
\testvisp{\vispa}{char32}
\testvisp{\vispb}{textvisiblespace}
\testvisp{\vispc}{textbottomtiebar}
\testvisp{\vispd}{smile}
\end{document}
`
-