59 lines
3.3 KiB
TeX
59 lines
3.3 KiB
TeX
%! TEX program = lualatex
|
||
|
||
\input{.maindir/tex/header/preamble-section}
|
||
% inputs the preamble only if necessary
|
||
\docStart
|
||
\section{Lua\texorpdfstring{\LaTeX}{LaTeX} and Unicode}\label{sec:unicode}
|
||
Plain text files like \TeX-source files are written using an encoding that tells the computer how to translate bytes into letters.
|
||
There are hundreds of encodings developed over the years but nowadays there is only one that makes any sense to use: UTF-8, one form of unicode.
|
||
In order to use UTF-8 in \LaTeX-documents compiled with \lstinline!pdflatex! one needs the line \lstinline!\usepackage[utf8]{inputenc}!.
|
||
In the more modern compilers Lua\LaTeX{} (and Xe\LaTeX{}%
|
||
\footnote{I am not familiar with Xe\LaTeX, so I will only refer to Lua\LaTeX.}
|
||
UTF-8 is the standard (and only possible (?)) encoding.
|
||
Lua\LaTeX{} supports UTF-8 far better than pdf\LaTeX{}.
|
||
That means that you can use any UTF-8 symbol in the code and it is used.
|
||
With one limitation: the font you use must include it.
|
||
The font is set with the package \lstinline!fontspec!.
|
||
|
||
I use in my template the following fonts which have a quite wide support of the unicode ranges I have used to far:
|
||
\begin{lstlisting}
|
||
\usePackage{fontspec}
|
||
% Standard fonts that work, can be overwritten
|
||
\setmainfont{DejaVu Serif}
|
||
\setsansfont{DejaVu Sans}
|
||
\setmonofont{DejaVu Sans Mono}
|
||
\end{lstlisting}
|
||
|
||
For setting the mathematics font you can use
|
||
\begin{lstlisting}
|
||
\usePackage{unicode-math}
|
||
\setmathfont{TeX Gyre DejaVu Math}
|
||
\end{lstlisting}
|
||
but I could not see any visual difference when adding those lines.
|
||
|
||
The important question now is: how to input the UTF-8 symbols.
|
||
I use the Neo2 keyboard layout%
|
||
\footnote{\url{https://neo-layout.org}} which already includes a lot
|
||
of symbols like greek letters and mathematical logic operators.
|
||
If you want to keep qwertz, there is also qwertz-neo which combines
|
||
qwertz with the other symbols from Neo2.
|
||
|
||
Additionally there is a feature in Linux called the \enquote{Compose} key
|
||
which allows you to type a sequence of keys to get an Unicode character.
|
||
You can configure it with a file \lstinline!~/.XCompose!.
|
||
For Windows there are programs that supply similar functionality.
|
||
For details search the web for \enquote{Compose key}, \enquote{.XCompose mathematical symbols}, etc.
|
||
This allows to have \LaTeX-code that has mathematical formulas that are closer to the pdf output and shorter:
|
||
\lstinline!$\sin α + \sin β + Σ_{ι=1}^3 λ_ι = Π_{κ = 1}^5 𝒫_κ$!.
|
||
(I am sorry for the horrible output, apparently using greek letters in code listings is a bad idea. Look at the source code!)
|
||
|
||
Note that sometimes you might want to give unicode characters a different meaning than they originally have. In my case \lstinline!Σ! is the sum symbol, not the greek capital letter Sigma. Hence I have in my template:
|
||
\begin{lstlisting}
|
||
\RequirePackage{newunicodechar} % makes this remapping possible
|
||
\newunicodechar{Σ}{\ensuremath{\sum}} % not capital sigma which is smaller!
|
||
\end{lstlisting}
|
||
It is debatable though if that is a good idea since there is also a sum symbol in UTF-8: \href{https://unicode-table.com/en/2211/}{∑}.
|
||
|
||
You can find unicode characters on the website \url{https://unicode-table.com}.
|
||
If you know what you want, but do not know how it is called, the website \url{http://shapecatcher.com/} might be helpful.
|
||
\docEnd
|