4

I'd like to have some code to set, document wide, a specific character variant for the letter "v" only if it is the first in the word. The solution in the MWE is not a solution because I have a document of several hundreds of pages. Any suggestion? Thanks.

\documentclass[a4paper,14pt,openright,twoside]{memoir}
\usepackage[T1]{fontenc}
\usepackage[scale=1,osf,nf,lf]{ebgaramond}
\usepackage{fontspec}
\usepackage{microtype}
\usepackage{csquotes}
\usepackage{realscripts}

\begin{document}

Normal set:
{\fontshape{it}
    \addfontfeature{RawFeature=+hlig}
        \addfontfeature{CharacterVariant=5:2}
            \addfontfeature{RawFeature=+liga}
                \addfontfeature{RawFeature=+dlig}
                    \addfontfeature{RawFeature=+swsh}
                        \addfontfeature{Numbers=OldStyle}
                            \selectfont 

Ha visto un valvassore vivere come un valvassino invidioso che gridava evviva!}         

Nice to have:
{\fontshape{it}
    \addfontfeature{RawFeature=+hlig}
        \addfontfeature{CharacterVariant=5:1}
            \addfontfeature{RawFeature=+liga}
                \addfontfeature{RawFeature=+dlig}
                    \addfontfeature{RawFeature=+swsh}
                        \addfontfeature{Numbers=OldStyle}
                            \selectfont                 

Ha {\addfontfeature{CharacterVariant=5:2}v}isto un {\addfontfeature{CharacterVariant=5:2}v}alvassore {\addfontfeature{CharacterVariant=5:2}v}ivere come un {\addfontfeature{CharacterVariant=5:2}v}alvassino invidioso che gridava evviva!} 
\end{document}
3

You may use a character class:

\documentclass[a4paper,14pt,openright,twoside]{memoir}
\usepackage{fontspec}

\setmainfont{EB Garamond}[
  Numbers=Lining,
  ItalicFeatures={
    RawFeature=+hlig,
    RawFeature=+liga,
    RawFeature=+dlig,
    RawFeature=+swsh,
    Numbers=OldStyle,
  },
]
\newfontfamily\varv{EB Garamond}[
  Numbers=Lining,
  ItalicFeatures={
    RawFeature=+hlig,
    RawFeature=+liga,
    RawFeature=+dlig,
    RawFeature=+swsh,
    Numbers=OldStyle,
    CharacterVariant=5:2,
  },
]

\XeTeXinterchartokenstate=1
\newXeTeXintercharclass\vclass
\XeTeXcharclass`v=\vclass
\XeTeXinterchartoks 255 \vclass = {\openswashv}

\makeatletter
\newcommand\openswashv{%
  % by preceding the v with U+200C it's not at the boundary any more
  \ifnum\strcmp{\f@shape}{it}=\z@
    \begingroup\varv^^^^200cv\endgroup
    \nobreak\hspace{0pt}% allow hyphenation in the rest of the word
    \expandafter\@gobble
  \fi
}
\makeatother


\begin{document}

Normal font:
  Ha visto un valvassore vivere come un valvassino invidioso che gridava evviva!

Italic font: {\itshape
  Ha visto un valvassore vivere come un valvassino invidioso che gridava evviva!
}

\end{document}

This allows hyphenation on the rest of the word (but could give some wrong hyphenation point with languages different from Italian). I checked and EB Garamond doesn't define any kerning pair between v and another letter.

You should ask the font developer for a stylistic set.

enter image description here

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.