Skip to content

Commit

Permalink
Fix handling of fonts and letterspacing under XeTeX and LuaTeX. Ref T…
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskgrant committed Feb 26, 2023
1 parent ede6ed1 commit 7f3ab42
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 83 deletions.
26 changes: 15 additions & 11 deletions sample-book.tex
Original file line number Diff line number Diff line change
Expand Up @@ -785,9 +785,14 @@ \section{Full-width text blocks}
\section{Typography}\label{sec:typography}

\subsection{Typefaces}\label{sec:typefaces}\index{typefaces}
If the Palatino, \textsf{Helvetica}, and \texttt{Bera Mono} typefaces are installed, this style
will use them automatically. Otherwise, we'll fall back on the Computer Modern
typefaces.
If you're using \tXeLaTeX\ or Lua\LaTeX, the class defaults to the
\TeX\ Gyre Pagella, \textsf{\TeX\ Gyre Heros}, and \texttt{\TeX\ Gyre
Cursor} typefaces---which are usually included with \TeX\ Live
distributions. In these cases, the class automatically loads the
\docpkg{fontspec} package, so you can easily select your own system
fonts. Under pdf\LaTeX, the class defaults to the Palatino, \textsf{Helvetica},
and \texttt{Bera Mono} typefaces if they're installed. Otherwise,
we'll fall back on the Computer Modern typefaces.

\subsection{Letterspacing}\label{sec:letterspacing}
This document class includes two new commands and some improvements on
Expand Down Expand Up @@ -847,16 +852,15 @@ \section{Document Class Options}\label{sec:options}
also cause the graphics to be replaced by outlines.

The \docclsoptdef{nofonts} option prevents the \TL classes from
automatically loading the Palatino and Helvetica typefaces. You should use
this option if you wish to load your own fonts. If you're using \tXeLaTeX, this
option is implied (i.e., the Palatino and Helvetica fonts aren't loaded if you
use \tXeLaTeX).
automatically loading the Palatino and Helvetica typefaces if you're using
pdf\LaTeX. You should use this option if you wish to load your own fonts
in pdf\LaTeX. If you're using \tXeLaTeX\ or Lua\LaTeX, the default fonts
will be loaded anyway but you can easily reset them using \docpkg{fontspec}.

The \docclsoptdef{nols} option inhibits the letterspacing code. The \TL\
classes try to load the appropriate letterspacing package (either pdf\TeX's
\docpkg{letterspace} package or the \docpkg{soul} package). If you're using
\tXeLaTeX\ with \docpkg{fontenc}, however, you should configure your own
letterspacing.
classes try to load the appropriate letterspacing package (either
\docpkg{letterspace} or the \docpkg{soul} under pdf\TeX, or \docpkg{fontspec}
under \tXeLaTeX\ or Lua\LaTeX).

The \docclsoptdef{notitlepage} option causes \doccmd{maketitle} to generate a title
block instead of a title page. The \doccls{book} class defaults to a title
Expand Down
11 changes: 8 additions & 3 deletions sample-handout.tex
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,14 @@ \section{Full-width text blocks}
\section{Typography}\label{sec:typography}

\subsection{Typefaces}\label{sec:typefaces}
If the Palatino, \textsf{Helvetica}, and \texttt{Bera Mono} typefaces are installed, this style
will use them automatically. Otherwise, we'll fall back on the Computer Modern
typefaces.
If you're using Xe\LaTeX\ or Lua\LaTeX, the class defaults to the
\TeX\ Gyre Pagella, \textsf{\TeX\ Gyre Heros}, and \texttt{\TeX\ Gyre
Cursor} typefaces---which are usually included with \TeX\ Live
distributions. In these cases, the class automatically loads the
\texttt{fontspec} package, so you can easily select your own system
fonts. Under pdf\LaTeX, the class defaults to the Palatino, \textsf{Helvetica},
and \texttt{Bera Mono} typefaces if they're installed. Otherwise,
we'll fall back on the Computer Modern typefaces.

\subsection{Letterspacing}\label{sec:letterspacing}
This document class includes two new commands and some improvements on
Expand Down
141 changes: 72 additions & 69 deletions tufte-common.def
Original file line number Diff line number Diff line change
Expand Up @@ -438,18 +438,35 @@
\setboolean{@tufte@luatex}{false}
}

