Perhaps a question for David ?
I thought it would be interesting to be able to use unicode Greek characters directly to name nodes (points) with tkz-elements. I have no problem with the naming and all the macros seem to work correctly, but the problem arises with the tkzLabelPoint macro. As a first step, I've decided to create a new macro dedicated to Greek characters: \tkzLabelGPoint and I have a solution to automate this, but with the help of the luacode environment. I'd like to be able to use the directlua macro ... and I can't.
I hesitated about which question to ask. It's possible I've been wrong all along. Is it easier not to use lua?
\documentclass{article}
\usepackage[mini]{tkz-euclide}
\usepackage{tkz-elements}
\usepackage{luacode}
\begin{luacode}
-- Unicode Greek letter mapping to LaTeX
local greek_to_latex = {
["α"] = "\\alpha",
["β"] = "\\beta",
["γ"] = "\\gamma",
["δ"] = "\\delta",
["ε"] = "\\epsilon",
["ζ"] = "\\zeta",
["η"] = "\\eta",
["θ"] = "\\theta",
["ι"] = "\\iota",
["κ"] = "\\kappa",
["λ"] = "\\lambda",
["μ"] = "\\mu",
["ν"] = "\\nu",
["ξ"] = "\\xi",
["ο"] = "o",
["π"] = "\\pi",
["ρ"] = "\\rho",
["σ"] = "\\sigma",
["τ"] = "\\tau",
["υ"] = "\\upsilon",
["φ"] = "\\phi",
["χ"] = "\\chi",
["ψ"] = "\\psi",
["ω"] = "\\omega",
-- Majuscules
["Α"] = "A",
["Β"] = "B",
["Γ"] = "\\Gamma",
["Δ"] = "\\Delta",
["Ε"] = "E",
["Ζ"] = "Z",
["Η"] = "H",
["Θ"] = "\\Theta",
["Ι"] = "I",
["Κ"] = "K",
["Λ"] = "\\Lambda",
["Μ"] = "M",
["Ν"] = "N",
["Ξ"] = "\\Xi",
["Ο"] = "O",
["Π"] = "\\Pi",
["Ρ"] = "P",
["Σ"] = "\\Sigma",
["Τ"] = "T",
["Υ"] = "\\Upsilon",
["Φ"] = "\\Phi",
["Χ"] = "X",
["Ψ"] = "\\Psi",
["Ω"] = "\\Omega"
}
function convert_greek_to_latex(char)
local latex_char = greek_to_latex[char]
tex.sprint("$" .. latex_char .. "$")
end
\end{luacode}
\newcommand{\convertGreek}[1]{%
\directlua{convert_greek_to_latex("#1")}%
}
\def\tkzLabelGPoint[#1](#2){%
\node[label style,#1] at (#2) {\convertGreek{#2}};
}%
\begin{document}
Test: \convertGreek{α}, \convertGreek{β}
\vspace{12pt}
\begin{tikzpicture}
\tkzDefPoint(1,2){α}
\tkzDefPoint(3,1){β}
\tkzDrawLine(α,β)
\tkzDrawPoints(α, β)
\tkzLabelGPoint[red,below](α)
\tkzLabelGPoint[red,below](β)
\end{tikzpicture}
\end{document}
So a direct answer to the question is
\documentclass{article}
\usepackage[mini]{tkz-euclide}
\usepackage{tkz-elements}
% stop expansion and use % not -- comments
\directlua{
%-- Unicode Greek letter mapping to LaTeX
local greek_to_latex = {
["α"] = "\string\\alpha",
["β"] = "\string\\beta",
["γ"] = "\string\\gamma",
["δ"] = "\string\\delta",
["ε"] = "\string\\epsilon",
["ζ"] = "\string\\zeta",
["η"] = "\string\\eta",
["θ"] = "\string\\theta",
["ι"] = "\string\\iota",
["κ"] = "\string\\kappa",
["λ"] = "\string\\lambda",
["μ"] = "\string\\mu",
["ν"] = "\string\\nu",
["ξ"] = "\string\\xi",
["ο"] = "o",
["π"] = "\string\\pi",
["ρ"] = "\string\\rho",
["σ"] = "\string\\sigma",
["τ"] = "\string\\tau",
["υ"] = "\string\\upsilon",
["φ"] = "\string\\phi",
["χ"] = "\string\\chi",
["ψ"] = "\string\\psi",
["ω"] = "\string\\omega",
%-- Majuscules
["Α"] = "A",
["Β"] = "B",
["Γ"] = "\string\\Gamma",
["Δ"] = "\string\\Delta",
["Ε"] = "E",
["Ζ"] = "Z",
["Η"] = "H",
["Θ"] = "\string\\Theta",
["Ι"] = "I",
["Κ"] = "K",
["Λ"] = "\string\\Lambda",
["Μ"] = "M",
["Ν"] = "N",
["Ξ"] = "\string\\Xi",
["Ο"] = "O",
["Π"] = "\string\\Pi",
["Ρ"] = "P",
["Σ"] = "\string\\Sigma",
["Τ"] = "T",
["Υ"] = "\string\\Upsilon",
["Φ"] = "\string\\Phi",
["Χ"] = "X",
["Ψ"] = "\string\\Psi",
["Ω"] = "\string\\Omega"
}
function convert_greek_to_latex(char)
local latex_char = greek_to_latex[char]
tex.sprint("$" .. latex_char .. "$")
end
}
\newcommand{\convertGreek}[1]{%
\directlua{convert_greek_to_latex("#1")}%
}
\def\tkzLabelGPoint[#1](#2){%
\node[label style,#1] at (#2) {\convertGreek{#2}};
}%
\begin{document}
Test: \convertGreek{α}, \convertGreek{β}
\vspace{12pt}
\begin{tikzpicture}
\tkzDefPoint(1,2){α}
\tkzDefPoint(3,1){β}
\tkzDrawLine(α,β)
\tkzDrawPoints(α, β)
\tkzLabelGPoint[red,below](α)
\tkzLabelGPoint[red,below](β)
\end{tikzpicture}
\end{document}


-- Unicode Greek letter mapping to LaTeXdo you really need to do that at all? it's probably simpler just to use the Greek in latex for which many solutions already exist, for exampleunicode-mathfor luatex or any of the Greek packages.