summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/greek-fontenc/lgr2licr.lua.html
blob: 7762506cab875c44d0982bb9bca956eb92c0a02a (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
<?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
- - -*- coding: utf-8 -*- -->
<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.
  Without argument, the script reads from standard input, e.g., a
  redirected file or interactive input ended with Ctrl-D.
Options: -h, --help      show this help
]]

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">if ... then
    s = string.gsub(..., &quot;\t&quot;, &quot; &quot;)
else
    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;,
  K = &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>Replace the “autosigma” (s) with “sigma” (sv) if followed by another
character and with “finalsigma” (c) if followed by space or punctuation:</p>
<pre class="literal-block">s = string.gsub(s, &quot;s([a-z'`~&lt;&gt;])&quot;, &quot;sv%1&quot;)
s = string.gsub(s, &quot;s([ ,.:;?!])&quot;, &quot;c%1&quot;)
s = string.gsub(s, 's&quot;(%s)', 'c&quot;%1')  -- &quot; before whitespace is quote/apostrophe
</pre>
<p>Use the mapping to replace every ASCII-character with
non-standard meaning to the corresponding LICR macro:</p>
<pre class="literal-block">s = string.gsub(s, &quot;([a-zA-Z'`~&lt;&gt;|\&quot;;?])&quot;, LGR_map)
</pre>
<p>Some cleanup operations:</p>
<pre class="literal-block">s = string.gsub(s, &quot;\\'\\'&quot;, &quot;\\textquoteright{}&quot;)               -- ''
s = string.gsub(s, &quot;\\`\\`&quot;, &quot;\\textquoteleft{}&quot;)                -- ``
s = string.gsub(s, &quot;\\textautosigma{}\\noboundary{}&quot;, &quot;\\textsigma{}&quot;) -- sv
s = string.gsub(s, &quot;{}\\&quot;, &quot;\\&quot;)
</pre>
<p>The quotation mark (“) denotes a quote/apostrophe if followed by a space:</p>
<pre class="literal-block">s = string.gsub(s, '\&quot;(%s)', &quot;\\textquoteright{}%1&quot;)
</pre>
<p>Write the result to stdout:</p>
<pre class="literal-block">io.write(s)
</pre>
</div>
</body>
</html>