% xltxtra loads xunicode and fontspec; must be loaded before bidi
\ifthenelse{\boolean{@tufte@xetex}}{%
\RequirePackage{xltxtra}%
}{}

% Set LuaTeX fonts
\ifthenelse{\boolean{@tufte@luatex}}{%
\RequirePackage{fontspec}
% Set XeTex/LuaTeX fonts
\ifthenelse{\boolean{@tufte@xetex} \OR \boolean{@tufte@luatex}}{%
% Use fontspec version >= 2.4
\RequirePackage{fontspec}[2015/03/14]
\RequirePackage[osf,sc]{mathpazo}
\setmainfont[Renderer=Basic, Numbers=OldStyle, Scale = 1.0]{TeX Gyre Pagella}
\setsansfont[Renderer=Basic, Scale=0.90]{TeX Gyre Heros}
\setmonofont[Renderer=Basic]{TeX Gyre Cursor}
\setmainfont{texgyrepagella}[
Extension = .otf,
UprightFont = *-regular,
BoldFont = *-bold,
ItalicFont = *-italic,
BoldItalicFont = *-bolditalic,
Numbers = OldStyle
]
\setsansfont{texgyreheros}[
Extension = .otf,
UprightFont = *-regular,
BoldFont = *-bold,
ItalicFont = *-italic,
BoldItalicFont = *-bolditalic
]
\setmonofont{texgyrecursor}[
Extension = .otf,
UprightFont = *-regular,
BoldFont = *-bold,
ItalicFont = *-italic,
BoldItalicFont = *-bolditalic,
Scale = 0.95,
Ligatures = Rare
]
}{}

%%
Expand Down Expand Up @@ -842,9 +859,9 @@
%%
% Improved letterspacing of small caps and all-caps text.
%
% First, try to use the `microtype' package, if it's available.
% Failing that, try to use the `soul' package, if it's available.
% Failing that, well, I give up.
% If using XeTeX or LuaTeX, use the `fontspec' package; if using
% pdfTeX: first, try to use the `microtype'/`letterspacing' package,
% then try to use the `soul' package, then give up.
\DeclareTextFontCommand{\textsmallcaps}{\scshape}

% Provides \MakeTextUppercase and \MakeTextLowercase
Expand All @@ -868,7 +885,7 @@

% If we're using pdfLaTeX v1.40+, use the letterspace package.
% If we're using pdfLaTex < v1.40, use the soul package.
% If we're using XeLaTeX, use XeLaTeX letterspacing options.
% If we're using XeLaTeX or LuaLaTeX, use fontspec.
% Otherwise fall back on the soul package.
\ifthenelse{\boolean{@tufte@pdf}}{%
\@tufte@debug@info@noline{ifpdf = true}
Expand All @@ -882,6 +899,12 @@
\@tufte@debug@info@noline{ifxetex = false}
}

\ifthenelse{\boolean{@tufte@luatex}}{%
\@tufte@debug@info@noline{ifluatex = true}
}{%
\@tufte@debug@info@noline{ifluatex = false}
}

% Check pdfLaTeX version
\def\@tufte@pdftexversion{0}
\ifx\normalpdftexversion\@undefined \else
Expand All @@ -898,14 +921,19 @@
\fi
\fi

\newboolean{@tufte@letterspace@pkg@prereqs}
\setboolean{@tufte@letterspace@pkg@prereqs}{true}
\ifnum\@tufte@pdftexversion<6
\setboolean{@tufte@letterspace@pkg@prereqs}{false}
\fi

% Check pdfTex version >= 1.40
\newboolean{@tufte@letterspace@pdf@prereqs}
\setboolean{@tufte@letterspace@pdf@prereqs}{false}
\ifthenelse{\boolean{@tufte@pdf}}{%
\ifthenelse{\@tufte@pdftexversion < 6}{}{%
\setboolean{@tufte@letterspace@pdf@prereqs}{true}
}
}{}

\newcommand{\@tufte@letterspacing@soul}{%
\@tufte@debug@info@noline{%
Old version of pdfTeX detected. Using `soul' package
}%
\RequirePackage{soul}%
\sodef\allcapsspacing{}{0.15em}{0.65em}{0.6em}%
\sodef\smallcapsspacing{}{0.075em}{0.5em}{0.6em}%
Expand Down Expand Up @@ -945,63 +973,38 @@
}

