9

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.

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
  • Did you try to use a feature file with 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:50
  • @zunbeltz The interword spaces that are inserted by LaTeX are not glyphs from the font. The font I'm using has a non-empty 'space' character. LaTeX apparently ignores that glyph, and uses a predefined metrical value to render the space. – Lex Luengas Dec 11 '13 at 09:11
  • The interword space used by tex to compose paragraphs is not a fixed-width glyph, but a stretchable glue. Only in verbatim-like environments you can get "true" spaces. listings package has options for showing those spaces as visible glyphs. Perhaps if you use your font in a \obeyspaces environment you can get also what you want. – JLDiaz Dec 11 '13 at 09:21
  • @LexLuengas does [\char32] give you the glyph you want? – David Carlisle Dec 11 '13 at 09:26
  • @DavidCarlisle \char32 shows 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

2 Answers2

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}

enter image description here

egreg
  • 1,121,712
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