12

With tracking activated for small caps, it can be a little bit hard to detect interword spaces. Cf. below.

\documentclass{article}
\usepackage{fontspec}
    \setmainfont{Libertine Serif}[
        SmallCapsFeatures = {Letters = SmallCaps, LetterSpace = 5}]
\begin{document}
The title of my article is \textsc{This is the moment your life changed forever}.
\end{document}

enter image description here

I'd like to increase the space between words in small caps, therefore, but only when words on either side are in small caps (i.e. there should be no extra space before the first word written in small caps or after the last word).

I would've thought I could do this by adding WordSpace = <> to SmallCapsFeatures, but this will change the interword space everywhere.

\documentclass{article}
\usepackage{fontspec}
    \setmainfont{Libertine Serif}[
        SmallCapsFeatures = {Letters = SmallCaps, LetterSpace = 5, WordSpace = 5}]
\begin{document}
The title of my article is \textsc{This is the moment your life changed forever}.
\end{document}

enter image description here

Sverre
  • 20,729
  • 1
    I understand you want to be on the bleeding edge, but TeX distributions only feature the old versions of Libertine. Testing your code always requires changing the font name. – egreg Sep 01 '15 at 18:29
  • @egreg I see your point, but in order to use \setmainfont{Linux Libertine O} too, you'd have to install the font on your system, right? (It being included in texlive doesn't mean it's a system font). So it doesn't require that much more to install Khaled Hosny's libertine fork than to install a font found in TeX? – Sverre Sep 01 '15 at 18:34
  • No, "Linux Libertine O" is distributed automatically with TeXLive and (full installations of) MikTeX. No need to go through any additional installation steps with "Linux Libertine O". – Mico Sep 01 '15 at 18:38
  • @Sverre Your code must be changed anyway, that's the problem. – egreg Sep 01 '15 at 18:39
  • @Mico I thought \setmainfont looked for system fonts. It also searches through the fonts in your TeX distribution? That's news to me, then, and would surely make @egreg's point even more pertinent. – Sverre Sep 01 '15 at 18:46
  • I don't know how font discovery works under Xe(La)TeX. With Lua(La)TeX, all fonts that the utility program luaotfload-tool manages to locate and index -- from the man page: "luaotfload-tool: generate and query the Luaotfload font names database" -- can be handled with \set[main,sans,mono,*]font. – Mico Sep 01 '15 at 18:51
  • @egreg My code must be changed only beacuse it's not necessary to install a font as a system font if it's included in your tex distribution. I didn't know that. I thought you'd have to manually install those fonts as system fonts too when using fontspec. That's why I couldn't see the big difference between installing font x that comes with tex and installing font y that doesn't come with tex. – Sverre Sep 02 '15 at 09:03
  • @egreg Here's an example of how setting \setmainfont{<font name>} for a font that comes with tex live that I haven't manually installed as a system font won't compile for me. – Sverre Sep 03 '15 at 05:34
  • Many people have their systems configured to include the TL font directories in the system font search paths. I don't know about OS X or Windows, but this is pretty standard for everyone else. And there are lots of everyone else using TeX SE :-). Plus, it is very, very common for this everybody else to already have the relevant versions of Libertine installed in /usr/share/fonts also. If they are not already installed, they are almost certainly pre-packaged. The same is not true for the forked fonts. To use those I have to track them down and then create a package and then install it. – cfr Jul 02 '16 at 16:30

4 Answers4

7

You want to set \spaceskip to a non null value (and perhaps also \xspaceskip).

\documentclass{article}
\usepackage{fontspec}
\usepackage{xpatch}

\setmainfont{Linux Libertine O}[
  SmallCapsFeatures = {
    Letters = SmallCaps,
    LetterSpace = 20,
  }
]

\xapptocmd{\scshape}
  {\spaceskip=3\fontdimen2\font plus 3\fontdimen3\font minus \fontdimen4\font
   \xspaceskip=2\fontdimen7\font}
  {}{}


\begin{document}

The title of my article is \textsc{This is the moment your life changed forever}.
Here the space is normal.

\end{document}

enter image description here

The values are of course exaggerated: here the interword space is set to three times the normal value.

When \spaceskip has a nonzero value, it is used for the interword space instead of the default font defined one. The relevant font parameters are

  1. \fontdimen2\font (the natural width of the interword space)
  2. \fontdimen3\font (the stretch component)
  3. \fontdimen4\font (the shrink component)

Thus, specifying

\spaceskip=3\fontdimen2\font plus 3\fontdimen3\font minus \fontdimen4\font

we're telling to use three times the normal interword space, stretchable three times as much it is normally and shrinking it the same as the default. The parameter \xspaceskip is related to the space factor: when the space factor is >2000, TeX adds its value to the normal interword space (this is how the space is increased after periods); by default TeX uses \fontdimen7\font, but it uses \xspaceskip if it is nonzero.