\ifthenelse{\boolean{@tufte@letterspace}}{%
\ifthenelse{%
\boolean{@tufte@pdf}\AND
\boolean{@tufte@letterspace@pkg@prereqs}\AND
\NOT\boolean{@tufte@xetex}}{%
\ifthenelse{\boolean{@tufte@letterspace@pdf@prereqs}}{%
% load letterspace pkg
\IfFileExists{letterspace.sty}{%
\@tufte@letterspacing@letterspace
}{}%
}{}%
% load soul pkg
\@ifpackageloaded{letterspace}{}{%
\IfFileExists{soul.sty}{%
\@tufte@letterspacing@soul
}{%
% soul not installed... giving up.
\@tufte@warning@noline{Couldn't locate `soul' package}%
\ifthenelse{\boolean{@tufte@xetex} \OR \boolean{@tufte@luatex}}{%
\@tufte@debug@info@noline{%
Using fontspec for letter spacing in XeTeX or LuaTeX
}%
\renewcommand{\allcaps}[1]{%
{\addfontfeatures{LetterSpace=15.0} \MakeTextUppercase{#1}}%
}%
\renewcommand{\textsc}[1]{%
{\addfontfeatures{LetterSpace=8.0} {\scshape #1}}%
}
\renewcommand{\smallcaps}[1]{%
\textsc{\MakeTextLowercase{#1}}%
}%
}{%
% load soul pkg
\@ifpackageloaded{letterspace}{}{%
\IfFileExists{soul.sty}{%
\@tufte@letterspacing@soul
}{%
% soul not installed... giving up.
\@tufte@warning@noline{Couldn't locate `soul' package}%
}%
}%
}%
}{}

%\ifthenelse{\boolean{@tufte@letterspace}}{%
%\ifthenelse{\boolean{pdf}}{%
%\ifthenelse{\NOT\boolean{@tufte@letterspace@pkg@prereqs}}{%
%% pdfLaTeX version is too old or not using pdfLaTeX
%\ifthenelse{\boolean{@tufte@xetex}}{%
%% TODO use xetex letterspacing
%\@tufte@debug@info@noline{XeTeX detected. Reverting to `soul' package for letterspacing}%
%\@tufte@loadsoul%
%}{%
%% use `soul' package for letterspacing
%\@tufte@debug@info@noline{Old version of pdfTeX detected. Reverting to `soul' package for letterspacing}%
%\@tufte@loadsoul%
%}
%}{%
%\IfFileExists{letterspace.sty}{%
%\@tufte@debug@info@noline{Modern version of pdfTeX detected. Using `letterspace' package}
%\RequirePackage{letterspace}
%% Set up letterspacing (using microtype package) -- requires pdfTeX v1.40+
%\renewcommand{\allcapsspacing}[1]{\textls[200]{##1}}
%\renewcommand{\smallcapsspacing}[1]{\textls[50]{##1}}
%\renewcommand{\allcaps}[1]{\textls[200]{\MakeTextUppercase{##1}}}
%\renewcommand{\smallcaps}[1]{\smallcapsspacing{\MakeTextLowercase{##1}}}
%\renewcommand{\textsc}[1]{\smallcapsspacing{\textsmallcaps{##1}}}
%}{% microtype failed, check for soul
%\@tufte@debug@info@noline{Modern version of pdfTeX detected, but `letterspace' package not installed. Reverting to `soul' package for letterspacing}
%\@tufte@loadsoul
%}%
%}%
%}{%
%\@tufte@debug@info@noline{Plain LaTeX detected. Using `soul' package for letterspacing}
%\@tufte@loadsoul
%}
%}{%
%% we're not to load letterspacing, so do nothing
%}


%%
% An environment for paragraph-style section
\providecommand\newthought[1]{%
Expand Down

0 comments on commit 7f3ab42

Please sign in to comment.