6

I use xelatex, with Ubuntu font, and for some reason I can't insert a \textvisiblespace into my document - all that I get in result is a box: ``. Is there some way to fix that?

Example:

\documentclass[a4paper]{article}
\usepackage{xltxtra}
\setmainfont[Mapping=tex-text]{Ubuntu}
\begin{document}
\textvisiblespace
\end{document}
3
  • \textvisiblespace does not use any fonts. It constructs the "space character" as 3 rules. What kind of warnings do you receive in your output/.log file?
    – Werner
    Sep 22, 2012 at 16:40
  • 1
    @Werner - seems that it is not true - since the .log file contains this line: Missing character: There is no ␣ in font Ubuntu/ICU:mapping=tex-text,!. But I would be more than happy to draw it using three rules. How can I achieve this?
    – Rogach
    Sep 22, 2012 at 17:36
  • I've referenced a possible solution. It should work in your instance, but I'm unable to test it since I don't have the fonts installed.
    – Werner
    Sep 22, 2012 at 17:56

2 Answers 2

5

The font Ubuntu doesn't support the Unicode character 2423. Use

\setmainfont[Mapping=tex-text]{DejaVu Serif}

for example. Another alternative maybe:

\documentclass[a4paper]{article}
\usepackage{fontspec}
\setmainfont[Mapping=tex-text]{Ubuntu}
\newfontface\TVSp{DejaVu Serif}
\def\textvisiblespace{{\TVSp\char"2423}}

\begin{document}
\textvisiblespace
\end{document}
4
  • That's sad, I like that font. But maybe you can suggest more conventional font? I'm writing a technical documentation text, that would be probably read on computer screen.
    – Rogach
    Sep 22, 2012 at 17:45
  • see edited answer. However, Ubuntu is similiar to Bera Sans
    – user2478
    Sep 22, 2012 at 17:46
  • +1, but I suggest \protected\def. It's true that \TVSp will be "robust", but it's perhaps more desirable to write \textvisiblespace in case it appears in a moving argument.
    – egreg
    Sep 22, 2012 at 18:03
  • And where is the problem, if it appears for example in a \caption command??
    – user2478
    Sep 22, 2012 at 18:17
4

I don't have the font installed, so I'm not sure whether this is what you're after:

  1. Redefine \textvisiblespace after loading the Ubuntu font. The following definition is taken from latex.ltx:

    \def\textvisiblespace{%
       \mbox{\kern.06em\vrule height.3ex}%
       \vbox{\hrule width.3em}%
       \hbox{\vrule height.3ex}}
    
  2. Capture the contents of \textvisiblespace in a box before loading the new font and restore it afterwards:

    % Document preamble
    \newsavebox{\textvisiblespacebox}
    \begin{lrbox}{\textvisiblespacebox}\textvisiblespace\end{lrbox}
    % Insert font-related changes here
    \def\textvisiblespace{\usebox{\textvisiblespacebox}}
    

    Note that this will fix the setting of \textvisiblespace in \normalfont, so it won't change with size changes like \small (for example).

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .