Skip to content

Commit

Permalink
Merge pull request #229 from Ericson2314/xelatex-with-tex-fonts
Browse files Browse the repository at this point in the history
Don't force "modern" fonts with XeLaTeX / LuaTex
  • Loading branch information
fmarotta authored Sep 17, 2022
2 parents 3347fc3 + db151ad commit 9f34e3e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 20 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
73 changes: 53 additions & 20 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,10 +13,11 @@
% 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
\RequirePackage{iftex} % Check wether XeTeX is being used
\RequirePackage{iftex} % Check whether XeTeX is being used
\RequirePackage{xifthen} % Easy conditionals
\RequirePackage{options} % Manage class options
\RequirePackage{xparse} % Parse arguments for macros
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 @@ -1039,20 +1073,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 @@ -1069,8 +1090,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 @@ -1080,7 +1102,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 Expand Up @@ -1359,7 +1393,6 @@
% Special gliphs
\RequirePackage{ccicons} % Creative Commons icons
\RequirePackage{metalogo} % XeTeX logo
% Index, glossary and nomenclature
\RequirePackage{imakeidx}
Expand Down

0 comments on commit 9f34e3e

Please sign in to comment.