Is there a way to globally (or in an environment) set the 'space' glyph as the interword space? I'm importing the OpenType font via fontspec which has a specially designed 'space' glyph that I want to use.
Asked
Active
Viewed 681 times
9
Joseph Wright
- 259,911
- 34
- 706
- 1,036
Lex Luengas
- 93
2 Answers
5
You can, but doing it globally is something I wouldn't dare.
The key is to use a modification of Marcin Woliński's TeX Pearl “How to make a box disappear at a line break” I have already used in my answer to Check if at begin of a line
\documentclass{article}
\usepackage[T1]{fontenc} % or with fontspec
\usepackage[polish]{babel} % just because the original text is in Polish
\newenvironment{visiblespace}
{\par\obeyspaces
\endlinechar=`\ %
\begingroup\lccode`~=`\ \lowercase{\endgroup
\def~}{\setbox0\hbox{\char`\ }% change here with the location of the glyph you want
\dimen0=\wd0
\hskip 1pt plus 2pt
\cleaders\box0 \hskip\dimen0
\hskip 1pt plus 2pt }%
}
{\unskip\par}
\begin{document}
\begin{visiblespace}
Ten typowy testowy akapit tekstu daje przy okazji rodzaj filigranowego
wysypu hodowli pieczarek w zielonym kasztanie regloryfikacji
stanowisk ministerialnych i podsypanych minimalistom jako fetysz
zaduchu studziennych barykad.
\end{visiblespace}
\end{document}

4
as \char32 gives the glyph you want you could do
{\catcode`\ =12a b c d e f g }
but note that is no longer a word space put rather punctuation, so you will disable hyphenation, and space stretching for justification, so it depends on your use case, whether that is an acceptable result.
David Carlisle
- 757,742
-
This effectively answers my question. In my case, somehow, consecutive spaces are kerned negatively by half the 'space' glyph width. Also, spaces at the end of lines are not displayed. – Lex Luengas Dec 12 '13 at 11:15
-
@LexLuengas TeX's input scanner removes spaces at end of line at a very early stage before tokenisation as part of its normalisation of line ending and record types for different machine architectures, there is no way to make tex see those (perhaps luatex is different, not sure) – David Carlisle Dec 12 '13 at 11:52
feature filewith LuaLaTeX? You can make a substitution like in (http://tex.stackexchange.com/questions/142605/fixing-fonts-with-luatex-feature-files). You should find the proper way to refer to the space character. (Not sure if feature files can be used with\addfontfeature) – TeXtnik Dec 11 '13 at 08:50listingspackage has options for showing those spaces as visible glyphs. Perhaps if you use your font in a\obeyspacesenvironment you can get also what you want. – JLDiaz Dec 11 '13 at 09:21[\char32]give you the glyph you want? – David Carlisle Dec 11 '13 at 09:26\char32shows the space glyph I need, thanks. However, the contextual substitutions of the font don't seem to work for the manually inserted 'space' glyph. – Lex Luengas Dec 11 '13 at 09:32