7

I'm trying to reproduce historical examples of typography and there's something I don't know how to obtain: poems are typed in italic, except the initial capital letters of each verse is upshape, and there is some italic correction between the initial letter of the first word of the verse, and the following letter. Besides, all capital letters inside verses are upshape too.

I feel like I should define a new font family, but trying to adapt some code found on this site results in an error (!Extra \endgroup). I'd be quite grateful to anyone who could explain how to do it.

  • 2
    No font does this and there's no defined OpenType feature for it. You probably are better served by some LuaTeX callback. – egreg Jun 12 '16 at 15:56
  • @egreg: Howevr, Khaled Hosny's answer to this question explains how to obtain capital letters only in red. Of course, that's a font feature, but I hoped it might be possible to have something comparable to the mechanism of virtual fonts. – Bernard Jun 12 '16 at 16:04
  • Yes, I forgot about character classes, but the \newfontfamily is just for efficiency. Why not adding your attempt? – egreg Jun 12 '16 at 16:08
  • Anyway, trying this code and just replacingthe font name with my actual font doesn't work. As this answer is almost 5 years old, maybe some details have changed since then. – Bernard Jun 12 '16 at 16:14
  • 1
    Note that from TL 2016, XeTeX version 0.99996, the upper limit of character classes is 4095, not 255 any more. If I change 255 with 4095, the code in the answer works. – egreg Jun 12 '16 at 16:21
5

Adapting the code by Andrey Vihrov to your needs and to the changed number of character classes, I can offer

\documentclass{article}

\usepackage{fontspec}

\XeTeXinterchartokenstate=1
\newXeTeXintercharclass \uppercaseclass

\makeatletter
% Assign the new class to all Latin capital letters
\@tempcnta=`\A
\loop\unless\ifnum\@tempcnta>`\Z
  \XeTeXcharclass \@tempcnta \uppercaseclass
  \advance \@tempcnta by 1
\repeat
\makeatother

% Setup font change
\XeTeXinterchartoks 0 \uppercaseclass    = {\begingroup\upshape}
\XeTeXinterchartoks \uppercaseclass 0    = {\endgroup}
\XeTeXinterchartoks 4095 \uppercaseclass = {\begingroup\upshape}
\XeTeXinterchartoks \uppercaseclass 4095 = {\endgroup}

\begin{document}

\itshape
Once Upon a Time, there was a Beautiful Princess\ldots

\end{document}

enter image description here

  • There's a second pair \makeatletter … \makeatother that's messed up. But the main point is I have a! Extra \endgroup. <XeTeXinterchartoks> \endgroup in the .log file. This error message disappears if I replace \e@alloc@intercharclass@top with 4095. I suppose you want to preserve the possibility of having other values for the upper bound? – Bernard Jun 12 '16 at 18:46
  • @Bernard That was the idea, but I rolled back to the explicit number. There has been some misunderstanding, so \e@alloc@intercharclass@top didn't find its way into the current kernel. – egreg Jun 12 '16 at 19:14
  • Testing and comparing with a historical document, I changed the two {\endgroup} with \kern 0.06em\endgroup} (a standard italic correction was really too much). B.t.w., a pair of \makeatletter … \makeatother is missing. – Bernard Jun 12 '16 at 19:42
14

With luatex/luaotfload you can (in texlive 2016 and up-to-date miktex) build a combo font. Imho there is no high-level interface yet, but beside this it works:

\documentclass[]{article}
\usepackage{fontspec}

\font \one = file:EBGaramond12-Italic.otf
\font \two = file:EBGaramond12-Regular.otf

\font \onetwo = "combo: 1 -> \fontid \one ;
                        2 -> \fontid \two , 0x41-0x5A;"


\begin{document}
\onetwo Some Text with Capital XYabcXY

\end{document}

enter image description here

  • Thanks for your answer! I have a couple of problems with your solution: while your code compiles fine, it requires the open type files be installed within a TeX tree. I'd like to use system fonts without having to make copies in the fonts directory. The other problem (secondary in my context) is that any font change (adding \textbf, say) results in going back to Computer Modern. – Bernard Jun 12 '16 at 17:27
  • I have no problem to use a system font like e.g. arial for one of the fonts (with \font \one = file:arial.ttf). And yes: these are lowlevel commands. To be able to use nfss and size commands you will have to setup suitable font definitions, see e.g. eu2lmr.fd – Ulrike Fischer Jun 12 '16 at 17:39
  • Thanks for the explanations. I'll have quite some work to do for the next few days… – Bernard Jun 12 '16 at 17:48
0

The other option is to alter the .otf or .ttf file and then incorporate the font family as:

\newfontfamily\myFont{my-awesome-font}[
Path            =   ./Fonts/awesome-font/,
Extension       =   .ttf,
UprightFont     =   *-Regular,
BoldFont        =   *-Bold,
ItalicFont      =   *-Italic,
BoldItalicFont  =   *-BoldItalic
]  

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.