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

9
  • 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 1 '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 1 '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 1 '15 at 18:38
  • @Sverre Your code must be changed anyway, that's the problem.
    – egreg
    Sep 1 '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 1 '15 at 18:46
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.

7
  • 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 2 '15 at 9:04
  • 1
    @Sverre I added a description
    – egreg
    Sep 2 '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 2 '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 2 '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 2 '15 at 11:00
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

7
  • When I try this code, the third (and final) word in my header (which is like textsc{Word1 Word2 Word3}) disappears ...
    – Sverre
    Sep 1 '15 at 18:00
  • 1
    @Sverre Using fancyhdr package, I can confirm the problem. Now let me think why... Sep 1 '15 at 18:32
  • @Sverre Actually, foolish me did not realize the problem exists even in normal text. Let me fix it. Sep 1 '15 at 18:35
  • @Sverre Fixed now. Sep 1 '15 at 18:40
  • 1
    @ezgranet I don't believe that this approach would allow that. However, there may be something possible with the \spaceskip parameter, for example, see tex.stackexchange.com/questions/600615/… Jun 23 at 17:05
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

1
  • Could you perhaps suggest an improvement along these lines at fontspec's Github page? I could also do it, but I would just link to your answer here.
    – Sverre
    May 22 '17 at 17:33
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.

3
  • 3
    An example of usage?
    – egreg
    Sep 1 '15 at 21:40
  • @egreg Example added :)
    – Aydin
    Sep 4 '15 at 9:18
  • I am not sure if it does exactly what OP asked for, but the sole purpose of this command is to increase spacing properly in small caps words and it solves problem with hyphenation. So, it could be usefull for the OP.
    – Aydin
    Sep 4 '15 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.