Menu

HowTo_Template_LuaLaTeX_XeLaTeX

How to make a minimal template with KOMA-Script for use with LuaLaTeX or XeLaTeX

XeLaTeX and LuaLaTeX are parallel developments alongside PDFLaTeX. One of their advantages is that you can access system fonts. However, some extensions of PDFTeX do not work with XeLaTeX or LuaLaTeX or work differently. In addition, XeLaTeX and LuaTeX also support native UTF-8 input. Especially if certain fonts are required, LuaLaTeX and XeLaTeX can show their advantages. Furthermore, LuaLaTeX is particularly recommended for memory-intensive documents, as for instance may arise very quickly with TikZ or pgfplots. In contrast to XeLaTeX and PDFLaTeX, LuaLaTeX does not work with fixed-size memory arrays, but can allocate memory at runtime. It also supports more than 16 files open for reading or writing at the same time. This is a good argument for the general use of LuaLaTeX.

Just as with the template for PDFLaTeX, with XeLaTeX and LuaLateX you should save the document in UTF-8 encoding. This is also the default for all modern LaTeX editors like TeXworks, TeXmaker, TeXstudio or TeXnicCenter from version 2.0 (but not for version 1.0!). If necessary, see the manual of the editor you are using. However, while it would not be a mistake to use the inputenc package with PDFLaTeX, even with a different encoding option than utf8 if necessary, this package should be avoided when using LuaLaTeX and XeLaTeX. The same applies to packages based on it such as selinput or inputenx. The \usepackage[T1]{fontenc} statement is also not applicable to LuaLaTeX and XeLaTeX. Instead, you use the package fontspec and get the OpenType version of Latin Modern as a default.

For language switching, babel can also be used for most languages in XeLaTeX and LuaLaTeX. Since earlier versions of babel automatically switched font encoding to support certain languages, the package polyglossia was also developed for XeLaTeX. Therefore, its use is often recommended for XeLaTeX. The example thus changes to:

\documentclass{scrartcl}% see <https://komascript.de>
% !TeX program = xelatex
% !TeX encoding = UTF-8 Unicode
\documentclass{scrartcl}% see <https://komascript.de>
\usepackage{fontspec}% font selection with native XeTeX features;
                     % new default: Latin Modern
\usepackage{polyglossia}% language selection
\setdefaultlanguage{UKengliah}% document language: British English
\begin{document}
% ----------------------------------------------------------------------------
% title
\titlehead{head above title with chair etc.}% optional.
\subject{type of document}% optional
\title{title of the document}% mandatory
\subtitle{subtitle}% optional
\author{this is me}% mandatory
\date{e.g. the deadline}% reasonable
\publishers{place for supervisor or similar}% optional
\maketitle% uses the previously given information to design a title
% ----------------------------------------------------------------------------
% table of contents:
\tableofcontents
% ----------------------------------------------------------------------------
% Outline and text:
\section{motivation}
\label{sec:motivation}
This section should address the task. It can also cover basics. However,
it may be useful to use a separate section for the basics. 
The text may also contain many special characters such as the German
umlauts: äöü, or a µ or ç.
\section{implementation}
\label{sec:implementation}
Here you tell now what you have done.
\section{conclusion}
\label{sec:conclusion}
This is the conclusion and, if necessary, the outlook on further things
that could be done.
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-engine: xetex
%%% TeX-PDF-mode: t
%%% coding: utf-8
%%% TeX-master: t
%%% End:  

The somewhat strange comments at the beginning of the example serve to set the LaTeX editors TeXShop, TeXStudio and TeXworks to use xelatex and UTF-8 encoding right away. The comments at the end do the same (and a little more) for emacs + AucTeX. More details can be found in the respective manuals.

The use of polyglossia also has disadvantages. For example, for German this package knows the dialects german, austrian and swiss and can also load hyphenation patterns for different spellings, but it assumes that language-dependent terms within a language are always the same. So if a class or package defines language-dependent terms differently according to old and new German spelling, polyglossia always uses those of the old spelling. Therefore, I myself prefer the very actively maintained babel even with XeLaTeX and even more so with LuaLaTeX:

\documentclass[UKenglish]{scrartcl}% see <https://komascript.de>
% !TeX program = lualatex
% !TeX encoding = UTF-8 Unicode
\documentclass{scrartcl}% see <https://komascript.de>
\usepackage{fontspec}% font selection with native XeTeX features;
                % new default: Latin Modern
\usepackage{babel}% language selection: British English has already been
                % selected globally via option UKenglish.
\begin{document}
% ----------------------------------------------------------------------------
% title
\titlehead{head above title with chair etc.}% optional.
\subject{type of document}% optional
\title{title of the document}% mandatory
\subtitle{subtitle}% optional
\author{this is me}% mandatory
\date{e.g. the deadline}% reasonable
\publishers{place for supervisor or similar}% optional
\maketitle% uses the previously given information to design a title
% ----------------------------------------------------------------------------
% table of contents:
\tableofcontents
% ----------------------------------------------------------------------------
% Outline and text:
\section{motivation}
\label{sec:motivation}
This section should address the task. It can also cover basics. However,
it may be useful to use a separate section for the basics. 
The text may also contain many special characters such as the German
umlauts: äöü, or a µ or ç.
\section{implementation}
\label{sec:implementation}
Here you tell now what you have done.
\section{conclusion}
\label{sec:conclusion}
This is the conclusion and, if necessary, the outlook on further things
that could be done.
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-engine: luatex
%%% TeX-PDF-mode: t
%%% coding: utf-8
%%% TeX-master: t
%%% End:  

For a change, the comments for selecting a TeX engine for LuaLaTeX have been adapted here.


Related

Wiki (English): HowTo_Template
Wiki (English): HowTo_Template_PDFLaTeX

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.