summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/greek-fontenc/lgr2licr.lua.html
blob: 33e6d586acb41614474490cf2f6ab5aa02f3ca51 (plain)
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
167
168
169
170
171
172
173
174
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.11: http://docutils.sourceforge.net/" />
<title>LGR Transcription to Greek LICR transformation</title>
<meta name="copyright" content="© 2010 Günter Milde" />
<link rel="stylesheet" href="../../../../../Python/docutils-svn/docutils/docutils/writers/html4strict/html4css1.css" type="text/css" />
<link rel="stylesheet" href="../../../../../Python/docutils-svn/docutils/docutils/writers/html4strict/html4css2.css" type="text/css" />
</head>
<body>
<div class="document" 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</dt>
<dd class="copyright">© 2010 Günter Milde</dd>
<dt>Licence</dt>
<dd><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&nbsp;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] == &quot;-h&quot; or arg[1] == &quot;--help&quot; then
    print(usage)
    return
end
</pre>
<p>Get input string:</p>
<pre class="literal-block">local s

if arg[1] == &quot;-f&quot; then
    local f = assert(io.open(arg[2], &quot;r&quot;))
    s = f:read(&quot;*all&quot;)
    f:close()
elseif arg[1] then
    s = table.concat(arg, &quot; &quot;) .. &quot;\n&quot;
