\documentclass[a4paper]{article}
\usepackage{cmap} % fix search and cut-and-paste in Acrobat Reader
\usepackage[LGR,T1]{fontenc}
\usepackage[utf8]{inputenc}
%\usepackage{textalpha}
\usepackage{textcomp}
\usepackage[colorlinks]{hyperref}
\usepackage{bookmark}
\usepackage{parskip}
\usepackage{booktabs}

\usepackage{lmodern}
% \usepackage{kerkis}
% \usepackage{gfsdidot}

% The document should work with and without babel:
\usepackage[greek,english]{babel}
\languageattribute{greek}{polutoniko}

% from textalpha.sty:
\DeclareTextCommandDefault{\ensuregreek}[1]{{\fontencoding{LGR}\selectfont #1}}

\begin{document}

\title{Greek Unicode with \emph{inputenc}}
\author{Günter Milde}
\maketitle

\abstract{
The definitions in \texttt{lgrenc.dfu} provide UTF-8 support for Greek based
on \href{http://www.ctan.org/pkg/inputenc}{inputenc} and the LICRs (LaTeX
internal character representations) defined in \texttt{lgrenc.def} from the
\href{http://www.ctan.org/pkg/greek-fontec}{greek-fontec} package.
}


\section{Usage}

If the \emph{greek-fontenc} package is installed, the line
\begin{verbatim}
  \usepackage[utf8]{inputenc}
\end{verbatim}
in the document preamble allows the use of Greek Unicode literals in the
document body, if the current font encoding is LGR.\footnote{%
All \emph{inputenc} Unicode definitions only work for text in the correct
font encoding.}
% e.g. Π produces:
% ! LaTeX Error: Command \textPi unavailable in encoding T1.
% just like Ж produces:
% ! LaTeX Error: Command \CYRZH unavailable in encoding T1.
%
(The font encoding is automatically set to LGR by babel for the
\emph{greek} language.)

In combination with the \emph{textalpha} package from
\href{http://www.ctan.org/pkg/lgrx}{lgrx}, Greek Unicode literals can be
used in text with any font encoding just like the symbols provided by
package ``textcomp'' (i.e. with some limitations to kerning,
MakeUppercase/MakeLowercase and multiple accents, described in
\texttt{textalpha-test} from the ``lgrx'' package):
%
\begin{verbatim}
  \usepackage[utf8]{inputenc}
  \usepackage{textalpha}
\end{verbatim}

In combination with the \emph{alphabeta} package (also from
\href{http://www.ctan.org/pkg/lgrx}{lgrx}),
Greek Unicode literals can also be used in math mode:
%
\begin{verbatim}
  \usepackage[utf8]{inputenc}
  \usepackage{alphabeta}
\end{verbatim}


\section{Supported Characters}

LGR is no ``standard font encoding''. Latin characters are mapped to Greek
if LGR is the active font encoding. This means you need an explicit
font-encoding switch for Latin words and abbreviations in Greek text.

Unicode definitions exist for all non-ASCII characters that can be rendered
with an LGR-encoded font.

\pagebreak

\subsection{Greek and Coptic}

legend: * glyph missing in LGR, [space] Unicode point not defined

\selectlanguage{greek}
\begin{tabular}{rrrrrrrrrrrrrrrrr}
\toprule
    & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & A & B & \textlatin C & D & E & F\\
\midrule
\textlatin{370} & * & * & * & * & ʹ & ͵ & * & * &   &   & ͺ & * & * & * & ; &  \\
\textlatin{380} &   &   &   &   & ΄ & ΅ & Ά & · & Έ & Ή & Ί &   & Ό &   & Ύ & Ώ\\
\textlatin{390} & ΐ & Α & Β & Γ & Δ & Ε & Ζ & Η & Θ & Ι & Κ & Λ & Μ & Ν & Ξ & Ο\\
\textlatin{3A0} & Π & Ρ &   & Σ & Τ & Υ & Φ & Χ & Ψ & Ω & Ϊ & Ϋ & ά & έ & ή & ί\\
\textlatin{3B0} & ΰ & α & β & γ & δ & ε & ζ & η & θ & ι & κ & λ & μ & ν & ξ & ο\\
\textlatin{3C0} & π & ρ & ς & σ & τ & υ & φ & χ & ψ & ω & ϊ & ϋ & ό & ύ & ώ &  \\
\textlatin{3D0} & * & * & * & * & * & * & * & * & Ϙ & ϙ & Ϛ & ϛ & Ϝ & ϝ & * & ϟ\\
\textlatin{3E0} & Ϡ & ϡ & * & * & * & * & * & * & * & * & * & * & * & * & * & *\\
\textlatin{3F0} & * & * & * & * & * & * & * & * & * & * & * & * & * & * & * & *\\
\bottomrule
\end{tabular}
\selectlanguage{english}

\subsection{Greek Extended}

\selectlanguage{greek}
\begin{tabular}{rrrrrrrrrrrrrrrrr}
\toprule
      & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & A & B & \textlatin C & D & E & F\\
\midrule
\textlatin{1F00} & ἀ & ἁ & ἂ & ἃ & ἄ & ἅ & ἆ & ἇ & Ἀ & Ἁ & Ἂ & Ἃ & Ἄ & Ἅ & Ἆ & Ἇ\\
\textlatin{1F10} & ἐ & ἑ & ἒ & ἓ & ἔ & ἕ &   &   & Ἐ & Ἑ & Ἒ & Ἓ & Ἔ & Ἕ &   &  \\
\textlatin{1F20} & ἠ & ἡ & ἢ & ἣ & ἤ & ἥ & ἦ & ἧ & Ἠ & Ἡ & Ἢ & Ἣ & Ἤ & Ἥ & Ἦ & Ἧ\\
\textlatin{1F30} & ἰ & ἱ & ἲ & ἳ & ἴ & ἵ & ἶ & ἷ & Ἰ & Ἱ & Ἲ & Ἳ & Ἴ & Ἵ & Ἶ & Ἷ\\
\textlatin{1F40} & ὀ & ὁ & ὂ & ὃ & ὄ & ὅ &   &   & Ὀ & Ὁ & Ὂ & Ὃ & Ὄ & Ὅ &   &  \\
\textlatin{1F50} & ὐ & ὑ & ὒ & ὓ & ὔ & ὕ & ὖ & ὗ &   & Ὑ &   & Ὓ &   & Ὕ &   & Ὗ\\
\textlatin{1F60} & ὠ & ὡ & ὢ & ὣ & ὤ & ὥ & ὦ & ὧ & Ὠ & Ὡ & Ὢ & Ὣ & Ὤ & Ὥ & Ὦ & Ὧ\\
\textlatin{1F70} & ὰ & ά & ὲ & έ & ὴ & ή & ὶ & ί & ὸ & ό & ὺ & ύ & ὼ & ώ &   &  \\
\textlatin{1F80} & ᾀ & ᾁ & ᾂ & ᾃ & ᾄ & ᾅ & ᾆ & ᾇ & ᾈ & ᾉ & ᾊ & ᾋ & ᾌ & ᾍ & ᾎ & ᾏ\\
\textlatin{1F90} & ᾐ & ᾑ & ᾒ & ᾓ & ᾔ & ᾕ & ᾖ & ᾗ & ᾘ & ᾙ & ᾚ & ᾛ & ᾜ & ᾝ & ᾞ & ᾟ\\
\textlatin{1FA0} & ᾠ & ᾡ & ᾢ & ᾣ & ᾤ & ᾥ & ᾦ & ᾧ & ᾨ & ᾩ & ᾪ & ᾫ & ᾬ & ᾭ & ᾮ & ᾯ\\
\textlatin{1FB0} & ᾰ & ᾱ & ᾲ & ᾳ & ᾴ &   & ᾶ & ᾷ & Ᾰ & Ᾱ & Ὰ & Ά & ᾼ & ᾽ & ι & ᾿\\
\textlatin{1FC0} & ῀ & ῁ & ῂ & ῃ & ῄ &   & ῆ & ῇ & Ὲ & Έ & Ὴ & Ή & ῌ & ῍ & ῎ & ῏\\
\textlatin{1FD0} & ῐ & ῑ & ῒ & ΐ &   &   & ῖ & ῗ & Ῐ & Ῑ & Ὶ & Ί &   & ῝ & ῞ & ῟\\
\textlatin{1FE0} & ῠ & ῡ & ῢ & ΰ & ῤ & ῥ & ῦ & ῧ & Ῠ & Ῡ & Ὺ & Ύ & Ῥ & ῭ & ΅ & `\\
\textlatin{1FF0} &   &   & ῲ & ῳ & ῴ &   & ῶ & ῷ & Ὸ & Ό & Ὼ & Ώ & ῼ & ´ & ῾ &  \\
\bottomrule
\end{tabular}
\selectlanguage{english}


\subsection{Other Unicode Blocks}

Latin-1 Supplement: \ensuregreek{¨ « ¯ ´ · »}

IPA Extensions: \ensuregreek{ə}

Spacing Modifier Letters: \ensuregreek{˘a} (here followed by letter alpha)

General Punctuation: \ensuregreek{– — ‘ ’ ‰} ZWNJ (zero width no joiner,
prevents kerning and ligatures, e.g. \ensuregreek{A‌‌U} vs. \ensuregreek{AU} and
\ensuregreek{'‌a} vs. \ensuregreek{'a})

Currency Symbols: \ensuregreek{€}

Letterlike Symbols: Ω  % OHM SIGN, preferred representation is 03A9

Ancient Greek Numbers: \ensuregreek{
𐅄 % \textPiDelta{} % GREEK ACROPHONIC ATTIC FIFTY
𐅅 % \textPiEta{}   % GREEK ACROPHONIC ATTIC FIVE HUNDRED
𐅆 % \textPiChi{}   % GREEK ACROPHONIC ATTIC FIVE THOUSAND
𐅇 % \textPiMu{}    % GREEK ACROPHONIC ATTIC FIFTY THOUSAND
}

\section{MakeUppercase, MakeLowercase}

Capital Greek letters have diacritics (except the dialytika) to the left
(instead of above) and drop them in uppercase, e.g.
\ensuregreek{μαΐστρος $\mapsto$ \MakeUppercase{μαΐστρος}}.

Tonos and dasia on the first vowel of a diphthong (\ensuregreek{άι, άυ, έι})
imply a \emph{hiatus}. A dialytika must be placed on the second
vowel if they are dropped (\ensuregreek{\MakeUppercase{\'ai, \'au, \'ei}}).

The auto-hiatus feature in lgrxenc.def works nice with the Latin
transcription and with character-macros (%
\ensuregreek{\MakeUppercase{%
  \'ai,
  \'\textalpha \textupsilon,
  \'\textepsilon \textiota
}})
and also if the first character is wrapped in \verb+\ensuregreek+ (as done by
the lgrenc.dfu definition for accented characters) or a literal Unicode
character
(\ensuregreek{\MakeUppercase{%
  \ensuregreek{\'\textalpha}\textiota,
  ά\textupsilon,
  ά\textiota
}})
but not if the second character of the diphthong is a Unicode literal
(\ensuregreek{\MakeUppercase{%
  \'\textalpha ι,
  άυ,
  \'\textepsilon ι
}}).

Therefore, the diaresis is missing in the following examples:
\ensuregreek{άυλος  $\mapsto$ \MakeUppercase{άυλος},
	   ἄυλος  $\mapsto$ \MakeUppercase{ἄυλος},
	   μάινα  $\mapsto$ \MakeUppercase{μάινα},
	   κέικ,  $\mapsto$ \MakeUppercase{κέικ},
	   ἀυπνία $\mapsto$ \MakeUppercase{ἀυπνία}}.

Fixing this shortcoming requires knowledge of what the
\verb+\LGR@ifnextchar+ ``sees'' when the next character is an upcased
Unicode literal.

As an ugly workaround, use \verb+\textiota+ resp. \verb+\textupsilon+
for the character that should get the diaresis:
\ensuregreek{ἀ\textupsilon{}πνία $\mapsto$ \MakeUppercase{ἀ\textupsilon{}πνία}}.



The following subsections test MakeUppercase and MakeLowercase with all
characters defined in lgrenc.dfu:

\subsection{Greek and Coptic}

\newcommand{\GreekAndCoptic}{ʹ͵ͺ; ΄ ΅ Ά·ΈΉΊΌΎΏΐΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩΪΫϘϚϜϠ}
\newcommand{\greekandcoptic}{άέήίΰαβγδεζηθικλμνξοπρςστυφχψωϊϋόύώϙϛϝϟϡ}

Characters of the Greek and Coptic Unicode Block:

\begin{quote}
  \selectlanguage{greek}
  \GreekAndCoptic\\
  \greekandcoptic
\end{quote}

MakeUppercase:

\begin{quote}
  \selectlanguage{greek}
  \MakeUppercase{\GreekAndCoptic}\\
  \MakeUppercase{\greekandcoptic}
\end{quote}

Letters and ypogegrammeni upcased, tonos dropped, dialytika kept.

There is no capital Koppa in LGR, therefore \ensuregreek{ϟ} is left unchanged
with MakeUppercase.


MakeLowercase:

\begin{quote}
  \selectlanguage{greek}
  \MakeLowercase{\GreekAndCoptic}\\
  \MakeLowercase{\greekandcoptic}
\end{quote}

The lowercase of \ensuregreek{Σ} is the «auto-sigma» (\verb+\textautosigma+):
\ensuregreek{ΣΣ $\mapsto$ \MakeLowercase{ΣΣ}}. Add a ZWNJ or use the
\verb+\noboundary+ macro to prevent conversion to final sigma:
\ensuregreek{\MakeLowercase{ΣΣ‌}}. The lowercase of GREEK LETTER STIGMA
\ensuregreek{Ϛ} is \ensuregreek{\MakeLowercase{Ϛ}}.

\newpage

\subsection{Greek extended}

MakeUppercase:

\selectlanguage{greek}

\MakeUppercase{ ἀ ἁ ἂ ἃ ἄ ἅ ἆ ἇ Ἀ Ἁ Ἂ Ἃ Ἄ Ἅ Ἆ Ἇ }\\
\MakeUppercase{ ἐ ἑ ἒ ἓ ἔ ἕ     Ἐ Ἑ Ἒ Ἓ Ἔ Ἕ     }\\
\MakeUppercase{ ἠ ἡ ἢ ἣ ἤ ἥ ἦ ἧ Ἠ Ἡ Ἢ Ἣ Ἤ Ἥ Ἦ Ἧ }\\
\MakeUppercase{ ἰ ἱ ἲ ἳ ἴ ἵ ἶ ἷ Ἰ Ἱ Ἲ Ἳ Ἴ Ἵ Ἶ Ἷ }\\
\MakeUppercase{ ὀ ὁ ὂ ὃ ὄ ὅ     Ὀ Ὁ Ὂ Ὃ Ὄ Ὅ     }\\
\MakeUppercase{ ὐ ὑ ὒ ὓ ὔ ὕ ὖ ὗ   Ὑ   Ὓ   Ὕ   Ὗ }\\
\MakeUppercase{ ὠ ὡ ὢ ὣ ὤ ὥ ὦ ὧ Ὠ Ὡ Ὢ Ὣ Ὤ Ὥ Ὦ Ὧ }\\
\MakeUppercase{ ὰ ά ὲ έ ὴ ή ὶ ί ὸ ό ὺ ύ ὼ ώ     }\\
\MakeUppercase{ ᾀ ᾁ ᾂ ᾃ ᾄ ᾅ ᾆ ᾇ ᾈ ᾉ ᾊ ᾋ ᾌ ᾍ ᾎ ᾏ }\\
\MakeUppercase{ ᾐ ᾑ ᾒ ᾓ ᾔ ᾕ ᾖ ᾗ ᾘ ᾙ ᾚ ᾛ ᾜ ᾝ ᾞ ᾟ }\\
\MakeUppercase{ ᾠ ᾡ ᾢ ᾣ ᾤ ᾥ ᾦ ᾧ ᾨ ᾩ ᾪ ᾫ ᾬ ᾭ ᾮ ᾯ }\\
\MakeUppercase{ ᾰ ᾱ ᾲ ᾳ ᾴ   ᾶ ᾷ Ᾰ Ᾱ Ὰ Ά ᾼ ᾽ ι ᾿ }\\
\MakeUppercase{ ῀ ῁ ῂ ῃ ῄ   ῆ ῇ Ὲ Έ Ὴ Ή ῌ ῍ ῎ ῏ }\\
\MakeUppercase{ ῐ ῑ ῒ ΐ     ῖ ῗ Ῐ Ῑ Ὶ Ί   ῝ ῞ ῟ }\\
\MakeUppercase{ ῠ ῡ ῢ ΰ ῤ ῥ ῦ ῧ Ῠ Ῡ Ὺ Ύ Ῥ ῭ ΅ ` }\\
\MakeUppercase{     ῲ ῳ ῴ   ῶ ῷ Ὸ Ό Ὼ Ώ ῼ ´ ῾   }
\selectlanguage{english}

MakeLowercase:

\selectlanguage{greek}
\MakeLowercase{ ἀ ἁ ἂ ἃ ἄ ἅ ἆ ἇ Ἀ Ἁ Ἂ Ἃ Ἄ Ἅ Ἆ Ἇ }\\
\MakeLowercase{ ἐ ἑ ἒ ἓ ἔ ἕ     Ἐ Ἑ Ἒ Ἓ Ἔ Ἕ     }\\
\MakeLowercase{ ἠ ἡ ἢ ἣ ἤ ἥ ἦ ἧ Ἠ Ἡ Ἢ Ἣ Ἤ Ἥ Ἦ Ἧ }\\
\MakeLowercase{ ἰ ἱ ἲ ἳ ἴ ἵ ἶ ἷ Ἰ Ἱ Ἲ Ἳ Ἴ Ἵ Ἶ Ἷ }\\
\MakeLowercase{ ὀ ὁ ὂ ὃ ὄ ὅ     Ὀ Ὁ Ὂ Ὃ Ὄ Ὅ     }\\
\MakeLowercase{ ὐ ὑ ὒ ὓ ὔ ὕ ὖ ὗ   Ὑ   Ὓ   Ὕ   Ὗ }\\
\MakeLowercase{ ὠ ὡ ὢ ὣ ὤ ὥ ὦ ὧ Ὠ Ὡ Ὢ Ὣ Ὤ Ὥ Ὦ Ὧ }\\
\MakeLowercase{ ὰ ά ὲ έ ὴ ή ὶ ί ὸ ό ὺ ύ ὼ ώ     }\\
\MakeLowercase{ ᾀ ᾁ ᾂ ᾃ ᾄ ᾅ ᾆ ᾇ ᾈ ᾉ ᾊ ᾋ ᾌ ᾍ ᾎ ᾏ }\\
\MakeLowercase{ ᾐ ᾑ ᾒ ᾓ ᾔ ᾕ ᾖ ᾗ ᾘ ᾙ ᾚ ᾛ ᾜ ᾝ ᾞ ᾟ }\\
\MakeLowercase{ ᾠ ᾡ ᾢ ᾣ ᾤ ᾥ ᾦ ᾧ ᾨ ᾩ ᾪ ᾫ ᾬ ᾭ ᾮ ᾯ }\\
\MakeLowercase{ ᾰ ᾱ ᾲ ᾳ ᾴ   ᾶ ᾷ Ᾰ Ᾱ Ὰ Ά ᾼ ᾽ ι ᾿ }\\
\MakeLowercase{ ῀ ῁ ῂ ῃ ῄ   ῆ ῇ Ὲ Έ Ὴ Ή ῌ ῍ ῎ ῏ }\\
\MakeLowercase{ ῐ ῑ ῒ ΐ     ῖ ῗ Ῐ Ῑ Ὶ Ί   ῝ ῞ ῟ }\\
\MakeLowercase{ ῠ ῡ ῢ ΰ ῤ ῥ ῦ ῧ Ῠ Ῡ Ὺ Ύ Ῥ ῭ ΅ ` }\\
\MakeLowercase{     ῲ ῳ ῴ   ῶ ῷ Ὸ Ό Ὼ Ώ ῼ ´ ῾   }
\selectlanguage{english}

\subsection{Other Unicode Blocks}

MakeUppercase works without effect on non-letter symbols and the letter shwa:

\ensuregreek{
\MakeUppercase{¨ « ¯ ´ · »}
\MakeUppercase{ə}
\MakeUppercase{˘a}
\MakeUppercase{– — ‘ ’ ‰ a‌u}
\MakeUppercase{€}
% \MakeUppercase{Ω}
\MakeUppercase{
𐅄 % GREEK ACROPHONIC ATTIC FIFTY
𐅅 % GREEK ACROPHONIC ATTIC FIVE HUNDRED
𐅆 % GREEK ACROPHONIC ATTIC FIVE THOUSAND
𐅇 % GREEK ACROPHONIC ATTIC FIFTY THOUSAND
}
}

MakeLowercase works without effect on non-letter symbols, too:

\ensuregreek{
\MakeLowercase{¨ « ¯ ´ · »}
\MakeLowercase{ə}
\MakeLowercase{˘A}
\MakeLowercase{– — ‘ ’ ‰ A‌‌U}
\MakeLowercase{€}
% \MakeLowercase{Ω}
\MakeLowercase{
𐅄 % GREEK ACROPHONIC ATTIC FIFTY
𐅅 % GREEK ACROPHONIC ATTIC FIVE HUNDRED
𐅆 % GREEK ACROPHONIC ATTIC FIVE THOUSAND
𐅇 % GREEK ACROPHONIC ATTIC FIFTY THOUSAND
}
}
\end{document}


Problems with text-extraction from PDF with Kerkis:

     0  1 2 3 4  5   6 7  8  9  A  B  C D E    F
370  *  * * *  ΄  ͵  * *         ι *  * *   ;
380            ΄ ΅  ΄Α   ΄Ε ΄Η  ΄Ι   ΄Ο   ΄Υ  ΄Ω
390   ΐ Α Β Γ ∆  Ε   Ζ Η Θ    Ι Κ  Λ Μ  Ν Ξ    Ο
3Α0  Π  Ρ   Σ Τ  Υ  Φ  Χ Ψ   Ω   Ϊ Ϋ  ά έ  ή    ί
3Β0  ΰ  α ϐ γ δ  ε   Ϲ η  ϑ   ι κ  λ  µ ν  ξ   ο
3῝0  π  ϱ ς σ τ  υ   ϕ χ  ψ  ω   ϊ ϋ  ό ύ  ώ
3∆0  *  * * * *  *   * *     Ϟ  Ϝ  ϝ  Ϝ ϝ  *   ϟ
3Ε0     ϡ * * *  *   * *  *  *  *  *  * *  *   *
3Φ0  *  * * * *  *   * *  *  *  *  *  * *  *   *


0387	GREEK ANO TELEIA    missing
03B6    zeta  	  	          replaced by 03F9	GREEK CAPITAL LUNATE SIGMA SYMBOL
03B8	GREEK SMALL LETTER THETA  replaced by 03D1	GREEK THETA SYMBOL
03C1	GREEK SMALL LETTER RHO    replaced by 03F1	GREEK RHO SYMBOL
03C6	GREEK SMALL LETTER PHI    replaced by 03D5	GREEK PHI SYMBOL


and GFS Didot:

       0   1   2  3  4  5   6 7  8  9  A  B  C D  E   F
370 *      *   *  *   ´  ͵ *  *         ι *  * *   ;
380                   ´  ῆ Α
                         ´ ´    ´Ε ´Η  ´Ι   ´Ο   ´Υ  ´Ω
390 ῆ  ´ι Α   Β   Γ  ∆  Ε Ζ   Η  Θ  Ι  Κ  Λ Μ  Ν  Ξ   Ο
3Α0 Π      Ρ       Σ  Τ  Υ Φ   Χ Ψ   Ω   ῆ
                                        Ι ῆ
                                          Υ  ά έ  ή    ί
3Β0 ῆ ´υ  α    β  γ  δ  ε ζ   η  ϑ   ι κ  λ  μ ν  ξ   ο
 3῝0 π    ρ    ς  σ  τ  υ φ   χ  ψ  ω   ι
                                        ῆ υ
                                          ῆ  ό ύ ώ
3∆0 *      *   *  *  *  * *   *           Ϛ  Ϝ Ϝ  *   Ϟ
3Ε0            *  *  *  * *   *  *  *   * *  * *  *   *
3Φ0 *      *   *  *  *  * *   *  *  *   * *  * *  *   *
