Character extensions and repertoires
The built-in conversion functions use a closed, standards-oriented Greek
alphabet. createConverter() creates an isolated immutable registry when an
application needs additional input spellings, direct mappings for extra
characters, or a smaller effective repertoire.
The configuration is checked when the converter is created, as conversion
options are. An unknown key throws an OptionError, whose path names it
(exclude, aliases[0].spellings, characters[0].forms.greek.lowercase) and
whose accepted lists the keys allowed there. So does a value outside a known
set: an out-of-scope behavior, the letter of an alias (aliases[0].letter),
or an identifier of repertoire or exclude that names no character
(exclude[1]), whose accepted lists the identifiers of the converter. A
list, a definition, or a field of the wrong type throws a TypeError, as an
invalid definition does (an empty or ambiguous spelling, a duplicate
identifier, a spelling that already has a meaning without override).
Aliases of built-in letters
Section titled “Aliases of built-in letters”An alias supplies another source spelling for an existing semantic letter:
import { createConverter } from "@humanities/greek-conversion";
const converter = createConverter({ aliases: [{ letter: "theta", format: "transliteration", spellings: ["þ"], }],});
converter.convert("þeós", "transliteration", "greek"); // → θεόςconverter.reencode("þeós", "transliteration"); // → theósreencode() writes the text again in its format, as the function of the same
name does: here it replaces the alias with the canonical spelling.
The alias is replaced by the canonical source-format spelling before parsing. It therefore receives the ordinary case, diacritic, context, validation, and information-loss behavior of the selected built-in letter.
Aliases are matched longest first. Construction rejects empty and ambiguous
spellings. A spelling already understood by the parser requires
override: true, making the change of meaning explicit.
Opaque custom characters
Section titled “Opaque custom characters”A custom character declares a stable identifier and one lowercase plus an optional uppercase spelling in every format:
import { createConverter } from "@humanities/greek-conversion";
const converter = createConverter({ characters: [{ id: "san", forms: { greek: { lowercase: "ϻ", uppercase: "Ϻ" }, "beta-code": { lowercase: "#9", uppercase: "*#9" }, transliteration: { lowercase: "š", uppercase: "Š" }, }, override: true, }],});
converter.convert("ϻαν Ϻ", "greek", "transliteration"); // → šan Šconverter.convert("ϻαν Ϻ", "greek", "beta-code"); // → #9an *#9Custom characters are opaque inside the Greek engine. The converter guarantees direct mapping, declared case, registry immutability, and stable round trips when the supplied forms are unambiguous. It does not infer that a custom character:
- is a vowel or consonant;
- accepts Greek diacritics;
- participates in a diphthong, dental assimilation, aspiration, or digraph;
- has an alphabetic-numeral value;
- belongs to any bundled preset.
The lowercase or uppercase form is selected from the semantic case recognized in
the source. General output options such as text.letterCase and betaCode.case
do not rewrite opaque forms; declare the exact forms required by the custom
profile. Beta Code input remains ASCII-case-insensitive, and * remains the
only semantic uppercase marker.
Word context
Section titled “Word context”A custom character stands for one letter of its word. The current
implementation still treats it as a word boundary for the built-in letters
around it: a sigma before it takes its final form, a vowel after it can
receive an inferred smooth breathing, and a capital spelled with several Latin
letters next to it is written with its first letter only in capitals (ΘϷΑ →
ThShA for a custom Ϸ → Sh). These are limitations, not guarantees. A
1.x release may let custom characters take part in their word, and such
output would then change as a correction.
The same applies to the case of a custom form. Among capitals, a multi-letter
uppercase form may then be written in full capitals, as built-in letters are
(THSHA): the toUpperCase() of the declared uppercase form, with the Greek
locale for Greek forms, and that spelling will be read back. Declare forms
that each represent one letter: for a form made of several words, or
containing spaces or punctuation, no case or word behavior is guaranteed.
Use an alias when a new spelling is semantically a known Greek letter. Use a custom character only when it represents a genuinely distinct inventory item.
The implementation reserves private-use Unicode scalars internally while a conversion is running. Supplying one of those scalars as input is rejected instead of risking silent corruption.
Greek passages
Section titled “Greek passages”A converter’s convertGreekPassages() and convertGreekPassagesDetailed()
convert the Greek passages of a text in another language with its characters
and scope, and copy the rest. Its Greek spellings, those of its aliases and of
its characters, belong to the passages, whatever characters they are made of:
import { createConverter } from "@humanities/greek-conversion";
const converter = createConverter({ aliases: [{ letter: "digamma", format: "greek", spellings: ["𝟋"] }],});
converter.convertGreekPassages("voir 𝟋άναξ ;", "transliteration");// → voir wánax ;The mathematical digamma 𝟋 (U+1D7CB) is outside the Greek blocks: without
the alias, it would be copied with the French around it.
Restricting the repertoire
Section titled “Restricting the repertoire”repertoire is an exact allow-list. Omitting it enables all built-in and
registered custom characters. exclude is applied afterwards and always wins:
import { createConverter } from "@humanities/greek-conversion";
const san = { id: "san", forms: { greek: { lowercase: "ϻ" }, "beta-code": { lowercase: "#9" }, transliteration: { lowercase: "š" }, }, override: true,};const converter = createConverter({ characters: [san], repertoire: ["alpha", "beta", "san"], exclude: ["san"],});
// Gamma is outside the allow-list, and san is excluded from it.converter.convert("αβγϻ", "greek", "transliteration"); // → abγϻThe policy is semantic rather than graphical. Excluding stigma applies to
its Greek, Beta Code, and transliterated spellings. An out-of-scope letter is
kept as the source writes it in its word:
- from Greek or Beta Code, in that format’s canonical spelling, which notes
every mark and shape the source can note: a final sigma stays final, a
lunate sigma stays lunate, and Beta Code is written in lowercase, with
*for a capital andjfor yot, whatever the conversion’sbetaCodeoptions, which only shape the converted text. A letter of a sign for several letters is written alone (ϗ, with iota out of scope, giveskaι), and a letter overlined in Beta Code in an overline of its own (<i#2>, with stigma out of scope, givesi̅<#2>). A mark that the reader does not know stays after it as a literal, once, though Unicode writes it in one cluster with the letter’s own marks (ἅ̇, with alpha out of scope); - from transliteration, copied from the source as it was read (with
source, when the options give one), since a transliteration’s spelling depends on options that can leave marks out: thenofngstaysn, and a macron or a coronis stays. After a restyle, the output’s style may read that spelling otherwise, andconvertDetailed()reports it: with phi out of scope,phílosrestyled underphi: "f"keepsph, which that style reads as pi and a rough breathing.
The options that shape the converted text, diacritics, greek, betaCode,
and transliteration, do not reach it, except the Unicode form of Greek
output (greek.composition and greek.acute), which applies to the whole
output. The transformations of the whole text (text) do: its case follows
text.letterCase, and under numerals: "decimal" a numeral it belongs to is
written as one number. A matched custom form retains its registered spelling.
The target may consequently contain a deliberate source-format fragment:
import { createConverter } from "@humanities/greek-conversion";
const noSigma = createConverter({ exclude: ["sigma"] });
noSigma.convert("λόγος σῶμα", "greek", "transliteration", { text: { letterCase: "title" },});// → Lógoς Σō̃maA kept letter is a letter of its word, so the letters around it keep their
place in it: σο, with omicron out of scope, keeps its medial sigma, title
case capitalizes the first letter of the word only, and a capital next to a
kept capital is among capitals (ΘΕΟΣ, with epsilon out of scope, gives
THΕOS). No rule reads which letter it is, though:
- A letter whose spelling depends on its neighbour is written as if the kept
letter were not a Greek letter. With alpha out of scope, the upsilon of
αὐτόνis transliteratedy(αytón). With kappa out of scope, the gamma ofἀνάγκηisg(anágκē). - Monotonic accentuation leaves the accent of a word that contains a kept letter, whose syllables it cannot count.
- A kept letter is not aspirated before a rough breathing:
ἀπ’ οὗ, with pi out of scope, keeps itsπ, which Greek output writesφunderelidedStop: "aspirate". - Transliteration writes the
hof a diphthong with a rough breathing before both vowels. Thehgoes with the vowel that has the breathing:hoi, with iota out of scope, givesοhiin Greek. - A letter whose spelling the reader shares with a neighbour, as the two
letters of a modern digraph do (
bfor μπ), is written alone, as it was read. - A spacing breathing or tonos (
΄) before a kept capital, at the start of a word, is written with a zero-width non-joiner (U+200C) after it, as before a capital that cannot carry it, since the writer cannot tell whether the kept capital would take it: the sign stays apart when the output is read again (῾άor΄ά, with alpha out of scope, in capitals).
Read again, a kept letter is a letter that the reader of the target keeps as
text, which is also a letter of its word (see
Guarantees):
the rules around it decide again what they decided. With alpha out of scope,
σα gives sα in Beta Code, which reads back as σα, and έα, in
monotonic Beta Code, keeps its accent: e/α. A second conversion still
reads otherwise:
- the spelling of a kept letter in its source format, its case, marks, and
codes included, which the target reads as its own characters:
a+, from Beta Code with alpha out of scope, givesa+in Greek, whose+reads back as a plus sign (a%7in Beta Code), and1’a, under ISO 843, gives1’a, whose apostrophe transliteration writes again as a modifier letter (1ʼa), lest it read back as a smooth breathing; - a kept letter in the target’s own format, which reads back as that letter:
with sigma out of scope, a
Σkept in Greek output is a sigma, which can begin a numeral under decimal numerals (ΣΤ΄); - a kept letter of transliteration in Beta Code output, or the reverse,
which the target reads as one of its own letters: Beta Code reads no case,
and with iota out of scope, transliteration
IagivesIain Beta Code, andiawhen converted again. Between these two formats, whose letters are both Latin, this is frequent; - under decimal numerals, a numeral after a kept letter whose combining mark
the target reads apart:
μὰςʹ, with alpha out of scope, givesmὰsʹin transliteration, whosesʹreads back as the numeral 200.
convertDetailed() reports a kept letter whose output does not convert back
to its spelling in the source as a literal that the target does not
represent (unrepresented-literal). It reports so the kept letters with
marks of a conversion that would otherwise be lossless, when the output does
not convert back as a whole. A conversion that it reports as lossless
therefore converts back to its source, as the guarantees
say.
convertDetailed() keeps scope diagnostics separate from conversion losses:
import { createConverter } from "@humanities/greek-conversion";
const converter = createConverter({ exclude: ["stigma"] });const result = converter.convertDetailed( "ἀϛβ", "greek", "transliteration",);
result.output; // → aϛbresult.lossy; // → falseresult.diagnostics[0].code; // → out-of-scope-character// In UTF-16 code units of the input.result.diagnostics[0].offset; // → 1Each diagnostic carries the index of its token in the source document as
the conversion prepared it, the document that losses and spans index as
well (a custom form preserved as several literals is reported at the first
of them), and the offset and length of the character’s spelling in the input
as supplied, whether the spelling is built in, an alias, or a custom form.
The result’s losses and spans follow the
conversion-analysis contract.
Keeping a letter is not information loss, so it does not set lossy.
For strict processing, select rejection when creating the converter:
import { CharacterScopeError, createConverter,} from "@humanities/greek-conversion";
const strict = createConverter({ preset: "perseus", outOfScopeBehavior: "reject",});
try { strict.convert("αϝ", "greek", "beta-code");} catch (error) { if (!(error instanceof CharacterScopeError)) throw error; error.message; // → Conversion rejected: 1 out-of-scope character. error.diagnostics.map(({ code, index }) => [code, index]); // → [["out-of-scope-character",1]]}Both convert() and convertDetailed() reject the entire input when a
recognized character falls outside the effective repertoire or has a known
undefined or unresolved mapping in the target preset. The error contains
every such occurrence, with the same source token indices as
convertDetailed().diagnostics in preservation mode. Unknown literals remain
literal: strict mode checks recognized characters, not arbitrary text.
Rejection checks a recognized character against the converter’s effective
repertoire and the known missing mappings for the bound preset and target. It
does not guarantee a reversible or fully standards-conformant conversion. For
example, a strict BnF converter accepts αʹ and emits á, whose numeral mark
cannot be recovered reliably. This can have lossy: true without scope
diagnostics. Check convertDetailed().losses independently when these
distinctions matter. See the preset behavior audit
for other rules that require contextual information.
Preset boundary
Section titled “Preset boundary”Bind a preset to a converter to apply both its conversion options and every scope boundary established by the audit:
import { createConverter } from "@humanities/greek-conversion";
const perseus = createConverter({ preset: "perseus" });
perseus.convert("Ἄνθρωπος ϝ", "greek", "beta-code");// → *)/anqrwpos ϝHere digamma is recognized but preserved because it is outside the Perseus
subset. Named in options instead, as convert() takes it, a preset is its
options alone, and holds the text to no scope. convertDetailed() reports it as out-of-scope-character. Set
outOfScopeBehavior: "reject" on the converter to reject it instead. Per-call
options may refine the bound preset, but selecting another preset is rejected
because its options would no longer agree with the converter’s fixed scope.
The input is the exception: source describes how it is written, may name
another preset, and is resolved on its own, so that source: {} reads the
default style, not the bound preset’s.
ALA-LC boundaries are context-sensitive. For example, a modern ALA-LC-bound
converter preserves unmarked stigma but accepts ϛʹ as the alphabetic numeral
6. ISO 843 includes stigma, koppa, and sampi in its Greek source inventory but
does not define their Type 1 transliterations. A bound ISO converter reports
undefined-preset-mapping when transliterating them; for archaic koppa it
reports unresolved-preset-mapping because the single koppa named in the
standard cannot be assigned unambiguously to the engine’s two forms. In
preservation mode they remain Greek text in the output; strict mode rejects
them. Explicit decimal conversion of marked numerals still works. Other
conversion targets, and conversions that name the preset in their options,
retain the engine’s behavior.
Adding an alias or custom character never expands the documented scope of a
preset. A custom character registered alongside a bound preset is allowed as
an explicit application extension, but no preset guarantees apply to its
mapping. repertoire and exclude can restrict built-in and custom characters
further; they never override a preset exclusion.