else
    -- test:
    -- s = &quot;\\emph{x\\'us}&quot;
    s = io.read(&quot;*all&quot;)
end
</pre>
<p>The mapping from the LGR Latin transcription to LICR macros:</p>
<pre class="literal-block">LGR_map = {
  A = &quot;\\textAlpha{}&quot;,
  B = &quot;\\textBeta{}&quot;,
  G = &quot;\\textGamma{}&quot;,
  D = &quot;\\textDelta{}&quot;,
  E = &quot;\\textEpsilon{}&quot;,
  Z = &quot;\\textZeta{}&quot;,
  H = &quot;\\textEta{}&quot;,
  J = &quot;\\textTheta{}&quot;,
  I = &quot;\\textIota{}&quot;,
  K = &quot;\\textKappa{}&quot;,
  L = &quot;\\textLambda{}&quot;,
  M = &quot;\\textMu{}&quot;,
  N = &quot;\\textNu{}&quot;,
  X = &quot;\\textXi{}&quot;,
  O = &quot;\\textOmicron{}&quot;,
  P = &quot;\\textPi{}&quot;,
  R = &quot;\\textRho{}&quot;,
  S = &quot;\\textSigma{}&quot;,
  T = &quot;\\textTau{}&quot;,
  U = &quot;\\textUpsilon{}&quot;,
  F = &quot;\\textPhi{}&quot;,
  Q = &quot;\\textChi{}&quot;,
  Y = &quot;\\textPsi{}&quot;,
  W = &quot;\\textOmega{}&quot;,

  a = &quot;\\textalpha{}&quot;,
  b = &quot;\\textbeta{}&quot;,
  g = &quot;\\textgamma{}&quot;,
  d = &quot;\\textdelta{}&quot;,
  e = &quot;\\textepsilon{}&quot;,
  z = &quot;\\textzeta{}&quot;,
  h = &quot;\\texteta{}&quot;,
  j = &quot;\\texttheta{}&quot;,
  i = &quot;\\textiota{}&quot;,
  k = &quot;\\textkappa{}&quot;,
  l = &quot;\\textlambda{}&quot;,
  m = &quot;\\textmu{}&quot;,
  n = &quot;\\textnu{}&quot;,
  x = &quot;\\textxi{}&quot;,
  o = &quot;\\textomicron{}&quot;,
  p = &quot;\\textpi{}&quot;,
  r = &quot;\\textrho{}&quot;,
  s = &quot;\\textautosigma{}&quot;,
  c = &quot;\\textfinalsigma{}&quot;,
  t = &quot;\\texttau{}&quot;,
  u = &quot;\\textupsilon{}&quot;,
  f = &quot;\\textphi{}&quot;,
  q = &quot;\\textchi{}&quot;,
  y = &quot;\\textpsi{}&quot;,
  w = &quot;\\textomega{}&quot;,
  v = &quot;\\noboundary{}&quot;,

  [&quot;'&quot;] = &quot;\\'&quot;,
  [&quot;`&quot;] = &quot;\\`&quot;,
  [&quot;~&quot;] = &quot;\\~&quot;,
  [&quot;&lt;&quot;] = &quot;\\&lt;&quot;,
  [&quot;&gt;&quot;] = &quot;\\&gt;&quot;,
  [&quot;|&quot;] = &quot;\\|&quot;,
  ['&quot;'] = '\\&quot;',
  [&quot;;&quot;] = &quot;\\textanoteleia{}&quot;,
  [&quot;?&quot;] = &quot;\\texterotimatiko{}&quot;,
}
</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 == &quot;\\&quot; then
        if c2 and (c2 ~= &quot;&quot;) then
            return c1 .. c2 .. (LGR_map[c3] or c3 or &quot;&quot;)
        end
        return c1 .. c3
    end
    c2 = string.gsub(c2, &quot;s(.)&quot;, &quot;sv%1&quot;)
    return (string.gsub(c2, &quot;.&quot;, LGR_map) or &quot;&quot;) .. (LGR_map[c3] or c3 or &quot;&quot;)
end

-- Use the mapping to replace every ASCII-character with
-- non-standard meaning to the corresponding LICR macro
-- (skip macros)::
  -- *([a-zA-Z'`~&lt;&gt;|\&quot;;?]
s = string.gsub(s, &quot;(\\?)([a-zA-Z]*)([^\\]?)&quot;, lgr_replace)
</pre>
<p>Ligatures:</p>
<pre class="literal-block">s = string.gsub(s, &quot;%(%(&quot;, &quot;\\guillemotleft{}&quot;)
s = string.gsub(s, &quot;%)%)&quot;, &quot;\\guillemotright{}&quot;)
s = string.gsub(s, &quot;\\'\\'&quot;, &quot;\\textquoteright{}&quot;)               -- ''
s = string.gsub(s, &quot;\\`\\`&quot;, &quot;\\textquoteleft{}&quot;)                -- ``
s = string.gsub(s, '\&quot;(%s)', &quot;\\textquoteright{}%1&quot;)
</pre>
<p>Separating empty group “{}” only required if followed by space or ASCII:</p>
<pre class="literal-block">s = string.gsub(s, &quot;{}([^ a-zA-Z])&quot;, &quot;%1&quot;)
</pre>
<p>Autosigma replacements:</p>
<pre class="literal-block">s = string.gsub(s, &quot;\\textautosigma\\noboundary&quot;, &quot;\\textsigma&quot;)  -- sv
s = string.gsub(s, &quot;\\textautosigma(\\['`~&lt;&gt;|\&quot;])&quot;, &quot;\\textsigma%1&quot;) -- accents

s = string.gsub(s, &quot;\\textautosigma([-%s!#$%%&amp;%(%)*+,./0-9:=%[%]{|}])&quot;,
                   &quot;\\textfinalsigma%1&quot;)

s = string.gsub(s, &quot;\\textautosigma(\\textquote)&quot;, &quot;\\textfinalsigma%1&quot;)
s = string.gsub(s, &quot;\\textautosigma(\\texterotimatiko)&quot;, &quot;\\textfinalsigma%1&quot;)
s = string.gsub(s, &quot;\\textautosigma(\\textanoteleia)&quot;, &quot;\\textfinalsigma%1&quot;)

s = string.gsub(s, &quot;\\textautosigma$&quot;, &quot;\\textfinalsigma&quot;)
</pre>
<p>Write the result to stdout:</p>
<pre class="literal-block">io.write(s)
</pre>
</div>
</body>
</html>