![映射的组成?| 将 (罗马) Velthuis 编码转换为 IAST 音译](https://linux22.com/image/456809/%E6%98%A0%E5%B0%84%E7%9A%84%E7%BB%84%E6%88%90%EF%BC%9F%7C%20%E5%B0%86%20(%E7%BD%97%E9%A9%AC)%20Velthuis%20%E7%BC%96%E7%A0%81%E8%BD%AC%E6%8D%A2%E4%B8%BA%20IAST%20%E9%9F%B3%E8%AF%91.png)
我的问题是十年前提出的这个问题的后续:梵语音译。
我想将罗马文本(Velthuis 编码)转换为
- 梵文文本(天城体文字),以及
- IAST音译。
veltuis-sanskrit
我使用包提供的映射实现了罗马字母到天城文的转换devanagari
。
关于第二部分(罗马字母到 IAST 字母的转写),曾有人尝试从天城文文本中获取 IAST 字母的转写:逆向文本映射(天城文到 IAST 音译). 如何实现从罗马文字到英文的转换?
本质上我想实现两个地图的复合
velthuis-sanskrit
(罗马字转天城文)deva-to-iast
假如这里(天城文转 IAST)
有没有一种方法可以简单地通过组合两个地图(例如使用teckit
)并生成一个新地图来实现这一点?
平均能量损失
我想要实现的目标被锁定在标有感叹号的第四行中。
我想定义\romiastfont
使得最后两行给出相同的输出。
velthuis-sanskrit
是否可以将这两个映射(和)组合成一个新的映射deva-to-iast
,然后\romiastfont
根据新映射进行定义?可以使用 来完成吗teckit
?
% !TeX program = xelatex
\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguage{sanskrit}
\newfontfamily{\devanagarifont}{Gargi}[
Script=Devanagari,
Path=/usr/share/fonts/truetype/Gargi/,
UprightFont=Gargi,
Extension=.ttf,
%Mapping=velthuis-sanskrit
]
\newfontfamily{\romdevfont}{Gargi}[
Script=Devanagari,
Path=/usr/share/fonts/truetype/Gargi/,
UprightFont=Gargi,
Extension=.ttf,
Mapping=velthuis-sanskrit
]
\newfontfamily{\iastfont}{times}[
Path=/usr/share/fonts/truetype/msttcorefonts/,
UprightFont=times,
BoldFont=timesbd,
Extension=.ttf,
Mapping=deva-to-iast % deva-to-iast.tec obtained from here (and compiled): https://gist.github.com/hrishikeshrt/c35e1a5332a4fbcdcdf7102446d2e796
]
\catcode`\~=12
\begin{document}
\noindent\textsanskrit{रामो राजमणि सदा विजयते रामं रमेशं भजे}\\ % direct sanskrit
\romdevfont{raamo raajama.ni sadaa vijayate raama.m rame"sa.m bhaje}\\ % roman to sanskrit
\iastfont{रामो राजमणि सदा विजयते रामं रमेशं भजे}\\ % sanskrit to IAST
\newcommand{\romiastfont}[1]{\iastfont{\romdevfont{#1}}} % <-- !!! roman to IAST; doesn't work; what should this be?
\romiastfont{raamo raajama.ni sadaa vijayate raama.m rame"sa.m bhaje} % expect this to be same as previous line
\end{document}
答案1
我认为您可以相当轻松地编写地图文件,这足以完成给出的示例(我必须更改字体)请注意,问题中声明的字体命令不接受参数。
\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguage{sanskrit}
\newfontfamily{\devanagarifont}{Noto Sans Devanagari}[
Script=Devanagari,
%Mapping=velthuis-sanskrit
]
\newfontfamily{\romdevfont}{Noto Sans Devanagari}[
Script=Devanagari,
Mapping=velthuis-sanskrit
]
\newfontfamily{\iastfont}{Times New Roman}[
Mapping=deva-to-iast % deva-to-iast.tec obtained from here (and compiled): https://gist.github.com/hrishikeshrt/c35e1a5332a4fbcdcdf7102446d2e796
]
\newfontfamily{\romiastfont}{Times New Roman}[
Mapping=deva2 %
]
\catcode`\~=12
\begin{document}
\textsanskrit{रामो राजमणि सदा विजयते रामं रमेशं भजे}% direct sanskrit
{\romdevfont raamo raajama.ni sadaa vijayate raama.m rame"sa.m bhaje}% \romdevfont does not have {} % roman to sanskrit
{\iastfont रामो राजमणि सदा विजयते रामं रमेशं भजे} % sanskrit to IAST \iast font does not have {}
{\romiastfont raamo raajama.ni sadaa vijayate raama.m rame"sa.m bhaje} % expect this to be same as previous line
\end{document}
使用已编译的deva2.map
文件
LHSName "deva2"
pass(Unicode)
U+0061 U+0061 <>U+0101; aa
U+002E U+006E <>U+1E47; .n
U+002E U+006D <>U+1E43; .m
U+0022 U+0073 <>U+015B; "s
答案2
根据@David Carlisle 的建议,我尝试创建一张将 Velthuis 编码转换为 IAST 音译的地图。
https://gist.github.com/vachan-potluri/6c26a7963bf8323b8709f2d3136ef8ec
; Velthuis encoding to IAST transliteration
; motivated by velthuis-sanskrit.map from xetex-devanagari and deva-to-iast.map from
; https://tex.stackexchange.com/questions/502515/reversing-text-mapping-devanagari-to-iast-transliteration?noredirect=1&lq=1
; Also see
; https://en.wikipedia.org/wiki/Velthuis#Transliteration_scheme, and
; https://en.wikipedia.org/wiki/Devanagari_transliteration#Transliteration_comparison
LHSName "Velthuis-Sanskrit-IAST"
RHSName "UNICODE"
LHSDescription "Velthuis Devanagari for IAST Sanskrit transliteration"
Version "1"
Define a U+0061 ;a
Define d U+0064 ;d
Define h U+0068 ;h
Define i U+0069 ;i
Define l U+006C ;l
Define m U+006D ;m
Define n U+006E ;n
Define r U+0072 ;r
Define o U+006F ;o
Define s U+0073 ;s
Define t U+0074 ;t
Define u U+0075 ;u
Define quot U+0022
Define dot U+002E
Define tlde U+007E
Define Asvara U+0101
Define Isvara U+012B
Define Usvara U+016B
Define rvoc U+1E5B
Define Rvoc U+1E5D
Define lvoc U+1E37
Define Lvoc U+1E39
Define bindu U+1E43
Define visarga U+1E25
Define avagraha U+0027
pass(Unicode)
a a <> Asvara
i i <> Isvara
u u <> Usvara
dot r <> rvoc
dot r r <> Rvoc
dot l <> lvoc
dot l l <> Lvoc
dot m <> bindu
dot h <> visarga
dot a <> avagraha
quot n <> U+1E45; ṅ
tlde n <> U+00F1; ñ
dot t <> U+1E6D; ṭ
dot d <> U+1E0D; ḍ
dot n <> U+1E47; ṇ
quot s <> U+015B; ś
dot s <> U+1E63; ṣ
dot o <> o U+1E43; oṃ
我还没有彻底测试过。如果有人能测试并提供评论/改进,那就太好了。它目前适用于问题中发布的 MWE。
答案3
使用 expl3 进行映射,并使用 lualatex 进行编译。
.map
使用此方法不需要用 TECkit编译文件。
使用 expl3 将正则表达式带入实现映射的 LaTeX,允许使用参考查找表(存储为 expl3 序列(=set))作为映射存储库,进而允许在开放式映射方案集之间进行多对多连接,所有这些都在用户的控制之下。
记录示例
平均能量损失
\documentclass{article}
\usepackage{xcolor}
\usepackage{fontspec}
\newfontscript{Devanagari}{dev2,deva}
\newfontfamily\fdevb[Script=Devanagari,Renderer=HarfBuzz]{Shobhika}
\newfontfamily\fipa{Noto Serif}
\usepackage{multicol}
\ExplSyntaxOn
\cs_generate_variant:Nn
\seq_gset_split:Nnn
{ cno }
\cs_generate_variant:Nn
\seq_set_split:Nnn
{ cnx }
\cs_generate_variant:Nn
\tl_count_tokens:n
{ V }
\cs_generate_variant:Nn
\tl_replace_all:Nnn
{ Nxx }
\tl_new:N \g_fctr_ns_tl %
\seq_new:N
\l_ic_mfsq_seq
\seq_new:N
\l_ic_mfsqz_seq
\seq_new:N
\l_ic_mfsqy_seq
\tl_new:N
\l_ic_mfsqz_tl
\seq_new:N
\l_ic_mfsqyy_seq
\int_new:N
\l_ic_mfsqz_int
\int_new:N
\l_ic_mfsqy_int
\seq_new:N \l_trtmpa_seq
\tl_new:N \l_mytr_tl
%---12
\cs_set:Nn \ic_vowelsxasciidevapost: {
\regex_replace_all:nnN
{ a }
{ }
\l_mytr_tl
}
%---21
\cs_set:Nn \ic_vowelsdevaxasciipre: {
\regex_replace_all:nnN
{ ([क-ह]) }
{
\1
X
}
\l_mytr_tl
}
%---21
\cs_set:Nn \ic_vowelsdevaxasciipost: {
% no end vowel
\regex_replace_all:nnN
{ (X)(\s) }
{
\2
}
\l_mytr_tl
% halant
\regex_replace_all:nnN
{ (X\c{&}) }
{
}
\l_mytr_tl
% before non-inherent vowel
\regex_replace_all:nnN
{ (X)([aeiou\,\|]) }
{
\2
}
\l_mytr_tl
% is inherent vowel
\regex_replace_all:nnN
{ (X) }
{
a
}
\l_mytr_tl
}
%---72
\cs_set:Nn \ic_vowelsveltdevapre: {
\regex_replace_all:nnN
{ (\S)(aa) }
{ \1 a \c{Uchar} 2366 \c{tex_relax:D} }
\l_mytr_tl
\regex_replace_all:nnN
{ (\S)(e) }
{ \1 a \c{Uchar} 2375 \c{tex_relax:D} }
\l_mytr_tl
\regex_replace_all:nnN
{ (\S)(i) }
{ \1 a \c{Uchar} 2367 \c{tex_relax:D} }
\l_mytr_tl
\regex_replace_all:nnN
{ (\S)(o) }
{ \1 a \c{Uchar} 2379 \c{tex_relax:D} }
\l_mytr_tl
}
%---78
\cs_set:Nn \ic_vowelsveltiastmid: {
\regex_replace_all:nnN
{ ([蝟-螃])([^蝐-蝞螈-螫]) }
{ \1 a }
\l_mytranslitph_tl
}
%---78im
\cs_set:Nn \ic_vowelsveltiastmidim: {
% no mid-processing required for 78im fibre
}
%---28
\cs_set:Nn \ic_vowelsdevaiastpost: {
\regex_replace_all:nnN
{ ([hlmnrtv]{1})(/) }
{ \1 x\2 }
\l_mytr_tl
\regex_replace_all:nnN
{ ([hlmnrtv]{1})([^(ā|i|/{3})]{1}) }
{ \1 a }
\l_mytr_tl
% ([^t]+|(t([^e]|$)|te([^s]|$)|tes([^t]|$)))+
%^((?!hede).)*$
}
%---
\cs_set:Npn \ic_listseq:n #1 { % 1=pair (in record)
%----- store the record
\seq_set_split:cnx
{ l_trtmpa_seq }
{; } % separator
{ #1 }
\noindent
\group_begin:
\l_trns_formata_tl
\seq_item:Nn
\l_trtmpa_seq
{ \l_trns_fielda_tl }
\group_end:
\group_begin:
\tl_use:c { l_trns_formatmap_tl }
\group_end:
\group_begin:
\l_trns_formatb_tl
\seq_item:Nn
\l_trtmpa_seq
{ \l_trns_fieldb_tl }
\group_end:
\group_begin:
% postnote
\tl_if_empty:cF
{ l_trns_fieldc_tl }
{
\tex_space:D
(
\l_trns_formatc_tl
\seq_item:Nn
\l_trtmpa_seq
{ \l_trns_fieldc_tl }
)
}
\group_end:
\tex_par:D
}
\tl_new:N \l_mytranslookup_tl
%---
\cs_set:Npn \ic_ttseq:n #1 { % 1=pair
%----- store the record
\seq_set_split:cnx
{ l_trtmpa_seq }
{; } % separator
{ #1 }
\tl_set:Nx
\l_mytranslookup_tl
{
\seq_item:Nn
\l_trtmpa_seq
{ \l_trns_fielda_tl } % field number in record (first of pair)
}
\tl_if_empty:NF
\l_mytranslookup_tl
{
% if there is somthing to look up:
\tl_replace_all:Nxx
\l_mytr_tl
{
\seq_item:Nn
\l_trtmpa_seq
{ \l_trns_fielda_tl } % field number in record (first of pair)
}
{
\seq_item:Nn
\l_trtmpa_seq
{ \l_trns_fieldb_tl }% field number in record (second of pair)
}
} % end lookup
}
\tl_new:N \l_mytranslitph_tl
%Two-step: all-from to unique
%---
\cs_set:Npn \ic_ttseqa:n #1 { % 1=pair
%----- store the record
\seq_set_split:cnx
{ l_trtmpa_seq }
{; } % separator
{ #1 }
\tl_set:Nx
\l_mytranslookup_tl
{
\seq_item:Nn
\l_trtmpa_seq
{ \l_trns_fielda_tl } % field number in record (first of pair)
}
\tl_if_empty:NF
\l_mytranslookup_tl
{
% if there is somthing to look up:
\int_set:Nn
\l_tmpa_int
{
34633 +
\seq_item:Nn
\l_trtmpa_seq
{ \l_trns_placeholder_tl }
}
\tl_replace_all:Nxx
\l_mytr_tl
{
\seq_item:Nn
\l_trtmpa_seq
{ \l_trns_fielda_tl } % field number in record (first of pair)
}
{
\Uchar \l_tmpa_int
}
} % end lookup
}
%Two-step: unique to all-to
%---
\cs_set:Npn \ic_ttseqb:n #1 { % 1=pair
%----- store the record
\seq_set_split:cnx
{ l_trtmpa_seq }
{; } % separator
{ #1 }
\int_set:Nn
\l_tmpa_int
{
34633 +
\seq_item:Nn
\l_trtmpa_seq
{ \l_trns_placeholder_tl }
}
\tl_replace_all:Nxx
\l_mytranslitph_tl
{
\Uchar \l_tmpa_int
}
{
\seq_item:Nn
\l_trtmpa_seq
{ \l_trns_fieldb_tl }% field number in record (second of pair)
}
}
%intermediate
\tl_new:N \l_mytranslitim_tl
%Two-step: all-from to im
%---
\cs_set:Npn \ic_ttseqima:n #1 { % 1=pair
%----- store the record
\seq_set_split:cnx
{ l_trtmpa_seq }
{; } % separator
{ #1 }
\tl_set:Nx
\l_mytranslookup_tl
{
\seq_item:Nn
\l_trtmpa_seq
{ \l_trns_fielda_tl } % field number in record (first of pair)
}
\tl_if_empty:NF
\l_mytranslookup_tl
{
% if there is somthing to look up:
\tl_replace_all:Nxx
\l_mytr_tl
{
\seq_item:Nn
\l_trtmpa_seq
{ \l_trns_fielda_tl } % field number in record (first of pair)
}
{
\seq_item:Nn
\l_trtmpa_seq
{ \l_trns_intermediate_tl }
}
} % end lookup
}
%Two-step: im to all-to
%---
\cs_set:Npn \ic_ttseqimb:n #1 { % 1=pair
%----- store the record
\seq_set_split:cnx
{ l_trtmpa_seq }
{; } % separator
{ #1 }
\tl_replace_all:Nxx
\l_mytranslitim_tl
{
\seq_item:Nn
\l_trtmpa_seq
{ \l_trns_intermediate_tl }
}
{
\seq_item:Nn
\l_trtmpa_seq
{ \l_trns_fieldb_tl }% field number in record (second of pair)
}
}
%---
\cs_set:Npn \ic_sortseq:cnn #1#2#3 {
% 1=seq,
% 2=order (<:descending, >:ascending)
% 3=sort field
\seq_sort:cn { #1 } %\l_ic_mfsq_seq
{
\seq_clear:N
\l_ic_mfsqz_seq
\seq_clear:N
\l_ic_mfsqy_seq
\seq_set_split:Nnn
\l_ic_mfsqz_seq
{; }
{ ##1 }
\seq_set_split:Nnn
\l_ic_mfsqy_seq
{; }
{ ##2 }
\tl_set:Nx
\l_ic_mfsqz_tl
{
\seq_item:Nn
\l_ic_mfsqz_seq
{ #3 } % sort field
}
\tl_set:Nx
\l_ic_mfsqy_tl
{
\seq_item:Nn
\l_ic_mfsqy_seq
{ #3 } % sort field
}
\int_set:Nn
\l_ic_mfsqz_int
{
\tl_count_tokens:V
\l_ic_mfsqz_tl
}
\int_set:Nn
\l_ic_mfsqy_int
{
\tl_count_tokens:V
\l_ic_mfsqy_tl
}
\int_compare:nNnTF
{ \l_ic_mfsqz_int } { #2 } { \l_ic_mfsqy_int }
{ \sort_return_swapped: }
{ \sort_return_same: }
}
}
%---
\cs_set:Npn \ic_sortseqnum:cnn #1#2#3 {
% 1=seq,
% 2=order (<:descending, >:ascending)
% 3=sort field
\seq_sort:cn { #1 } %\l_ic_mfsq_seq
{
\seq_clear:N
\l_ic_mfsqz_seq
\seq_clear:N
\l_ic_mfsqy_seq
\seq_set_split:Nnn
\l_ic_mfsqz_seq
{; }
{ ##1 }
\seq_set_split:Nnn
\l_ic_mfsqy_seq
{; }
{ ##2 }
\tl_set:Nx
\l_ic_mfsqz_tl
{
\seq_item:Nn
\l_ic_mfsqz_seq
{ #3 } % sort field
}
\tl_set:Nx
\l_ic_mfsqy_tl
{
\seq_item:Nn
\l_ic_mfsqy_seq
{ #3 } % sort field
}
\int_set:Nn
\l_ic_mfsqz_int
{
% \tl_count_tokens:V
\l_ic_mfsqz_tl
}
\int_set:Nn
\l_ic_mfsqy_int
{
% \tl_count_tokens:V
\l_ic_mfsqy_tl
}
\int_compare:nNnTF
{ \l_ic_mfsqz_int } { #2 } { \l_ic_mfsqy_int }
{ \sort_return_swapped: }
{ \sort_return_same: }
}
}
%-----
\NewDocumentCommand { \mfstrloadaseq } { o m +m } {
% 1=namespace
% 2=seq name
% 3=data
\IfNoValueTF { #1 }
{ \tl_clear:N \g_fctr_ns_tl }
{ \tl_gset:Nn \g_fctr_ns_tl { #1 } }
\cs_if_free:cT
{ g_fc_rwe \g_fctr_ns_tl #2 _seq }
{ \seq_new:c
{ g_fc_rwe \g_fctr_ns_tl #2 _seq }
}
\seq_gclear:c
{ g_fc_rwe \g_fctr_ns_tl #2 _seq }
\seq_gset_split:cno
{ g_fc_rwe \g_fctr_ns_tl #2 _seq }
{ , }
{ #3 }
}
%-----
\NewDocumentCommand { \mfssortaseq } { o m m m } {
%1=namespace
%2=seqname,
%3=><, asc/desc
%4=sort field
\IfNoValueTF { #1 }
{ \tl_clear:N \g_fctr_ns_tl }
{ \tl_gset:Nn \g_fctr_ns_tl { #1 } }
\ic_sortseq:cnn
{ g_fc_rwe \g_fctr_ns_tl #2 _seq }
{ #3 } %desc/asc
{ #4 } %sort field
}
%-----
\NewDocumentCommand { \mfssortaseqnum } { o m m m } {
%1=namespace
%2=seqname,
%3=><, asc/desc
%4=sort field
\IfNoValueTF { #1 }
{ \tl_clear:N \g_fctr_ns_tl }
{ \tl_gset:Nn \g_fctr_ns_tl { #1 } }
\ic_sortseqnum:cnn
{ g_fc_rwe \g_fctr_ns_tl #2 _seq }
{ #3 } %desc/asc
{ #4 } %sort field
}
%---
\keys_define:nn { trnsllist }
{
fielda .tl_set:c = { l_trns_fielda_tl },
fielda .initial:n = { 1 },
fielda .default:n = { 1 },
fieldb .tl_set:c = { l_trns_fieldb_tl },
fieldb .initial:n = { 2 },
fieldb .default:n = { 2 },
formata .tl_set:c = { l_trns_formata_tl },
formata .initial:n = { },
formata .default:n = { },
formatb .tl_set:c = { l_trns_formatb_tl },
formatb .initial:n = { },
formatb .default:n = { },
formatmap .tl_set:c = { l_trns_formatmap_tl },
formatmap .initial:n = { \tex_space:D $\mapsto$ \tex_space:D },
formatmap .default:n = { \tex_space:D $\mapsto$ \tex_space:D },
placeholder .tl_set:c = { l_trns_placeholder_tl },
placeholder .initial:n = { },
placeholder .default:n = { },
fieldc .tl_set:c = { l_trns_fieldc_tl },
fieldc .initial:n = { },
fieldc .default:n = { },
formatc .tl_set:c = { l_trns_formatc_tl },
formatc .initial:n = { },
formatc .default:n = { },
showoriginal .bool_set:c = { l_trns_showoriginal_bool },
showoriginal .initial:n = {false},
showoriginal .default:n = {false},
intermediate .tl_set:c = { l_trns_intermediate_tl }, %bridge B: A>B>C
intermediate .initial:n = { },
intermediate .default:n = { },
}
%-----
\NewDocumentCommand { \mfslistaseq } { o m O{} } {
%1=namespace
%2=seqname
%3=keys
\IfNoValueF{#3}
{
\keys_set:nn { trnsllist } { #3 }
}
\IfNoValueTF { #1 }
{ \tl_clear:N \g_fctr_ns_tl }
{ \tl_gset:Nn \g_fctr_ns_tl { #1 } }
\seq_map_function:cN
{ g_fc_rwe \g_fctr_ns_tl #2 _seq }
\ic_listseq:n
}
\tl_new:N \l_mytranslitorig_tl
\regex_const:Nn \c_consonantaa_regex { ([rm]{1})(aa) }
\tl_new:N \l_trns_fieldxascii_tl
\tl_new:N \l_trns_fielddeva_tl
\tl_new:N \l_trns_fieldvelt_tl
\tl_new:N \l_trns_fieldiast_tl
\tl_set:Nn \l_trns_fieldxascii_tl {1}
\tl_set:Nn \l_trns_fielddeva_tl {2}
\tl_set:Nn \l_trns_fieldvelt_tl {7}
\tl_set:Nn \l_trns_fieldiast_tl {8}
%-----
\NewDocumentCommand { \translitx } { o m O{} +m } {
%1=namespace
%2=seqname
%3=keys
%4=data
\tl_set:Nx \l_mytr_tl { #4 }
\IfNoValueF{#3}
{
\keys_set:nn { trnsllist } { #3 }
}
\bool_if:NT
\l_trns_showoriginal_bool % key
{
\tl_set_eq:NN
\l_mytranslitorig_tl
\l_mytr_tl
}
\IfNoValueTF { #1 }
{ \tl_clear:N \g_fctr_ns_tl }
{ \tl_gset:Nn \g_fctr_ns_tl { #1 } }
% pre-process vowels
%\ic_vowels2:
\tl_case:Nn \l_trns_fielda_tl
{
% % 2 ---
\l_trns_fielddeva_tl {
\tl_case:Nn \l_trns_fieldb_tl
{
\l_trns_fieldxascii_tl { \ic_vowelsdevaxasciipre: }
}
}
% 7 ---
\l_trns_fieldvelt_tl {
\tl_case:Nn \l_trns_fieldb_tl
{
\l_trns_fielddeva_tl { \ic_vowelsveltdevapre: }
}
}
}
% -----
\tl_if_empty:cTF
{ l_trns_placeholder_tl } % 34633
{
\tl_if_empty:cTF
{ l_trns_intermediate_tl }
{%not intermediate
%normal translit (A>B)
\seq_map_function:cN
{ g_fc_rwe \g_fctr_ns_tl #2 _seq }
\ic_ttseq:n
}
{%intermediate
%A>im
\seq_map_function:cN
{ g_fc_rwe \g_fctr_ns_tl #2 _seq }
\ic_ttseqima:n
\tl_set_eq:NN \l_mytranslitim_tl \l_mytr_tl
%---
% mid-process vowels (im)
\tl_case:Nn \l_trns_fielda_tl
{
% 7 ---
\l_trns_fieldvelt_tl {
\tl_case:Nn \l_trns_fieldb_tl
{
\l_trns_fieldiast_tl { \ic_vowelsveltiastmidim: }
}
}
}
%---
%im>B
\seq_map_function:cN
{ g_fc_rwe \g_fctr_ns_tl #2 _seq }
\ic_ttseqimb:n
\tl_set_eq:NN \l_mytr_tl \l_mytranslitim_tl
}
}
{
%A>unique:
\seq_map_function:cN
{ g_fc_rwe \g_fctr_ns_tl #2 _seq }
\ic_ttseqa:n
\tl_set_eq:NN \l_mytranslitph_tl \l_mytr_tl
% mid-process vowels
\tl_case:Nn \l_trns_fielda_tl
{
% 7 ---
\l_trns_fieldvelt_tl {
\tl_case:Nn \l_trns_fieldb_tl
{
\l_trns_fieldiast_tl { \ic_vowelsveltiastmid: }
}
}
}
%unique>B:
\seq_map_function:cN
{ g_fc_rwe \g_fctr_ns_tl #2 _seq }
\ic_ttseqb:n
\tl_set_eq:NN \l_mytr_tl \l_mytranslitph_tl
}
\bool_if:NT
\l_trns_showoriginal_bool
{
\group_begin:
\l_trns_formata_tl
\tl_use:N
\l_mytranslitorig_tl
\group_end:
{\usefont{T1}{lmr}{m}{it}\tex_space:D (original)}
\tex_par:D
}
% post-process vowels
\tl_case:Nn \l_trns_fielda_tl
{
% 1 --
\l_trns_fieldxascii_tl {
\tl_case:Nn \l_trns_fieldb_tl
{
\l_trns_fielddeva_tl { \ic_vowelsxasciidevapost: }
}
}
% 2 ---
\l_trns_fielddeva_tl {
\tl_case:Nn \l_trns_fieldb_tl
{
\l_trns_fieldxascii_tl { \ic_vowelsdevaxasciipost: }
\l_trns_fieldiast_tl { \ic_vowelsdevaiastpost: }
}
}
}
{
\group_begin:
\l_trns_formatb_tl
\tl_use:N \l_mytr_tl
\group_end:
}
}
%-----
\NewDocumentCommand { \translit } { o m O{} +m } {
%1=namespace
%2=seqname
%3=keys
%4=data
\tl_set:Nx \l_mytr_tl { #4 }
\IfNoValueF{#3}
{
\keys_set:nn { trnsllist } { #3 }
}
\bool_if:NT
\l_trns_showoriginal_bool % key
{
\tl_set_eq:NN
\l_mytranslitorig_tl
\l_mytr_tl
}
\IfNoValueTF { #1 }
{ \tl_clear:N \g_fctr_ns_tl }
{ \tl_gset:Nn \g_fctr_ns_tl { #1 } }
% -----
\tl_if_empty:cTF
{ l_trns_placeholder_tl } % 34633
{
\seq_map_function:cN
{ g_fc_rwe \g_fctr_ns_tl #2 _seq }
\ic_ttseq:n
}
{
%A:
\seq_map_function:cN
{ g_fc_rwe \g_fctr_ns_tl #2 _seq }
\ic_ttseqa:n
\tl_set_eq:NN \l_mytranslitph_tl \l_mytr_tl
%B:
\seq_map_function:cN
{ g_fc_rwe \g_fctr_ns_tl #2 _seq }
\ic_ttseqb:n
\tl_set_eq:NN \l_mytr_tl \l_mytranslitph_tl
}
\bool_if:NT
\l_trns_showoriginal_bool
{
\group_begin:
\l_trns_formata_tl
\tl_use:N
\l_mytranslitorig_tl
\group_end:
{\usefont{T1}{lmr}{m}{it}\tex_space:D (original)}
\tex_par:D
}
{
\group_begin:
\l_trns_formatb_tl
\tl_use:N \l_mytr_tl
\group_end:
}
}
\ExplSyntaxOff
\newcommand\campersand{\&}
\begin{document}
%===
%1 = xascii
%2 = devanagari
%3 = Unicode name
%4 = record number
%5 = Unicode codepoint
%6 = placeholder (tempvar for 3-way)
%7 = Velthuis
%8 = IAST
\catcode `\~=12
\mfstrloadaseq[x]{devatranslit}{%
//;ऀ;U+0900 ऀ DEVANAGARI SIGN INVERTED CANDRABINDU;1;2304;x0001;;
,/;ँ;U+0901 ँ DEVANAGARI SIGN CANDRABINDU;2;2305;x0002;;˜
,.m;ं;U+0902 ं DEVANAGARI SIGN ANUSVARA;3;2306;x0003;.m;ṃ
,.h;ः;U+0903 ः DEVANAGARI SIGN VISARGA;4;2307;x0004;.h;ḥ
,a=;ऄ;U+0904 ऄ DEVANAGARI LETTER SHORT A;5;2308;x0005;;
,a-;अ;U+0905 अ DEVANAGARI LETTER A;6;2309;x0006;a;a
,aa-;आ;U+0906 आ DEVANAGARI LETTER AA;7;2310;x0007;aa;ā
,i-;इ;U+0907 इ DEVANAGARI LETTER I;8;2311;x0008;i;i
,ii-;ई;U+0908 ई DEVANAGARI LETTER II;9;2312;x0009;ii;ī
,u-;उ;U+0909 उ DEVANAGARI LETTER U;10;2313;x0010;u;u
,uu-;ऊ;U+090A ऊ DEVANAGARI LETTER UU;11;2314;x0011;uu;ū
,.r-;ऋ;U+090B ऋ DEVANAGARI LETTER VOCALIC R;12;2315;x0012;.r;ṛ
,.l-;ऌ;U+090C ऌ DEVANAGARI LETTER VOCALIC L;13;2316;x0013;.l;ḷ
,~e;ऍ;U+090D ऍ DEVANAGARI LETTER CANDRA E;14;2317;x0014;;
,e=;ऎ;U+090E ऎ DEVANAGARI LETTER SHORT E;15;2318;x0015;;
,e-;ए;U+090F ए DEVANAGARI LETTER E;16;2319;x0016;e;e
,ai-;ऐ;U+0910 ऐ DEVANAGARI LETTER AI;17;2320;x0017;ai;ai
,~o;ऑ;U+0911 ऑ DEVANAGARI LETTER CANDRA O;18;2321;x0018;;
,o=;ऒ;U+0912 ऒ DEVANAGARI LETTER SHORT O;19;2322;x0019;;
,o-;ओ;U+0913 ओ DEVANAGARI LETTER O;20;2323;x0020;o;o
,au-;औ;U+0914 औ DEVANAGARI LETTER AU;21;2324;x0021;au;au
,k;क;U+0915 क DEVANAGARI LETTER KA;22;2325;x0022;k;k
,kh;ख;U+0916 ख DEVANAGARI LETTER KHA;23;2326;x0023;kh;kh
,g;ग;U+0917 ग DEVANAGARI LETTER GA;24;2327;x0024;g;g
,gh;घ;U+0918 घ DEVANAGARI LETTER GHA;25;2328;x0025;gh;gh
,"n;ङ;U+0919 ङ DEVANAGARI LETTER NGA;26;2329;x0026;"n;ṅ
,c;च;U+091A च DEVANAGARI LETTER CA;27;2330;x0027;c;c
,ch;छ;U+091B छ DEVANAGARI LETTER CHA;28;2331;x0028;ch;ch
,j;ज;U+091C ज DEVANAGARI LETTER JA;29;2332;x0029;j;j
,jh;झ;U+091D झ DEVANAGARI LETTER JHA;30;2333;x0030;jh;jh
,~na;ञ;U+091E ञ DEVANAGARI LETTER NYA;31;2334;x0031;~n;ñ
,.t;ट;U+091F ट DEVANAGARI LETTER TTA;32;2335;x0032;.t;ṭ
,.th;ठ;U+0920 ठ DEVANAGARI LETTER TTHA;33;2336;x0033;.th;ṭh
,.d;ड;U+0921 ड DEVANAGARI LETTER DDA;34;2337;x0034;.d;ḍ
,.dh;ढ;U+0922 ढ DEVANAGARI LETTER DDHA;35;2338;x0035;.dh;ḍh
,.n;ण;U+0923 ण DEVANAGARI LETTER NNA;36;2339;x0036;.n;ṇ
,t;त;U+0924 त DEVANAGARI LETTER TA;37;2340;x0037;t;t
,th;थ;U+0925 थ DEVANAGARI LETTER THA;38;2341;x0038;th;th
,d;द;U+0926 द DEVANAGARI LETTER DA;39;2342;x0039;d;d
,dh;ध;U+0927 ध DEVANAGARI LETTER DHA;40;2343;x0040;dh;dh
,n;न;U+0928 न DEVANAGARI LETTER NA;41;2344;x0041;n;n
,.nna;ऩ;U+0929 ऩ DEVANAGARI LETTER NNNA;42;2345;x0042;;
,p;प;U+092A प DEVANAGARI LETTER PA;43;2346;x0043;p;p
,ph;फ;U+092B फ DEVANAGARI LETTER PHA;44;2347;x0044;ph;ph
,b;ब;U+092C ब DEVANAGARI LETTER BA;45;2348;x0045;b;b
,bh;भ;U+092D भ DEVANAGARI LETTER BHA;46;2349;x0046;bh;bh
,m;म;U+092E म DEVANAGARI LETTER MA;47;2350;x0047;m;m
,y;य;U+092F य DEVANAGARI LETTER YA;48;2351;x0048;y;y
,r;र;U+0930 र DEVANAGARI LETTER RA;49;2352;x0049;r;r
,rra;ऱ;U+0931 ऱ DEVANAGARI LETTER RRA;50;2353;x0050;;
,l;ल;U+0932 ल DEVANAGARI LETTER LA;51;2354;x0051;l;l
,.L;ळ;U+0933 ळ DEVANAGARI LETTER LLA;52;2355;x0052;;
,.LL;ऴ;U+0934 ऴ DEVANAGARI LETTER LLLA;53;2356;x0053;;
,v;व;U+0935 व DEVANAGARI LETTER VA;54;2357;x0054;v;v
,"s;श;U+0936 श DEVANAGARI LETTER SHA;55;2358;x0055;"s;ś
,.s;ष;U+0937 ष DEVANAGARI LETTER SSA;56;2359;x0056;.s;ṣ
,s;स;U+0938 स DEVANAGARI LETTER SA;57;2360;x0057;s;s
,h;ह;U+0939 ह DEVANAGARI LETTER HA;58;2361;x0058;h;h
,oe;ऺ;U+093A ऺ DEVANAGARI VOWEL SIGN OE;59;2362;x0059;;
,ooe;ऻ;U+093B ऻ DEVANAGARI VOWEL SIGN OOE;60;2363;x0060;;
,N;़;U+093C ़ DEVANAGARI SIGN NUKTA;61;2364;x0061;;
,.a;ऽ;U+093D ऽ DEVANAGARI SIGN AVAGRAHA;62;2365;x0062;;'
,aa;ा;U+093E ा DEVANAGARI VOWEL SIGN AA;63;2366;x0063;;ā
,i;ि;U+093F ि DEVANAGARI VOWEL SIGN I;64;2367;x0064;;i
,ii;ी;U+0940 ी DEVANAGARI VOWEL SIGN II;65;2368;x0065;;ī
,u;ु;U+0941 ु DEVANAGARI VOWEL SIGN U;66;2369;x0066;;u
,uu;ू;U+0942 ू DEVANAGARI VOWEL SIGN UU;67;2370;x0067;;ū
,.r;ृ;U+0943 ृ DEVANAGARI VOWEL SIGN VOCALIC R;68;2371;x0068;;
,.l;ॄ;U+0944 ॄ DEVANAGARI VOWEL SIGN VOCALIC RR;69;2372;x0069;;
,~e;ॅ;U+0945 ॅ DEVANAGARI VOWEL SIGN CANDRA E;70;2373;x0070;;
,e=;ॆ;U+0946 ॆ DEVANAGARI VOWEL SIGN SHORT E;71;2374;x0071;;
,e;े;U+0947 े DEVANAGARI VOWEL SIGN E;72;2375;x0072;;
,ai;ै;U+0948 ै DEVANAGARI VOWEL SIGN AI;73;2376;x0073;;
,~o;ॉ;U+0949 ॉ DEVANAGARI VOWEL SIGN CANDRA O;74;2377;x0074;;
,o=;ॊ;U+094A ॊ DEVANAGARI VOWEL SIGN SHORT O;75;2378;x0075;;
,o;ो;U+094B ो DEVANAGARI VOWEL SIGN O;76;2379;x0076;;
,au;ौ;U+094C ौ DEVANAGARI VOWEL SIGN AU;77;2380;x0077;;
,\&;्;U+094D ् DEVANAGARI SIGN VIRAMA;78;2381;x0078;;///
%
%
,.o;ॐ;U+0950 ॐ DEVANAGARI OM;81;2384;x0081;;
%
%
%
%
%
%
%
,q;क़;U+0958 क़ DEVANAGARI LETTER QA;89;2392;x0089;;
,.kh;ख़;U+0959 ख़ DEVANAGARI LETTER KHHA;90;2393;x0090;;
,.g;ग़;U+095A ग़ DEVANAGARI LETTER GHHA;91;2394;x0091;;
,z;ज़;U+095B ज़ DEVANAGARI LETTER ZA;92;2395;x0092;;
,R;ड़;U+095C ड़ DEVANAGARI LETTER DDDHA;93;2396;x0093;;
,Rh;ढ़;U+095D ढ़ DEVANAGARI LETTER RHA;94;2397;x0094;;
,f;फ़;U+095E फ़ DEVANAGARI LETTER FA;95;2398;x0095;;
,yy;य़;U+095F य़ DEVANAGARI LETTER YYA;96;2399;x0096;;
,.rr-;ॠ;U+0960 ॠ DEVANAGARI LETTER VOCALIC RR;97;2400;x0097;.rr;ṝ
,.ll-;ॡ;U+0961 ॡ DEVANAGARI LETTER VOCALIC LL;98;2401;x0098;.ll;ḹ
,.ll;ॢ;U+0962 ॢ DEVANAGARI VOWEL SIGN VOCALIC L;99;2402;x0099;;
,.rr;ॣ;U+0963 ॣ DEVANAGARI VOWEL SIGN VOCALIC LL;100;2403;x0100;;
,|;।;U+0964 । DEVANAGARI DANDA;101;2404;x0101;;
,||;॥;U+0965 ॥ DEVANAGARI DOUBLE DANDA;102;2405;x0102;;
,0;०;U+0966 ० DEVANAGARI DIGIT ZERO;103;2406;x0103;;
,1;१;U+0967 १ DEVANAGARI DIGIT ONE;104;2407;x0104;;
,2;२;U+0968 २ DEVANAGARI DIGIT TWO;105;2408;x0105;;
,3;३;U+0969 ३ DEVANAGARI DIGIT THREE;106;2409;x0106;;
,4;४;U+096A ४ DEVANAGARI DIGIT FOUR;107;2410;x0107;;
,5;५;U+096B ५ DEVANAGARI DIGIT FIVE;108;2411;x0108;;
,6;६;U+096C ६ DEVANAGARI DIGIT SIX;109;2412;x0109;;
,7;७;U+096D ७ DEVANAGARI DIGIT SEVEN;110;2413;x0110;;
,8;८;U+096E ८ DEVANAGARI DIGIT EIGHT;111;2414;x0111;;
,9;९;U+096F ९ DEVANAGARI DIGIT NINE;112;2415;x0112;;
%
,…;ॱ;U+0971 ॱ DEVANAGARI SIGN HIGH SPACING DOT;114;2417;x0114;;
,~a-;ॲ;U+0972 ॲ DEVANAGARI LETTER CANDRA A;115;2418;x0115;;
,oe-;ॳ;U+0973 ॳ DEVANAGARI LETTER OE;116;2419;x0116;;
,ooe-;ॴ;U+0974 ॴ DEVANAGARI LETTER OOE;117;2420;x0117;;
,aw-;ॵ;U+0975 ॵ DEVANAGARI LETTER AW;118;2421;x0118;;
,ue-;ॶ;U+0976 ॶ DEVANAGARI LETTER UE;119;2422;x0119;;
,uue-;ॷ;U+0977 ॷ DEVANAGARI LETTER UUE;120;2423;x0120;;
,mdd;ॸ;U+0978 ॸ DEVANAGARI LETTER MARWARI DDA;121;2424;x0121;;
,zh;ॹ;U+0979 ॹ DEVANAGARI LETTER ZHA;122;2425;x0122;;
,Y;ॺ;U+097A ॺ DEVANAGARI LETTER HEAVY YA;123;2426;x0123;;
,gg;ॻ;U+097B ॻ DEVANAGARI LETTER GGA;124;2427;x0124;;
,jj;ॼ;U+097C ॼ DEVANAGARI LETTER JJA;125;2428;x0125;;
,?;ॽ;U+097D ॽ DEVANAGARI LETTER GLOTTAL STOP;126;2429;x0126;;
,.DD;ॾ;U+097E ॾ DEVANAGARI LETTER DDDA;127;2430;x0127;;
,bb;ॿ;U+097F ॿ DEVANAGARI LETTER BBA;128;2431;x0128;;
,c0;꣠;U+A8E0 ꣠ COMBINING DEVANAGARI DIGIT ZERO;129;43232;x0129;;
,c1;꣡;U+A8E1 ꣡ COMBINING DEVANAGARI DIGIT ONE;130;43233;x0130;;
,c2;꣢;U+A8E2 ꣢ COMBINING DEVANAGARI DIGIT TWO;131;43234;x0131;;
,c3;꣣;U+A8E3 ꣣ COMBINING DEVANAGARI DIGIT THREE;132;43235;x0132;;
,c4;꣤;U+A8E4 ꣤ COMBINING DEVANAGARI DIGIT FOUR;133;43236;x0133;;
,c5;꣥;U+A8E5 ꣥ COMBINING DEVANAGARI DIGIT FIVE;134;43237;x0134;;
,c6;꣦;U+A8E6 ꣦ COMBINING DEVANAGARI DIGIT SIX;135;43238;x0135;;
,c7;꣧;U+A8E7 ꣧ COMBINING DEVANAGARI DIGIT SEVEN;136;43239;x0136;;
,c8;꣨;U+A8E8 ꣨ COMBINING DEVANAGARI DIGIT EIGHT;137;43240;x0137;;
,c9;꣩;U+A8E9 ꣩ COMBINING DEVANAGARI DIGIT NINE;138;43241;x0138;;
%
,filler;꣹;U+A8F9 ꣹ DEVANAGARI GAP FILLER;154;43257;x0154;;
,caret;꣺;U+A8FA ꣺ DEVANAGARI CARET;155;43258;x0155;;
,head;ꣻ;U+A8FB ꣻ DEVANAGARI HEADSTROKE;156;43259;x0156;;
,siddham;꣼;U+A8FC ꣼ DEVANAGARI SIGN SIDDHAM;157;43260;x0157;;
,jom;ꣽ;U+A8FD ꣽ DEVANAGARI JAIN OM;158;43261;x0158;;
,ayno;ꣾ;U+A8FE ꣾ DEVANAGARI LETTER AY;159;43262;x0159;;
,ayno;ꣿ;U+A8FF ꣿ DEVANAGARI VOWEL SIGN AY;160;43263;x0160;;
,\#;…;;161;0;x0161;;
%,..;.;;162;0;x0162;;
}
\mfssortaseq[x]{devatranslit}{<}{1}
xascii2deva mapping:
\setlength{\columnseprule}{0.4pt}
\begin{multicols}{4}
\mfslistaseq[x]{devatranslit}[
formata=\usefont{T1}{lmtt}{m}{n},
formatb=\fdevb\Large,
]
\end{multicols}
\translitx[x]{devatranslit}[
formata=\usefont{T1}{lmtt}{m}{n},
formatb=\fdevb,
]
{data a-biicii. kuul bananas s\&kuul }
.dh is set up as
\translit[x]{devatranslit}[
fielda=1,
formata=\usefont{T1}{lmtt}{m}{n},
fieldb=3,
formatb=\fdevb,%\usefont{T1}{lmtt}{m}{n}\small,
placeholder=4,
]{.dh}
and maps to
\translitx[x]{devatranslit}[
fielda=1,
formata=\usefont{T1}{lmtt}{m}{n},
fieldb=2,
formatb=\fdevb,
placeholder,
]{.dh}.
\newpage
xascii2unicode
\mfslistaseq[x]{devatranslit}[
fielda=1,
formata=\usefont{T1}{lmtt}{m}{n},
fieldb=3,
%formatb=\fdevb\small,
]
\newpage
By record number
\mfssortaseqnum[x]{devatranslit}{>}{4} %sort on record number
\mfslistaseq[x]{devatranslit}[
fieldb=2,
formatb=\fdevb\Large,
fielda=3,
formata=\usefont{T1}{lmtt}{m}{n}\small,
]
\newpage
By Unicode codepoint
\mfssortaseqnum[x]{devatranslit}{>}{5}
\mfslistaseq[x]{devatranslit}[
fielda=3,
formata=\usefont{T1}{lmtt}{m}{n}\small,
fieldb=2,
formatb=\fdevb\huge\color{blue},
]
\newpage
deva2velt
\mfssortaseq[x]{devatranslit}{<}{2}
\begin{multicols}{4}
\mfslistaseq[x]{devatranslit}[
fielda=2,
formata=\fdevb,
fieldb=7,
formatb=\usefont{T1}{lmtt}{m}{n}\small,
]
\end{multicols}
\newpage
velt2deva
\mfssortaseq[x]{devatranslit}{<}{7}
\begin{multicols}{4}
\mfslistaseq[x]{devatranslit}[
fieldb=2,
formatb=\fdevb,
fielda=7,
formata=\usefont{T1}{lmtt}{m}{n}\small,
]
\end{multicols}
\newpage
velt2iast
\mfssortaseq[x]{devatranslit}{<}{7}
\begin{multicols}{4}
\mfslistaseq[x]{devatranslit}[
fielda=7,
formata=\usefont{T1}{lmtt}{m}{n}\small,
fieldb=8,
formatb=\fipa,
fieldc=2,
formatc=\fdevb,
]
\end{multicols}
\newpage
78
\mfssortaseq[x]{devatranslit}{<}{7}
\translitx[x]{devatranslit}[
fielda=7,
formata=\fipa,
fieldb=8,
formatb=\fipa,
showoriginal=true,
intermediate=2,
]{
raamo raajama.ni sadaa vijayate raama.m rame"sa.m bhaje |
}
\bigskip
\noindent\textbf{Velthuis to Deva}:
\translitx[x]{devatranslit}[
fielda=1,
formata=\fipa,
fieldb=2,
formatb=\fdevb,
showoriginal=true,
]{raamo raajama.ni sadaa vijayate raama.m rame"sa.m bhaje |}
\bigskip
\noindent\textbf{Velthuis to IAST}:
\translitx[x]{devatranslit}[
fielda=7,
formata=\fipa,
fieldb=8,
formatb=\fipa,
intermediate=2,
]{
raamo raajama.ni sadaa vijayate raama.m rame"sa.m bhaje |}
\bigskip
An example record, which looks like this as raw text,
{\fdevb\color{blue} ,.dh;ढ;U+0922 ढ DEVANAGARI LETTER DDHA;35;2338;x0035;.dh;ḍh},
has these fields:
\bigskip
.dh (in xascii mapping, superset of Velthuis) [field 1]
= \translitx[x]{devatranslit}[
fielda=1,
formata=\fipa,
fieldb=2,
formatb=\fdevb,
showoriginal=false,
placeholder,
]{.dh} [field 2]
= \translitx[x]{devatranslit}[
fielda=1,
formata=\fipa,
fieldb=3,
formatb=\fdevb,
]{.dh} [field 3]
= \translitx[x]{devatranslit}[
fielda=1,
formata=\fipa,
fieldb=4,
formatb=\fipa,
]{.dh} (record number) [field 4]
= \translitx[x]{devatranslit}[
fielda=1,
formata=\fipa,
fieldb=5,
formatb=\fipa,
]{.dh} (Unicode codepoint, decimal) [field 5]
= \translitx[x]{devatranslit}[
fielda=1,
formata=\fipa,
fieldb=6,
formatb=\fipa,
]{.dh} (ID, experimental) [field 6]
= \translitx[x]{devatranslit}[
fielda=1,
formata=\fipa,
fieldb=7,
formatb=\fipa,
]{.dh} (Velthuis) [field 7]
= \translitx[x]{devatranslit}[
fielda=1,
formata=\fipa,
fieldb=8,
formatb=\fipa,
]{.dh} (IAST) [field 8]
\end{document}
代码已被强行塞入以适应答案框的 30k 个字符的限制。