textalpha.sty

Greek symbols in text

Version:
2.5 (changelog)
Licence:

This work may be distributed and/or modified under the conditions of the LaTeX Project Public License, either version 1.3 of this license or any later version.

Abstract

Provide a set of LICR macros for Greek characters in text mode.

Motivation

By default, TeX macros for Greek letters are only valid in mathematical mode. This package sets up a suitable font encoding and LaTeX internal character representations (LICR) definitions for Greek (\textalpha\textOmega).

To allow documents using Greek LICR macros without worrying about the TeX engine used to compile them, this package tests the declared font encodings and does “the right thing” to set up Greek text font support:

Advantages:

Usage

Ensure support for Greek characters in text mode with

\usepackage{textalpha}

eventually with the options to normalize symbols variants

\usepackage[normalize-symbols]{textalpha}

and/or to use the semicolon as erotimatiko also in 8-bit TeX

\usepackage[normalize-symbols,keep-semicolon]{textalpha}

To give textalpha.sty a chance of finding out which font encodings are used, load it after fontspec and/or fontenc.

Documentation

A HTML rendering of the literal source is available as textalpha.sty.html (you may be reading it just now).

For detailed examples see textalpha-doc.tex and textalpha-doc.pdf (8-bit TeX and XeTeX/LuaTeX in 8-bit compatibility mode) as well as test-tuenc-greek.tex and test-tuenc-greek.pdf (XeTeX/LuaTeX with Unicode fonts).

With XeTeX or LuaTex, Unicode fonts and LGR encoded 8-bit fonts can be used in the same document (see test-tuenc-greek.tex).

Implementation

Identification

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{textalpha}[2023-09-12 2.5 macros for Greek letters in text]

Options

normalize-symbols

The “variant shape” symbol characters like 03D1 GREEK THETA SYMBOL are mathematical charcters for mathematical use (similar to 1D440 MATHEMATICAL ITALIC CAPITAL M). Unfortunately, some Greek texts sources in Unicode encoding mix letter and symbol characters .

The “normalize-symbols” option controls the handling of variant shape symbols under 8-bit TeX:

  • The option activates a simple “folding” mechanism that merges ϰ and κ to textkappa etc. for text copied from external sources which may use the GREEK SYMBOL characters in place of GREEK LETTERS,

  • Without this option, variant shape symbols in the input are reported as errors to prevent information loss in cases where the distinction between ϰ and κ is intended (e.g. in mathematical or scientific context).

With XeTeX/LuaTeX and Unicode fonts, this option is ignored.

\newif\iftextalpha@normalizeSymbols
\DeclareOption{normalize-symbols}{\textalpha@normalizeSymbolstrue}

keep-semicolon

The erotimatiko looks like a semicolon but is a Greek question mark:

  • The LGR font encoding uses the Latin question mark as input for the erotimatiko and maps the semicolon to a middle dot (ano teleia).

  • The Unicode standard provides the code point 037E GREEK QUESTION MARK but says: “character 003B SEMICOLON (and not 037E) is the preferred character for Greek question mark”.

The keep-semicolon option allows to use the semicolon as erotimatiko in both, Xe/LuaTeX and 8-bit TeX. (The ano teleia can be input as \textanoteleia or using character 00B7 MIDDLE DOT.) With XeTeX/LuaTeX and Unicode fonts, this option is ignored.

\newif\iftextalpha@keepSemicolon
\DeclareOption{keep-semicolon}{\textalpha@keepSemicolontrue}

\ProcessOptions\relax

Symbol macros for breathings

In the Latin transliteration provided by LGR, breathing accents (Dasia and Psili) are input as < and >. Provide the corresponding NFSS macro accents. (Used below for LGR, TU, and PU, if these font encodings are defined):

