Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't force "modern" fonts with XeLaTeX / LuaTex #229

Merged
merged 3 commits into from
Sep 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Don't force "modern" fonts with XeLaTeX / LuaTex
Create a new `fontmethod` kvoption with today's defaulting rules that
allows controlling this.
  • Loading branch information
Ericson2314 committed Apr 16, 2022
commit db151ad7fd262a01cd87285372ef7ee433d9d79e
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