unicode is great!

This commit is contained in:
Flukx 2022-02-15 19:35:33 +01:00
parent d8c0baf1e1
commit 7dc0805261
4 changed files with 69 additions and 0 deletions

View file

@ -12,6 +12,7 @@
\textinput{whitespace\de}
\textinput{paragraph\de}
\textinput{mathmode\de}
\textinput{unicode\de}
\textinput{operatorname\de}
\textinput{references\de}
\docEnd

View file

@ -162,4 +162,9 @@ Look at the code for an example.
Since in aligned environments \lstinline|\overset| can always be used
and \lstinline|\stackrel| only for one-symbol explanations \lstinline|\overset|
together with \lstinline|aligned-overset| is to be preferred.
\subsection{Find the right command}
If you do not know what a makro is called, use the website
\url{http://detexify.kirelabs.org/classify.html}.
Also consider using unicode, see section \ref{sec:unicode}.
\docEnd

56
tex/unicode.tex Normal file
View file

@ -0,0 +1,56 @@
%! 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 𝒫_κ$!.
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

7
tex/unicode_de.tex Normal file
View file

@ -0,0 +1,7 @@
%! TEX program = lualatex
\input{.maindir/tex/header/preamble-section}
% inputs the preamble only if necessary
\docStart
\textinput{unicode}
\docEnd