\providecommand*{\IfFormatAtLeastTF}[3]{#3} % new in 2020

\newcommand{\textalpha@define@breathings}[1]{
  \DeclareTextCommand{\<}{#1}{\accdasia}
  \DeclareTextCommand{\>}{#1}{\accpsili}
  % Composite accents starting with the new-defined shortcuts:
  \DeclareTextCompositeCommand{\>}{#1}{'}{\accpsilioxia}
  \DeclareTextCompositeCommand{\>}{#1}{`}{\accpsilivaria}
  \DeclareTextCompositeCommand{\>}{#1}{~}{\accpsiliperispomeni}
  \DeclareTextCompositeCommand{\<}{#1}{'}{\accdasiaoxia}
  \DeclareTextCompositeCommand{\<}{#1}{`}{\accdasiavaria}
  \DeclareTextCompositeCommand{\<}{#1}{~}{\accdasiaperispomeni}

  \IfFormatAtLeastTF{2022/06/01}{}{% else
    \DeclareTextCompositeCommand{\<}{#1}{^^9f}{\LGR@hiatus}
    \DeclareTextCompositeCommand{\>}{#1}{^^9f}{\LGR@hiatus}
  }

Also define “mixed” composites (required due to the fix for \MakeUppercase below:

  % \MakeUppercse: \>~a, \<~a
  % \DeclareTextCompositeCommand{\accpsili}{#1}{~}{\accpsiliperispomeni}
  % \DeclareTextCompositeCommand{\accdasia}{#1}{~}{\accdasiaperispomeni}
}

Fix 2022 MakeUppercase:

\ifdefined\DeclareCaseChangeEquivalent % new in 2023
  \DeclareCaseChangeEquivalent{\<}{\CaseSwitch{\<}{\LGR@accdropped}{\<}{\<}}
  \DeclareCaseChangeEquivalent{\>}{\CaseSwitch{\>}{\LGR@hiatus}{\>}{\>}}
\fi

Font encodings

With 8-bit LaTeX, the LGR font encoding is used for Greek characters. If no Greek-supporting font encoding (TU or LGR) is declared, LGR is loaded and set up as default Greek font encoding by this package.

With XeTeX or LuaTeX, there is one common input and font encoding – Unicode. 8-bit TeX font encodings are only used in compatibility mode or for fonts not available otherwise. For compatibility with the LaTeX font selection system, fontspec defines the TU font encoding. However fontspec does not define Greek LICR macros. We therefore explicitely load Greek LICR definitions for XeTeX/LuaTeX from tuenc-greek.def which in turn includes greek-fontenc.def.

Ensure a Greek-supporting font encoding exists and supports Greek LICR macros:

\ifdefined \UnicodeEncodingName % set by LaTeX for Unicode-aware engines
  \input{tuenc-greek.def}
  \textalpha@define@breathings{\UnicodeEncodingName}
\else
  \@ifl@aded{def}{lgrenc}
    {}
    {\input{lgrenc.def}
  }
\fi

LGR may also be used in a document compiled with Xe/LuaTeX (enables use of 8-bit TeX fonts and input via the Latin transliteration). Add setup for breathings:

\@ifl@aded{def}{lgrenc}
  {\textalpha@define@breathings{LGR}}
  {}

The package hyperref defines the PU font encoding and adds some LICR commands for monotonic Greek (in punenc-greekbasick.def). Add support for polytonic Greek, archaic symbols, and the \greekscript and \ensuregreek TextCommands:

\AtBeginDocument{
  \@ifl@aded{def}{puenc}
    {\@ifl@aded{def}{puenc-greek}
      {}% already loaded (e.g. by babel-greek)
      {\edef\RestoreAtCatcode{\catcode`@=\the\catcode`@\relax}%
       \makeatletter
       \input{puenc-greek.def}
       \RestoreAtCatcode
      }%
     \textalpha@define@breathings{PU}
     \pdfstringdefDisableCommands{\let\TextOrMath\@firstoftwo}
    }
    {}
}

The TS1 font encoding (available by default since 2022) provides a MICRO SIGN under the name \textmu but we use this name for the GREEK SMALL LETTER MU. The new macro \textmicro selects the character from TS1 fonts and is not capitalised with \MakeUppercase:

\DeclareTextSymbol{\textmicro}{TS1}{181} % micro sign
\DeclareTextSymbolDefault{\textmicro}{TS1}

Use it for the MICRO SIGN character:

\ifdefined\DeclareUnicodeCharacter
  \DeclareUnicodeCharacter{00B5}{\textmicro} % micro sign
\fi

Default declarations

The following definitions ensure that the Greek LICR macros can be used anywhere in the document also with 8-bit TeX by declaring LGR as their default font encoding. Abort here, if the LGR font encoding is not defined:

\@ifl@aded{def}{lgrenc}{}{ % else return:
  \expandafter\endinput
}

greekscript, ensuregreek

The \greekscript declaration ensures the current font encoding supports the Greek script. greek-fontenc.def sets this to the empty declaration for font encodings that do so. This is currently used by lgrenc.def (LGR) and tuenc-greek.def (Greek LICR macros for TU, EU1, or EU2).

We define LGR as default encoding for Greek text. We use \ProvideTextCommandDefault to enable the author or other packages to use an alternative definition (see [fntguide]):

\ProvideTextCommandDefault{\greekscript}{\fontencoding{LGR}\selectfont
      \def\encodingdefault{LGR}}

The \ensuregreek command can be used to ensure that its argument is set in a font encoding with support for Greek. Again the default is LGR:

\ProvideTextCommandDefault{\ensuregreek}[1]{\leavevmode{\greekscript #1}}

Eventually, all font encodings supporting Greek script (e.g. LGI, PU, TU) will declare \ensuregreek as text command that passes the argument unchanged. This way, kerning and selection of precomposed glyphs would work also for cases like \ensuregreek{\'A}U.

Greek Alphabet

Define the text* marcos as default for all font encodings:

\DeclareTextSymbolDefault{\textAlpha}{LGR}
\DeclareTextSymbolDefault{\textBeta}{LGR}
\DeclareTextSymbolDefault{\textGamma}{LGR}
\DeclareTextSymbolDefault{\textDelta}{LGR}
\DeclareTextSymbolDefault{\textEpsilon}{LGR}
\DeclareTextSymbolDefault{\textZeta}{LGR}
\DeclareTextSymbolDefault{\textEta}{LGR}
\DeclareTextSymbolDefault{\textTheta}{LGR}
\DeclareTextSymbolDefault{\textIota}{LGR}
\DeclareTextSymbolDefault{\textKappa}{LGR}
\DeclareTextSymbolDefault{\textLambda}{LGR}
\DeclareTextSymbolDefault{\textMu}{LGR}
\DeclareTextSymbolDefault{\textNu}{LGR}
\DeclareTextSymbolDefault{\textXi}{LGR}
\DeclareTextSymbolDefault{\textOmicron}{LGR}
\DeclareTextSymbolDefault{\textPi}{LGR}
\DeclareTextSymbolDefault{\textRho}{LGR}
\DeclareTextSymbolDefault{\textSigma}{LGR}
\DeclareTextSymbolDefault{\textTau}{LGR}
\DeclareTextSymbolDefault{\textUpsilon}{LGR}
\DeclareTextSymbolDefault{\textPhi}{LGR}
\DeclareTextSymbolDefault{\textChi}{LGR}
\DeclareTextSymbolDefault{\textPsi}{LGR}
\DeclareTextSymbolDefault{\textOmega}{LGR}
%
\DeclareTextSymbolDefault{\textalpha}{LGR}
\DeclareTextSymbolDefault{\textbeta}{LGR}
\DeclareTextSymbolDefault{\textgamma}{LGR}
\DeclareTextSymbolDefault{\textdelta}{LGR}
\DeclareTextSymbolDefault{\textepsilon}{LGR}
\DeclareTextSymbolDefault{\textzeta}{LGR}
\DeclareTextSymbolDefault{\texteta}{LGR}
\DeclareTextSymbolDefault{\texttheta}{LGR}
\DeclareTextSymbolDefault{\textiota}{LGR}
\DeclareTextSymbolDefault{\textkappa}{LGR}
\DeclareTextSymbolDefault{\textlambda}{LGR}
\DeclareTextSymbolDefault{\textmu}{LGR}
\DeclareTextSymbolDefault{\textmugreek}{LGR}    % (puenc.def)
\DeclareTextSymbolDefault{\textnu}{LGR}
\DeclareTextSymbolDefault{\textxi}{LGR}
\DeclareTextSymbolDefault{\textomicron}{LGR}
\DeclareTextSymbolDefault{\textpi}{LGR}
\DeclareTextSymbolDefault{\textrho}{LGR}
\DeclareTextSymbolDefault{\textsigma}{LGR}
\DeclareTextSymbolDefault{\textfinalsigma}{LGR}
\DeclareTextSymbolDefault{\textvarsigma}{LGR}   % alias for \textfinalsigma
\DeclareTextSymbolDefault{\textautosigma}{LGR}  % char 115 in LGR
\DeclareTextSymbolDefault{\texttau}{LGR}
\DeclareTextSymbolDefault{\textupsilon}{LGR}
\DeclareTextSymbolDefault{\textphi}{LGR}
\DeclareTextSymbolDefault{\textchi}{LGR}
\DeclareTextSymbolDefault{\textpsi}{LGR}
\DeclareTextSymbolDefault{\textomega}{LGR}

Additional Greek symbols

Including alias names for compatibility with hyperref’s puenc.def.

Ancient Greek Numbers (Athenian Numerals):

\DeclareTextSymbolDefault{\textpentedeka}{LGR}    % GREEK ACROPHONIC ATTIC FIFTY
\DeclareTextSymbolDefault{\textpentehekaton}{LGR} % GREEK ACROPHONIC ATTIC FIVE HUNDRED
\DeclareTextSymbolDefault{\textpenteqilioi}{LGR}  % GREEK ACROPHONIC ATTIC FIVE THOUSAND
\DeclareTextSymbolDefault{\textpentemurioi}{LGR}  % GREEK ACROPHONIC ATTIC FIFTY THOUSAND

Archaic letters:

\DeclareTextSymbolDefault{\textstigma}{LGR}      % ϛ
\DeclareTextSymbolDefault{\textstigmagreek}{LGR} % ϛ (puenc.def)
\DeclareTextSymbolDefault{\textvarstigma}{LGR}   % stigma variant (no separate Unicode character)
\DeclareTextSymbolDefault{\textkoppa}{LGR}       % ϟ Greek small letter koppa
\DeclareTextSymbolDefault{\textkoppagreek}{LGR}  % ϟ (puenc.def)
\DeclareTextSymbolDefault{\textKoppa}{LGR}       % ϟ Greek letter koppa (numeral koppa)
\DeclareTextSymbolDefault{\textKoppagreek}{LGR}  % ϟ (puenc.def)
\DeclareTextSymbolDefault{\textqoppa}{LGR}       % ϙ (archaic koppa)
\DeclareTextSymbolDefault{\textQoppa}{LGR}       % Ϙ (archaic Koppa)
\DeclareTextSymbolDefault{\textStigma}{LGR}      % Ϛ ϹΤ ligature in some fonts
\DeclareTextSymbolDefault{\textStigmagreek}{LGR} % Ϛ (puenc.def)
\DeclareTextSymbolDefault{\textSampi}{LGR}       % Ϡ
\DeclareTextSymbolDefault{\textSampigreek}{LGR}  % Ϡ (puenc.def)
\DeclareTextSymbolDefault{\textsampi}{LGR}       % ϡ
\DeclareTextSymbolDefault{\textsampigreek}{LGR}  % ϡ (puenc.def)
\DeclareTextSymbolDefault{\textanoteleia}{LGR}   % ·
\DeclareTextSymbolDefault{\texterotimatiko}{LGR} % ; (003B is the preferred character)
\DeclareTextSymbolDefault{\textdigamma}{LGR}     % ϝ
\DeclareTextSymbolDefault{\textDigamma}{LGR}     % Ϝ
\DeclareTextSymbolDefault{\textdigammagreek}{LGR} % ϝ (puenc.def)
\DeclareTextSymbolDefault{\textDigammagreek}{LGR} % Ϝ (puenc.def)

numeral signs: http://en.wikipedia.org/wiki/Greek_numerals

\DeclareTextSymbolDefault{\textdexiakeraia}{LGR}      % ʹ (Dexia keraia)
\DeclareTextSymbolDefault{\textnumeralsigngreek}{LGR} % (puenc.def)
\DeclareTextSymbolDefault{\textaristerikeraia}{LGR}   % ͵ (Aristeri keraia)
\DeclareTextSymbolDefault{\textnumeralsignlowergreek}{LGR} % (puenc.def)
variant shape symbols

Mathematical notation uses variant shapes of some Greek letters as additional symbols. There are separate code points for the symbol variants in Unicode but not in the LGR font encoding used for Greek in 8-bit TeX. The variations have no syntactic meaning in Greek text.

\DeclareTextSymbolDefault{\textbetasymbol}{LGR}    % ϐ GREEK BETA SYMBOL
\DeclareTextSymbolDefault{\textthetasymbol}{LGR}   % ϑ $\vartheta$ GREEK THETA SYMBOL
\DeclareTextSymbolDefault{\textphisymbol}{LGR}     % ϕ $\phi$ GREEK PHI SYMBOL
\DeclareTextSymbolDefault{\textpisymbol}{LGR}      % ϖ $\varpi$ GREEK PI SYMBOL
\DeclareTextSymbolDefault{\textkappasymbol}{LGR}   % ϰ GREEK KAPPA SYMBOL
\DeclareTextSymbolDefault{\textrhosymbol}{LGR}     % ϱ $\varrho$ GREEK RHO SYMBOL
\DeclareTextSymbolDefault{\textThetasymbol}{LGR}   % ϴ GREEK CAPITAL THETA SYMBOL
\DeclareTextSymbolDefault{\textepsilonsymbol}{LGR} % ϵ $\epsilon$ GREEK LUNATE EPSILON SYMBOL

Define compatibility mappings if the normalize-symbols option is set:

\iftextalpha@normalizeSymbols
  \DeclareTextCommand{\textbetasymbol}   {LGR}{\textbeta}
  \DeclareTextCommand{\textthetasymbol}  {LGR}{\texttheta}
  \DeclareTextCommand{\textphisymbol}    {LGR}{\textphi}
  \DeclareTextCommand{\textpisymbol}     {LGR}{\textpi}
  \DeclareTextCommand{\textkappasymbol}  {LGR}{\textkappa}
  \DeclareTextCommand{\textrhosymbol}    {LGR}{\textrho}
  \DeclareTextCommand{\textThetasymbol}  {LGR}{\textTheta}
  \DeclareTextCommand{\textepsilonsymbol}{LGR}{\textepsilon}
\fi

Diacritics

Greek diacritics via “named” macros:

\DeclareTextAccentDefault{\accdasia}{LGR}
\DeclareTextAccentDefault{\accpsili}{LGR}
\DeclareTextAccentDefault{\acctonos}{LGR}
\DeclareTextAccentDefault{\accoxia}{LGR}
\DeclareTextAccentDefault{\accvaria}{LGR}
\DeclareTextAccentDefault{\accperispomeni}{LGR}
\DeclareTextAccentDefault{\accdialytika}{LGR}
%
\DeclareTextAccentDefault{\accdasiaoxia}{LGR}
\DeclareTextAccentDefault{\accdasiavaria}{LGR}
\DeclareTextAccentDefault{\accdasiaperispomeni}{LGR}
\DeclareTextAccentDefault{\accpsilioxia}{LGR}
\DeclareTextAccentDefault{\accpsilivaria}{LGR}
\DeclareTextAccentDefault{\accpsiliperispomeni}{LGR}
\DeclareTextAccentDefault{\accdialytikatonos}{LGR}
\DeclareTextAccentDefault{\accdialytikavaria}{LGR}
\DeclareTextAccentDefault{\accdialytikaperispomeni}{LGR}

Symbol macros for the breathings:

\DeclareTextAccentDefault{\<}{LGR}
\DeclareTextAccentDefault{\>}{LGR}

Postfix accents:

\DeclareTextSymbolDefault{\ypogegrammeni}{LGR} % subscript mute iota (combining)
\DeclareTextSymbolDefault{\prosgegrammeni}{LGR}  % adscript mute iota (spacing)

Other accents in LGR:

\DeclareTextAccentDefault{\accinvertedbrevebelow}{LGR} % INVERTED BREVE BELOW
\DeclareTextAccentDefault{\textsubarch}{LGR}           % tipa, Teubner name: ut
\DeclareTextAccentDefault{\accbrevebelow}{LGR}         % BREVE BELOW

Auxiliary macros

\MakeUppercase requires four internal commands:

\DeclareTextAccentDefault{\LGR@accdropped}{LGR}
\DeclareTextAccentDefault{\LGR@accDialytika}{LGR}
\DeclareTextAccentDefault{\LGR@hiatus}{LGR}
\DeclareTextSymbolDefault{\LGR@ypogegrammeni}{LGR}

semicolon as erotimatiko

The text command \textsemicolon inserts \texterotimatiko in LGR font encoding and a “normal” semicolon else. In math mode, it inserts the “normal” semicolon also if the text font encoding is LGR:

\ProvideTextCommandDefault{\textsemicolon}{;}
\ProvideTextCommand{\textsemicolon}{LGR}{\texterotimatiko}

The LGR font encoding maps “;” to a middle dot (ano teleia). With the keep-semicolon option, the semicolon is made an active character and calls \textsemicolon:

\iftextalpha@keepSemicolon
  \catcode`;=\active
  \newcommand{;}{\TextOrMath{\textsemicolon}{\char59}}
\fi

TODO

Changelog

0.1

2010-06-16

initial version

0.2

2012-06-27

support for compound Unicode definitions outside LGR

0.3

2013-05-03

new accent macro names with lgrxenc.def 0.7

0.4

2013-05-28

use lgrenc.def from greek-fontenc.

0.5

2013-09-11

move to greek-fontenc,

support XeTeX/LuaTeX, add breve below accents.

0.11

2013-11-28

compatibility with Xe/LuaTeX in 8-bit mode.

0.12

2014-12-12

fix auxiliary macro names, define symbol macros for breathing accents.

0.13

2015-09-04

Option normalize-symbols: support for symbol variants.

Option keep-semicolon: use semicolon as erotimatiko in LGR.

0.13.2

2016-02-05

Support for standard Unicode text font encoding “TU” (new in fontspec v2.5a).

0.13.4

2019-07-11

Auxiliary command for subscript iota.

0.14

2020-02-28

Update test for Unicode fonts. Rename greek-euenc to tuenc-greek. Don’t use \LastDeclaredEncoding.

1.0

2020-09-25

Also set \encodingdefault with \greekscript.

2.0

2020-10-30

Load tuenc-greek.def with Xe/LuaTeX by default.

Load puenc-greek.def if used with hyperref.

2.2

2023-02-28

Don’t use \makeatother in \AtBeginDocument.

2.2.1

2023-03-08

Documentation update.

2.2.2

2023-03-17

Don’t map active ; to \textsemicolon in math mode.

2.4

2023-08-16

Map character 00B5 MICRO SIGN to \textmicro.

Fix upcasing of Greek letters with \< and \>.

2.5

2023-09-12

Support the \accoxia alias.

mirror server hosted at Truenetwork, Russian Federation.