summaryrefslogtreecommitdiff
path: root/tex/context/base/char-tex.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2010-02-21 19:21:00 +0100
committerHans Hagen <pragma@wxs.nl>2010-02-21 19:21:00 +0100
commit8b61273b8c492e094d65764f3151d779d2f7c6cc (patch)
tree430c0b68fbfb99c63226108911a506e4fa43905a /tex/context/base/char-tex.lua
parentd0e4f28e750d875abc052acb4429e78743693a2c (diff)
downloadcontext-8b61273b8c492e094d65764f3151d779d2f7c6cc.tar.gz
beta 2010.02.21 19:21
Diffstat (limited to 'tex/context/base/char-tex.lua')
-rw-r--r--tex/context/base/char-tex.lua75
1 files changed, 75 insertions, 0 deletions
diff --git a/tex/context/base/char-tex.lua b/tex/context/base/char-tex.lua
new file mode 100644
index 000000000..f3af91f79
--- /dev/null
+++ b/tex/context/base/char-tex.lua
@@ -0,0 +1,75 @@
+if not modules then modules = { } end modules ['char-tex'] = {
+ version = 1.001,
+ comment = "companion to char-ini.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+characters = characters or { }
+characters.tex = characters.tex or { }
+
+local find = string.find
+
+local accent_map = {
+ ['~'] = "̃" , -- ̃ Ẽ
+ ['"'] = "̈" , -- ̈ Ë
+ ["`"] = "̀" , -- ̀ È
+ ["'"] = "́" , -- ́ É
+ ["^"] = "̂" , -- ̂ Ê
+ -- ̄ Ē
+ -- ̆ Ĕ
+ -- ̇ Ė
+ -- ̉ Ẻ
+ -- ̌ Ě
+ -- ̏ Ȅ
+ -- ̑ Ȇ
+ -- ̣ Ẹ
+ -- ̧ Ȩ
+ -- ̨ Ę
+ -- ̭ Ḙ
+ -- ̰ Ḛ
+}
+
+local accents = table.concat(table.keys(accent_map))
+
+local function remap_accents(a,c,braced)
+ local m = accent_map[a]
+ if m then
+ return c .. m
+ elseif braced then
+ return "\\" .. a .. "{" .. c .. "}"
+ else
+ return "\\" .. a .. c
+ end
+end
+
+local command_map = {
+ ["i"] = "ı"
+}
+
+local function remap_commands(c)
+ local m = command_map[c]
+ if m then
+ return m
+ else
+ return "\\" .. c
+ end
+end
+
+local P, C, R, S, Cs, Cc = lpeg.P, lpeg.C, lpeg.R, lpeg.S, lpeg.Cs, lpeg.Cc
+local U, lpegmatch = lpeg.utf8, lpeg.match
+
+local accents = (P('\\') * C(S(accents)) * (P("{") * C(U) * P("}" * Cc(true)) + C(U) * Cc(false))) / remap_accents
+local commands = (P('\\') * C(R("az","AZ")^1)) / remap_commands
+
+local convert_accents = Cs((accents + P(1))^0)
+local convert_commands = Cs((commands + P(1))^0)
+
+function characters.tex.toutf(str)
+ if find(str,"\\") then
+ str = lpegmatch(convert_commands,str)
+ str = lpegmatch(convert_accents,str)
+ end
+ return str
+end