1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="generator" content="Docutils 0.19b.dev: https://docutils.sourceforge.io/" />
<title>LGR Transcription to Greek LICR transformation</title>
<meta name="dcterms.rights" content="© 2010 Günter Milde" />
<link rel="schema.dcterms" href="http://purl.org/dc/terms/"/>
<link rel="stylesheet" href="minimal.css" type="text/css" />
<link rel="stylesheet" href="responsive.css" type="text/css" />
</head>
<body>
<main id="lgr-transcription-to-greek-licr-transformation">
<h1 class="title">LGR Transcription to Greek LICR transformation</h1>
<dl class="docinfo simple">
<dt class="copyright">Copyright<span class="colon">:</span></dt>
<dd class="copyright">© 2010 Günter Milde</dd>
<dt class="licence">Licence<span class="colon">:</span></dt>
<dd class="licence"><p>This work may be distributed and/or modified under the
conditions of the <a class="reference external" href="http://www.latex-project.org/lppl.txt">LaTeX Project Public License</a>, either
version 1.3 of this license or any later version.</p>
</dd>
</dl>
<!-- #!/usr/bin/env lua -->
<p>The LGR font encoding is the de-facto standard for Greek typesetting with
LaTeX. This file provides a translation from the Latin transcription defined
by LGR into the LaTeX Internal Character Representation (LICR) macros.</p>
<pre class="literal-block">usage = [[
Usage: lua lgr2licr.lua [OPTIONS] [STRING]
Convert STRING from Latin transcription to LICR macros for Greek symbols.
(This dumb conversion fails if the string contains TeX macros.)
Without argument, the script reads from standard input like a
redirected file. End interactive input with Ctrl-D.
Options: -h, --help show this help
-f, --file read input from file STRING
]]
if arg[1] == "-h" or arg[1] == "--help" then
print(usage)
return
end</pre>
<p>Get input string:</p>
<pre class="literal-block">local s
if arg[1] == "-f" then
local f = assert(io.open(arg[2], "r"))
s = f:read("*all")
f:close()
elseif arg[1] then
s = table.concat(arg, " ") .. "\n"
else
-- test:
-- s = "\\emph{x\\'us}"
s = io.read("*all")
end</pre>
<p>The mapping from the LGR Latin transcription to LICR macros:</p>
<pre class="literal-block">LGR_map = {
A = "\\textAlpha{}",
B = "\\textBeta{}",
G = "\\textGamma{}",
D = "\\textDelta{}",
E = "\\textEpsilon{}",
Z = "\\textZeta{}",
H = "\\textEta{}",
J = "\\textTheta{}",
I = "\\textIota{}",
K = "\\textKappa{}",
L = "\\textLambda{}",
M = "\\textMu{}",
N = "\\textNu{}",
X = "\\textXi{}",
O = "\\textOmicron{}",
P = "\\textPi{}",
R = "\\textRho{}",
S = "\\textSigma{}",
T = "\\textTau{}",
U = "\\textUpsilon{}",
F = "\\textPhi{}",
Q = "\\textChi{}",
Y = "\\textPsi{}",
W = "\\textOmega{}",
a = "\\textalpha{}",
b = "\\textbeta{}",
g = "\\textgamma{}",
d = "\\textdelta{}",
e = "\\textepsilon{}",
z = "\\textzeta{}",
h = "\\texteta{}",
j = "\\texttheta{}",
i = "\\textiota{}",
k = "\\textkappa{}",
l = "\\textlambda{}",
m = "\\textmu{}",
n = "\\textnu{}",
x = "\\textxi{}",
o = "\\textomicron{}",
p = "\\textpi{}",
r = "\\textrho{}",
s = "\\textautosigma{}",
c = "\\textfinalsigma{}",
t = "\\texttau{}",
u = "\\textupsilon{}",
f = "\\textphi{}",
q = "\\textchi{}",
y = "\\textpsi{}",
w = "\\textomega{}",
v = "\\noboundary{}",
["'"] = "\\'",
["`"] = "\\`",
["~"] = "\\~",
["<"] = "\\<",
[">"] = "\\>",
["|"] = "\\|",
['"'] = '\\"',
[";"] = "\\textanoteleia{}",
["?"] = "\\texterotimatiko{}",
}</pre>
<p>Return substitution string for 3 captures:</p>
<p><cite>c1</cite> backslash
<cite>c2</cite> a-zA-Z
<cite>c3</cite> any other char</p>
<pre class="literal-block">function lgr_replace(c1, c2, c3)
-- print (c1, c2, c3)
if c1 == "\\" then
if c2 and (c2 ~= "") then
return c1 .. c2 .. (LGR_map[c3] or c3 or "")
end
return c1 .. c3
end
c2 = string.gsub(c2, "s(.)", "sv%1")
return (string.gsub(c2, ".", LGR_map) or "") .. (LGR_map[c3] or c3 or "")
end
-- Use the mapping to replace every ASCII-character with
-- non-standard meaning to the corresponding LICR macro
-- (skip macros)::
-- *([a-zA-Z'`~<>|\";?]
s = string.gsub(s, "(\\?)([a-zA-Z]*)([^\\]?)", lgr_replace)</pre>
<p>Ligatures:</p>
<pre class="literal-block">s = string.gsub(s, "%(%(", "\\guillemetleft{}")
s = string.gsub(s, "%)%)", "\\guillemetright{}")
s = string.gsub(s, "\\'\\'", "\\textquoteright{}") -- ''
s = string.gsub(s, "\\`\\`", "\\textquoteleft{}") -- ``
s = string.gsub(s, '\"(%s)', "\\textquoteright{}%1")</pre>
<p>Separating empty group “{}” only required if followed by space or ASCII:</p>
<pre class="literal-block">s = string.gsub(s, "{}([^ a-zA-Z])", "%1")</pre>
<p>Autosigma replacements:</p>
<pre class="literal-block">s = string.gsub(s, "\\textautosigma\\noboundary", "\\textsigma") -- sv
s = string.gsub(s, "\\textautosigma(\\['`~<>|\"])", "\\textsigma%1") -- accents
s = string.gsub(s, "\\textautosigma([-%s!#$%%&%(%)*+,./0-9:=%[%]{|}])",
"\\textfinalsigma%1")
s = string.gsub(s, "\\textautosigma(\\textquote)", "\\textfinalsigma%1")
s = string.gsub(s, "\\textautosigma(\\texterotimatiko)", "\\textfinalsigma%1")
s = string.gsub(s, "\\textautosigma(\\textanoteleia)", "\\textfinalsigma%1")
s = string.gsub(s, "\\textautosigma$", "\\textfinalsigma")</pre>
<p>Write the result to stdout:</p>
<pre class="literal-block">io.write(s)</pre>
</main>
</body>
</html>
|