1

I am finding that the fontspec package does not automatically correct the interword space after slanted text (\textsl{} or \slshape) even when I add \/ after the slant text. (Page 14 of the TeXbook recommands adding a slanted or italic correction after using slanted or italicized test.) I provide a MWE.

\documentclass{article}
\parindent=0pt
\usepackage{fontspec}
\setmainfont{Source Serif 4}[%Available for free on Google Fonts.
    Kerning=On%
    ,SlantedFont={Source Serif 4}%\textsl{},\slscape
        ,SlantedFeatures={%
            Kerning=On%
            ,FakeSlant=0.33%I use an exaggerated value to more clearly explain the issue.
        }%
]
\begin{document}
Fontspec does \textsl{not} add the slant correction automatically.\\
\textsl{text} text\quad\textsl{hello world} hello world\\
\textsl{text\/} text\quad\textsl{hello world\/} hello world\\
Fontspec adds the italic correction automatically.\\
\textit{text} text\quad\textit{hello world} hello world\\
\textit{text\/} text\quad\textit{hello world\/} hello world\\
\end{document}

EDIT: I have worked on this issue and created the following macro, contained in the following MWE. The macro adds and calculates the extra spacing based off the height of the last slanted letter.

\documentclass{article}
\raggedright
\usepackage{xstring}
\usepackage{fontspec}
\setmainfont{Source Serif 4}[%Available for free on Google Fonts.
    Kerning=On%
    ,SlantedFont={Source Serif 4}%\textsl,\slshsape
        ,SlantedFeatures={%
            Kerning=On%
            ,FakeSlant=0.18
            }
]
\newcommand\slantfactor{0.18}
\parindent=0pt
\newcommand{\textslant}[1]{%
    \textsl{#1}%
    \begingroup%
    \sbox0{\StrRight{#1}{1}}%Requires package xstring.
    \hspace{\fpeval{sin(atan(\slantfactor))}\ht0}%
    \endgroup%
}
\begin{document}
\textsl{shell} helms\quad No Slant Correction\\
\textslant{shell} helms\quad With Slant Correction\\
shell helms\quad Regular Text\\
\textsl{bulk} helms\quad No Slant Correction\\
\textslant{bulk} helms\quad With Slant Correction\\
bulk helms\quad Regular Text\\
\textsl{quad} helms\quad No Slant Correction\\
\textslant{quad} helms\quad With Slant Correction\\
quad helms\quad Regular Text\\
\end{document}

EDIT: I've used the result in my other question to answer this question (hopefully I'm correct). See: Fontspec Slant Units

User23456234
  • 1,808

1 Answers1

1

I believe that using the height of the last glyph is not the correct solution: the correction for “k” should be the same as for “x” and only “dfl” should get a larger correction, because of their shape. Probably, “f” should get even a bigger one, depending on the actual font.

You can use \nocorr as in standard LaTeX if the correction is not wanted.

Here's a solution that can easily be extended.

\documentclass{article}
\usepackage{fontspec}

\newcommand\slantfactor{0.18}

\setmainfont{Libertinus Serif}[ Kerning=On, SlantedFont=*, SlantedFeatures={ Kerning=On, FakeSlant=\slantfactor, }, ]

\NewCommandCopy\otextsl\textsl % for comparisons

\ExplSyntaxOn \RenewDocumentCommand{\textsl}{m} { { \slshape #1 \slanted_corr:e {\tl_item:nn { #1 } { -1 }} } }

\fp_const:Nn \c_slanted_corr_factor_fp { sin(atan(\slantfactor)) }

\cs_new_protected:Nn \slanted_corr:n { \str_if_eq:nnF { #1 } { \nocorr } { \str_if_in:nnTF { dfl } { #1 } { \slanted_corr_big:n { #1 } } { \slanted_corr_small:n { #1 } } } } \cs_generate_variant:Nn \slanted_corr:n { e }

\cs_new_protected:Nn \slanted_corr_big:n { \str_case:nn { #1 } { {f}{\slanted_corr_big_do:nn { f } { 1.1 }} } { \slanted_corr_big_do:nn { #1 } { 1 } } } \cs_new_protected:Nn \slanted_corr_big_do:nn { \kern \fp_eval:n { (#2) * \c_slanted_corr_factor_fp } \fontcharht\font`#1 \scan_stop: } \cs_new_protected:Nn \slanted_corr_small:n { \str_if_in:nnF { ., } { #1 } { \kern \fp_eval:n { \c_slanted_corr_factor_fp } ex } }

\ExplSyntaxOff

\setlength{\parindent}{0pt} \raggedright

\begin{document}

\otextsl{shelf} helms\quad No Slant Correction

\textsl{shelf} helms\quad With Slant Correction

shelf helms\quad Regular Text

\otextsl{shell} helms\quad No Slant Correction

\textsl{shell} helms\quad With Slant Correction

shell helms\quad Regular Text

\otextsl{bulk} helms\quad No Slant Correction

\textsl{bulk} helms\quad With Slant Correction

bulk helms\quad Regular Text

\otextsl{quad} helms\quad No Slant Correction

\textsl{quad} helms\quad With Slant Correction

quad helms\quad Regular Text

\otextsl{quad.} helms\quad No Slant Correction

\textsl{quad.} helms\quad With Slant Correction

quad. helms\quad Regular Text

\otextsl{quad}. helms\quad No Slant Correction

\textsl{quad\nocorr}. helms\quad With Slant Correction

quad. helms\quad Regular Text

\end{document}

enter image description here

egreg
  • 1,121,712