Skip to content

Commit

Permalink
Don't force "modern" fonts with XeLaTeX / LuaTex
Browse files Browse the repository at this point in the history
Create a new `fontmethod` kvoption with today's defaulting rules that
allows controlling this.
  • Loading branch information
Ericson2314 committed Apr 16, 2022
1 parent 94a9bbc commit db151ad
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 18 deletions.
1 change: 1 addition & 0 deletions examples/documentation/main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
%open=any, % If twoside=true, uncomment this to force new chapters to start on any page, not only on right (odd) pages
%chapterentrydots=true, % Uncomment to output dots from the chapter name to the page number in the table of contents
numbers=noenddot, % Comment to output dots after chapter numbers; the most common values for this option are: enddot, noenddot and auto (see the KOMAScript documentation for an in-depth explanation)
fontmethod=tex, % Can also use "modern" with XeLaTeX or LuaTex; "tex" is the default for PdfLaTex, and "modern" is the default for those two.
]{kaobook}

%----------------------------------------------------------------------------------------
Expand Down
70 changes: 52 additions & 18 deletions kao.sty
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
\ProvidesPackage{kao}

%----------------------------------------------------------------------------------------
% KAO-SPECIFIC OPTIONS
% DECLARE KAO
%----------------------------------------------------------------------------------------

\DefineFamily{kao}% Define the family name
Expand All @@ -13,6 +13,7 @@
% USEFUL PACKAGES AND COMMANDS
%----------------------------------------------------------------------------------------

\RequirePackage{kvoptions} % Handle package options
\RequirePackage{etoolbox} % Easy programming to modify TeX stuff
\RequirePackage{calc} % Make calculations
\RequirePackage[usenames,dvipsnames,table]{xcolor} % Colours
Expand All @@ -33,6 +34,39 @@
\let\Ifthispageodd\ifthispageodd%
}

%----------------------------------------------------------------------------------------
% KAO-SPECIFIC OPTIONS
%----------------------------------------------------------------------------------------

% Set up the package options
\SetupKeyvalOptions{
family = kao,
prefix = kao@
}

% https://tex.stackexchange.com/questions/47576/combining-ifxetex-and-ifluatex-with-the-logical-or-operation
% Introduce a command to find out whether the compiler is XeTeX or LuaTeX
\newif\ifxetexorluatex
\ifxetex
\xetexorluatextrue
\else
\ifluatex
\xetexorluatextrue
\else
\xetexorluatexfalse
\fi
\fi

\ifxetexorluatex
\newcommand{\kao@defaultfontmethod}{modern}
\else
\newcommand{\kao@defaultfontmethod}{tex}
\fi

% Set default based on rendering engine
\DeclareStringOption[\kao@defaultfontmethod]{fontmethod}

\ProcessKeyvalOptions{kao}

%----------------------------------------------------------------------------------------
% TITLE AND AUTHOR MACROS
Expand Down Expand Up @@ -1038,20 +1072,7 @@
% ENCODING AND FONTS
%----------------------------------------------------------------------------------------
% https://tex.stackexchange.com/questions/47576/combining-ifxetex-and-ifluatex-with-the-logical-or-operation
% Introduce a command to find out whether the compiler is XeTeX or LuaTeX
\newif\ifxetexorluatex
\ifxetex
\xetexorluatextrue
\else
\ifluatex
\xetexorluatextrue
\else
\xetexorluatexfalse
\fi
\fi
\ifxetexorluatex
\newcommand{\kao@fontmethodModern}{%
\RequirePackage{amssymb} % Must be loaded before unicode-math
\RequirePackage[force]{filehook} % Fixes an error
\RequirePackage{unicode-math} % Math fonts in xetexorluatex
Expand All @@ -1068,8 +1089,9 @@
\ifluatex
\else
\RequirePackage{morewrites} % Fix some errors related to floats (not necessary with LuaLaTeX
\fi
\else
\fi%
}
\newcommand{\kao@fontmethodTex}{%
\RequirePackage[utf8]{inputenc} % utf8 encoding in the input (.tex) file
\RequirePackage[T1]{fontenc} % utf8 encoding in the output (.pdf) file
Expand All @@ -1079,7 +1101,19 @@
\RequirePackage[scaled=.85]{beramono} % Monospace font
\RequirePackage[scr=rsfso,cal=boondoxo]{mathalfa} % Mathcal from STIX, unslanted a bit
\RequirePackage{morewrites} % Fix some errors related to floats
\fi
}
\ifthenelse%
{\equal{modern}{\kao@fontmethod}}{\kao@fontmethodModern}%
{\ifthenelse%
{\equal{tex}{\kao@fontmethod}}{\kao@fontmethodTex}%
{
\PackageError{kao}{%
Invalid fontmethod choice \kao@fontmethod.%
}{%
Should be one of "modern" or "tex"%
}
}}
% When using the Palatino (newpxtext) font, it is better to use a
% slightly larger stretch.
Expand Down

0 comments on commit db151ad

Please sign in to comment.