egreg
  • 1,121,712
  • Could you elaborate on your code here? I have no idea what numbers do what here, so I wouldn't know what to tweak in order to modify the interword space. – Sverre Sep 02 '15 at 09:04
  • 1
    @Sverre I added a description – egreg Sep 02 '15 at 10:32
  • I have to admit that I didn't understand the bit about \xspaceskip. It also doesn't affect the spacing in this MWE. – Sverre Sep 02 '15 at 10:50
  • @Sverre No, the space factor never enters into action because there's no punctuation. On the other hand, since Norwegian probably sets \frenchspacing, the space factor is completely irrelevant anyway. – egreg Sep 02 '15 at 10:57
  • I discovered a problem when using this in my document. It adds more vertical space between paragraphs instead of just using \baselineskip. – Sverre Sep 02 '15 at 11:00
  • @Sverre I don't think so. – egreg Sep 02 '15 at 11:09
  • Then there's something else in my code that makes this happen when I add your code (it also happens when I add Steven's code with \theskip). I'll try (later) to figure out what the culprit is. – Sverre Sep 02 '15 at 11:17
5

Here, \theskip defines the new inter-word space inside \textsc{}. EDITED to fix bug which chopped last word. I also show that it works in headers in this MWE.

\documentclass{article}
\let\svtextsc\textsc
\def\theskip{\hspace{4ex}}
\def\textsc#1{\def\myskip{}\wspaceout#1 \relax\relax}
\def\wspaceout#1 #2\relax{%
  \myskip\svtextsc{#1}\let\myskip\theskip\ifx\relax#2\else\wspaceout#2\relax\fi}
% HEADER STUFF
\usepackage{fancyhdr}
\lhead[\rm\thepage]{\textsc{Word1 Word2 Word3}}
\rhead[xxx]{\rm\thepage}
\pagestyle{fancy}
\begin{document}
The title of my article is \textsc{This is the moment your life changed forever}. 
And some more text

\def\theskip{\hspace{1.5ex}}
The title of my article is \textsc{This is the moment your life changed forever}. 
And some more text

\def\theskip{\ }
The title of my article is \textsc{This is the moment your life changed forever}. 
And some more text

\def\theskip{\hspace{2ex}}
The title of my article is \textsc{This is the moment your life changed forever}. 
And some more text
\end{document}

enter image description here

3

Imho fontspec could do better here and allow WordSpace to be set for small caps alone. The following is not meant as usable document code -- it redefines an internal command of fontspec and probably miss some cleaning up -- but only as proof of concept:

\documentclass{article}
\usepackage{fontspec}

\ExplSyntaxOn\makeatletter
\cs_set:Nn \__fontspec_declare_shapes_smcaps:nn
 {
    \tl_if_empty:NF \l__fontspec_nfss_sc_tl
     {
      \__fontspec_DeclareFontShape:xxxxxx {\l__fontspec_nfss_enc_tl} {\l_fontspec_family_tl} {#1}
        { \__fontspec_combo_sc_shape:n {#2} } {\l__fontspec_nfss_sc_tl} {\l__fontspec_postadjust_tl
         \l__uf_fontspec_postadjust_sc_tl
        }
     }
  }

 \tl_set:Nn \l__uf_fontspec_postadjust_sc_tl
     {
      \fontdimen 2 \font = 5 \fontdimen 2 \font
      \fontdimen 3 \font = 5 \fontdimen 3 \font
      \fontdimen 4 \font = 5 \fontdimen 4 \font
     }

\ExplSyntaxOff      

 \setmainfont{Linux Libertine O}[
        SmallCapsFeatures = {Letters = SmallCaps, LetterSpace = 5,}
           ]

\ExplSyntaxOn
%should not affect Arial:
 \tl_clear:N \l__uf_fontspec_postadjust_sc_tl
\ExplSyntaxOff 
 \setsansfont{Arial}    
\begin{document}
The title of my article is

\textsc{This is the moment your life changed forever}.

{\large \scshape Large: the title of my article} 

\textsc{\bfseries the title of my article}

the title of my article 

\sffamily some words in sans 

\scshape some words in small caps sans

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
1

Your problem should be solved by using \caps command form soul package. An example:

\documentclass{article}
\usepackage{soul}
\begin{document}
   \scshape{abcde fghijk lmnopqr stuvwxyz abcdefghij klmnopqr stuvwxyz}

   \caps{abcde fghijk lmnopqr stuvwxyz abcdefghij klmnopqr stuvwxyz}
\end{document}

You can change the font, spacing and even the command in use with command \capsdef.

Usage:

\capsdef{<font>}{<command>}{<inter-letter space>}{<inner space>}{<outer space>}

It seems that you want to increase <inner-space>. It can be done as follows:

\capsdef{T1/ppl/m/n/5-15}{\scshape}{.16em}{.6em}{.2em}

This also sets the command to \scshape so you won't need to use \caps.

Aydin
  • 1,983