# Converting Latin characters to Greek

Is there a package or simple method to generate Greek characters from their Roman counterparts?

Like, for instance:

\greek{a} would generate \alpha

\greek{b} would generate \beta

\greek{B} would generate \Beta,

And so on... I'm aware that such correspondence would not be a one-one map, but could be close enough.

My need for this is related to a set of commands that I have in my Ph.D. document to ensure a compatible (always equal) use of determined symbols in some categories. For instance, I have some commands such as:

\newcommand{\setname}[1]{\ensuremath{\uppercase{#1}}}
\newcommand{\matrixname}[1]{\ensuremath{\mathbf{\uppercase{#1}}}}
\newcommand{\vectorname}[1]{\ensuremath{\vec{\lowercase{#1}}}}
\newcommand{\scalarname}[1]{\ensuremath{\lowercase{#1}}}


Thus, if I ever need to define a set S, I can use \setname{S} and the set is ensured to be an uppercase letter with math formatting (italic like). If for some reason, later on, I need to change the formating of sets to use lowercase, I will just need to change the \setname command's definition.

Now I need a new command for a specific non-empty kind of set: an alphabet. I want to use uppercase greek characters to define the name of an alphabet. So I would like to create a command such as:

\newcommand{\alphabetname}[1]{\ensuremath{\greek{\uppercase{#1}}}}


Then for defining a Σ alphabet I could write:

\alphabetname{s} and get Σ.

• Is it for maths formulæ? – Bernard Aug 11 '19 at 20:41
• Yes, it is. I will probably use within a command that will have a ensuremath, just to be safe. – Isma Aug 11 '19 at 20:44
• I think it's more a problem of the editor. WinEdt has a package which allows for typing the letter α, say, from the letter a + a prefix, yet saves as \alpha. – Bernard Aug 11 '19 at 20:57
• I'll try to improve the question to be more clear in my needs :) – Isma Aug 11 '19 at 21:20
• You don't want to use \ensuremath throughout. Maybe using \setname{S} in text mode can be deemed easier, but it's wrong from a semantic point of view. You don't type something like the value of x is obtained… where x should be a math letter, do you? For the same reason, The set $\setname{S}$ is interesting should be the correct input. – egreg Aug 12 '19 at 9:35

Here's the encoding that's standard in LaTeX for inputting Greek with Latin characters.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\ucgreek}{m}
{
\str_case:nn { #1 }
{
{A}{\mathrm{A}}
{B}{\mathrm{B}}
{C}{\Sigma}
{D}{\Delta}
{E}{\mathrm{E}}
{F}{\Phi}
{G}{\Gamma}
{H}{\mathrm{H}}
{I}{\mathrm{I}}
{J}{\Theta}
{K}{\mathrm{K}}
{L}{\Lambda}
{M}{\mathrm{M}}
{N}{\mathrm{N}}
{O}{\mathrm{O}}
{P}{\Pi}
{Q}{\mathrm{X}}
{R}{\mathrm{P}}
{S}{\Sigma}
{T}{\mathrm{T}}
{U}{\Upsilon}
%{V}{}
{W}{\Omega}
{X}{\Xi}
{Y}{\Psi}
{Z}{\mathrm{Z}}
}
}
\NewDocumentCommand{\lcgreek}{m}
{
\str_case:nn { #1 }
{
{a}{\alpha}
{b}{\beta}
{c}{\varsigma}
{d}{\delta}
{e}{\varepsilon}
{f}{\varphi}
{g}{\gamma}
{h}{\eta}
{i}{\iota}
{j}{\vartheta}
{k}{\kappa}
{l}{\lambda}
{m}{\mu}
{n}{\nu}
{o}{o}
{p}{\pi}
{q}{\chi}
{r}{\rho}
{s}{\sigma}
{t}{\tau}
{u}{\upsilon}
%{v}{}
{w}{\omega}
{x}{\xi}
{y}{\psi}
{z}{\zeta}
}
}
\ExplSyntaxOff

\newcommand{\alphabetname}[1]{\uppercase{\ucgreek{#1}}}

\begin{document}

The alphabet $\alphabetname{S}$ is important.

\end{document}


One way is just to choose the character you want based on the code of the corresponding Roman character like the following (the code is incomplete, only first four letters are implemented, also, you might want to use another correspondence, \gamma for g for example):

\documentclass{article}

\newcounter{tmpgreek}
\newcommand{\greek}[1]{%
\setcounter{tmpgreek}{#1}
\ifcase\value{tmpgreek}
\alpha\or\beta\or\gamma\or\delta
\fi
\setcounter{tmpgreek}{#1}
\ifcase\value{tmpgreek}
\mathrm A\or \mathrm B\or\Gamma\or\Delta
\fi
}

\begin{document}
$\greek{a}$
$\greek{b}$
$\greek{c}$
$\greek{d}$

$\greek{A}$
$\greek{B}$
$\greek{C}$
$\greek{D}$
\end{document}