# Without loading fontspec, \verb* cannot produce visible space under XeLaTeX

\verb* fails to produce visible space, under XeLaTeX. The problem repairs if package fontspec is loaded. By the way, \textvisiblespace produces visible space under both occasions.

Moreover, \verb* works alright under pdfLaTeX, but the output of \textvisiblespace is somewhat strange.

Questions

1. Why \verb* fails to produce visible space without fontspec under XeLaTeX?
2. What did fontspec do to get the problem repaired under XeLaTeX?
3. Under pdfLaTeX, why \textvisiblespace produces the different output (symbol) as what \verb*| | does? How to get the same output as \verb*| |, using symbol-generating command (like \textvisiblespace)?

Example

\documentclass{minimal}
%\usepackage{fontspec}    % problem repaired if fontspec loaded

\begin{document}
\verb*|x x|               % failed under XeLaTeX, succeed under pdfLaTeX
\texttt\textvisiblespace  % succeed under both engine,
%   but strange under pdfLaTeX
\end{document}


Output

Version info

• TeX Live 2018 3.14159265-2.6
• XeTeX 0.99999
• pdfTeX 1.40.19
• LaTeX2e <2018-04-01> patch level 2
• fontspec 2018/07/30 v2.6h

Font info under XeLaTeX

• font family \TU/lmtt/m/n/10
• font used texmf-dist/fonts/opentype/public/lm/lmmono10-regular.otf
• with fontspec, the space symbol inside \verb*{...} is mapped to symbol U+2423 (found by using \XeTeXtracingfonts=1)
• I think that counts as a latex bug, you could report it here github.com/latex3/latex2e/issues (or I could) Aug 31, 2018 at 19:43
• I have edited the description of problem to provide info under pdfLaTeX, and images as output. @DavidCarlisle Hope this info is helpful. Aug 31, 2018 at 20:11
• @DavidCarlisle I have reported here github.com/latex3/latex2e/issues/69 Sep 1, 2018 at 19:23

## 2 Answers

In the default OT1 encoding only the typewriter font has a visible space character (others don't). Therefore the default definition for \textvisiblespace that has to work with all fonts has a madeup definition that differs from the character used by \verb*. The latter uses the character in slot 32 as that works correctly if you cut and paste from a pdf (producing a space then).

To get a good visible space in all circumstances one should load the T1 encoding with pdfTeX,i.e.

\usepackage[T1]{fontenc}


With the new LaTeX release (planned for December 2018) the character used by \verb* or verbatim* will get a name \verbvisiblespace that by default will simply select slot 32. Thus it can be used with other fonts as long as they do have an appropriate glyph in that space and it (but will give wrong results if not) and it can be redefined for example to always use \textvisiblespace (killing the cut-and-paste in that case), e.g.,

\DeclareRobustCommand\verbvisiblespace{\textvisiblespace}


In LuaTeX or XeTeX the default also gets redefined in that case to explicitly use the space character from OT1/cmtt to keep the ability to cut and paste (that's for issue #69).

• The copying from PDF feature you mention does not apply to all PDF viewers. It worked with (an old) Acrobat Reader (v10.1.16) on my Mac but copying from Skim.app or Preview.app produced the U+2423 character. (mac os mavericks) using \usepackage[T1]{fontenc}, \verb*|a b| with pdflatex.
– user4686
Oct 12, 2018 at 17:50
• @jbu ininteresting, you are quite right. looks like the font has some glyph name then that says im a visiblespace and that seems to be evaluated by reader software despite the fact that for TeX it is an ordinary ascii 32 it typesets. Oct 12, 2018 at 20:58

With pdflatex use the latin modern font (lmodern package) and T1 font encoding.

 \documentclass{minimal}
%\usepackage{fontspec}    % problem repaired if fontspec loaded
\usepackage{lmodern}
\usepackage[T1]{fontenc}

\begin{document}
\verb*|x x|               % failed under XeLaTeX, succeed under pdfLaTeX
\texttt\textvisiblespace  % succeed under both engine,
%   but strange under pdfLaTeX
\end{document}


and with xelatex or lualatex uncomment the fontspec line and comment out both the lmodern and fontenc line.

• Thanks for your answer, this helps with my third sub-question. With xelatex, I know how to get right output. The purpose of this whole question, is to ask for the "why" part. Sep 1, 2018 at 8:07