What should I put in the preamble (preferably packages) for this to work as expected with its unicode characters?
\documentclass{article}
\usepackage{listings}
\begin{document}
$α$ α
\begin{lstlisting}
α = 1.;
\end{lstlisting}
\end{document}
Note that alpha (α) appears in three contexts: as text, as math and as code (listings).
(I can use lualatex
if it simplifies things)
For a higher challenge, in this case I introduce a second level of difficulty, by introducing a second kind of alpha (𝛼: 0x1d6fc Mathematical italic small alpha vs. α: Greek small letter alpha). To see to what degree TeX can deal with the nuance (e.g. by make 𝛼 into $\alpha$, or by making 𝑝 --0x1D45D Mathematical italic small p-- into $p$):
\documentclass[]{article}
\usepackage[]{listings}
\begin{document}
$α$ α $𝛼$ 𝛼 𝑝
\begin{lstlisting}
α = 1.
𝛼 = 2.
\end{lstlisting}
\end{document}
listings
can only handle single byte chars plus stuff that can be represented in latin1. So someone has to write a fully utf8 aware version oflistings