我正在尝试使用梵文脚本中的一些字符来编写一个函数。我已将这些字符替换为完全不同的脚本中的其他一些字符。这是 MWE 所做的。
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Sanskrit 2003} %Any Devanagari font.
\newfontfamily{\doulo}{Doulos SIL}
\setlength{\parindent}{0cm}
\makeatletter
\catcode`\क=\active
\protected\def क{\doulo k}
\catcode`\ख=\active
\protected\def ख{\doulo kʰ}
\catcode`\ड=\active
\protected\def ड{\doulo ɖ}
\makeatother
\begin{document}
कखड
\end{document}
Doulos SIL 字体是角色出现所必需的,可以从这里
这将产生以下内容 -
现在我想有条件地添加 'ə' 这个字符。只有当梵文的另一个变音符号即'्'是缺席的.(这在某种程度上意味着无论何时'्'不应添加‘ə’符号,并且对于每个不跟相同‘ə’的字符都应添加。)对于这个条件设置,我已经对此进行了编码。
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Sanskrit 2003} %Any Devanagari font.
\newfontfamily{\doulo}{Doulos SIL}
\setlength{\parindent}{0cm}
\makeatletter
\catcode`\क=\active
\protected\def क{\bgroup\doulo k\futurelet\tmp\viramacheck}
\catcode`\ख=\active
\protected\def ख{\bgroup\doulo kʰ\futurelet\tmp\viramacheck}
\catcode`\ड=\active
\protected\def ड{\bgroup\doulo ɖ\futurelet\tmp\viramacheck}
\protected\def\viramacheck{\ifx\tmp ्\egroup\expandafter\@gobble\else ə\egroup\fi}
\makeatother
\begin{document}
क ख ड\\
क् ख् ड्
\end{document}
这提供了 -
对我来说,这一点很清楚。现在我想知道的是,除了有一个条件前提,即'्'我想要有一系列的前因。
例如,用逻辑语言来表达,如果 x 后面跟着् 和'A'和‘b’和'c' 不要添加 'ə'
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Sanskrit 2003} %Any Devanagari font.
\newfontfamily{\doulo}{Doulos SIL}
\setlength{\parindent}{0cm}
\makeatletter
\catcode`\क=\active
\protected\def क{\bgroup\doulo k\futurelet\tmp\viramacheck}
\catcode`\ख=\active
\protected\def ख{\bgroup\doulo kʰ\futurelet\tmp\viramacheck}
\catcode`\ड=\active
\protected\def ड{\bgroup\doulo ɖ\futurelet\tmp\viramacheck}
\protected\def\viramacheck{\ifx\tmp ्\egroup\expandafter\@gobble\else ə\egroup\fi}
\makeatother
\begin{document}
कaखbडc
\end{document}
输出是 -
我想要的是 -
如何制作这些条件数组,即'्'、‘a’、‘b’和‘c’?
根据@siracusa的建议,我按以下方式编辑了代码。这是最终的、完全准备好的代码。
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Sanskrit 2003} %Any Devanagari font.
\newfontfamily{\doulo}{Doulos SIL}
\setlength{\parindent}{0cm}
\makeatletter
\def\ifischar#1{%
\ifx\tmp#1%
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
\catcode`\क=\active
\protected\def क{\bgroup\doulo k\futurelet\tmp\viramacheck}
\catcode`\ख=\active
\protected\def ख{\bgroup\doulo kʰ\futurelet\tmp\viramacheck}
\catcode`\ड=\active
\protected\def ड{\bgroup\doulo ɖ\futurelet\tmp\viramacheck}
\catcode`\अ=\active
\protected\def अ{\bgroup\doulo ə}
\catcode`\ा=\active
\protected\def ा{\doulo a}
\catcode`\आ=\active
\protected\def आ{\doulo a}
\catcode`\ि=\active
\protected\def ि{\doulo i}
\catcode`\इ=\active
\protected\def इ{\doulo i}
\catcode`\ी=\active
\protected\def ी{\doulo iː}
\catcode`\ई=\active
\protected\def ई{\doulo iː}
\catcode`\ु=\active
\protected\def ु{\doulo u}
\catcode`\उ=\active
\protected\def उ{\doulo u}
\catcode`\ू=\active
\protected\def ू{\doulo uː}
\catcode`\ऊ=\active
\protected\def ऊ{\doulo uː}
\catcode`\े=\active
\protected\def े{\doulo e}
\catcode`\ए=\active
\protected\def ए{\doulo e}
\catcode`\ै=\active
\protected\def ै{\doulo ə͡i}
\catcode`\ऐ=\active
\protected\def ऐ{\doulo ə͡i}
\catcode`\ो=\active
\protected\def ो{\doulo o}
\catcode`\ओ=\active
\protected\def ओ{\doulo o}
\catcode`\ौ=\active
\protected\def ौ{\doulo ə͡u}
\catcode`\औ=\active
\protected\def औ{\doulo ə͡u}
\catcode`\ं=\active
\protected\def ं{\doulo ũ}
\protected\def\viramacheck{%
\ifischar{्}{\egroup\@gobble}{%
\ifischar{ा}{\egroup\@gobble}{%
\ifischar{ी}{\egroup\@gobble}{%
\ifischar{ू}{\egroup\@gobble}{%
\ifischar{ि}{\egroup\@gobble}{%
\ifischar{ु}{\egroup\@gobble}{%
\ifischar{े}{\egroup\@gobble}{%
\ifischar{ै}{\egroup\@gobble}{%
\ifischar{ो}{\egroup\@gobble}{%
\ifischar{ौ}{\egroup\@gobble}{%
\ifischar{अ}{\egroup\@gobble}{%
\ifischar{आ}{\egroup\@gobble}{%
\ifischar{ई}{\egroup\@gobble}{%
\ifischar{ई}{\egroup\@gobble}{%
\ifischar{उ}{\egroup\@gobble}{%
\ifischar{ऊ}{\egroup\@gobble}{%
\ifischar{ए}{\egroup\@gobble}{%
\ifischar{ऐ}{\egroup\@gobble}{%
\ifischar{ओ}{\egroup\@gobble}{%
\ifischar{औ}{\egroup\@gobble}{%
ə\egroup
}}}}}}}}}}}}}}}}}}}}%
}
\makeatother
\begin{document}
काखीडूअए
\end{document}
输出 -
这解决了添加字符 'ə' 的问题,但如果我们看行号 23、31 和 39,ा、ी 和 ू 定义为A,我&ː分别。它们没有出现在输出中。相反,如果我们查看第 21 行和第 45 行,अ 和 ए 分别被定义为 ə 和 e,并且它们出现在输出中。变音符号可能存在问题。我们能解决这个问题吗?
答案1
由于我的系统上没有合适的字体,因此这有点像是瞎猜。我的想法是进行嵌套\ifx
检查,如以下结构:
\ifx\tmp X
\else
\ifx\tmp Y
\else
\fi
\fi
因为您使用 来\@gobble
从输入流中删除以下标记,所以您必须更加小心,因为 TeX 会在标记流中保留\else
/结构的部分。因此,将删除这些标记而不是以下字符(这就是您在测试中这样做的原因)。对于嵌套 if,输入正确数量的s 太繁琐了。\fi
\@gobble
\expandafter
\expandafter
你可以使用类似这样的宏
% use as \ifischar{X}{then part}{else part}
\def\ifischar#1{%
\ifx\tmp#1%
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
它执行相同的检查,但注意没有虚假的标记留在标记流中。你的\viramacheck
宏将变成
\protected\def\viramacheck{%
\ifischar{्}{\egroup\@gobble}{%
\ifischar{a}{\egroup\@gobble}{%
\ifischar{b}{\egroup\@gobble}{%
\ifischar{c}{\egroup\@gobble}{%
ə\egroup
}}}}%
}
我认为这给出了正确的结果,但我不能确定。
答案2
@siracusa 建议了正确的格式化我的代码的方法,现在我已经完全准备好了。
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Sanskrit 2003} %Any Devanagari font.
\newfontfamily{\doulo}{Doulos SIL}
\setlength{\parindent}{0cm}
\makeatletter
\def\ifischar#1{%
\ifx\tmp#1%
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
\catcode`\क=\active
\protected\def क{\bgroup\doulo k\futurelet\tmp\viramacheck}
\catcode`\ख=\active
\protected\def ख{\bgroup\doulo kʰ\futurelet\tmp\viramacheck}
\catcode`\ग=\active
\protected\def ग{\bgroup\doulo g\futurelet\tmp\viramacheck}
\catcode`\घ=\active
\protected\def घ{\bgroup\doulo gʱ\futurelet\tmp\viramacheck}
\catcode`\ङ=\active
\protected\def ङ{\bgroup\doulo ŋ\futurelet\tmp\viramacheck}
\catcode`\च=\active
\protected\def च{\bgroup\doulo ʧ\futurelet\tmp\viramacheck}
\catcode`\छ=\active
\protected\def छ{\bgroup\doulo ʧʰ\futurelet\tmp\viramacheck}
\catcode`\ज=\active
\protected\def ज{\bgroup\doulo ʤ\futurelet\tmp\viramacheck}
\catcode`\झ=\active
\protected\def झ{\bgroup\doulo ʤʱ\futurelet\tmp\viramacheck}
\catcode`\ञ=\active
\protected\def ञ{\bgroup\doulo ɲ\futurelet\tmp\viramacheck}
\catcode`\ट=\active
\protected\def ट{\bgroup\doulo ʈ\futurelet\tmp\viramacheck}
\catcode`\ठ=\active
\protected\def ठ{\bgroup\doulo ʈʰ\futurelet\tmp\viramacheck}
\catcode`\ड=\active
\protected\def ड{\bgroup\doulo ɖ\futurelet\tmp\viramacheck}
\catcode`\ढ=\active
\protected\def ढ{\bgroup\doulo ɖʱ\futurelet\tmp\viramacheck}
\catcode`\ण=\active
\protected\def ण{\bgroup\doulo ɳ\futurelet\tmp\viramacheck}
\catcode`\त=\active
\protected\def त{\bgroup\doulo t̪\futurelet\tmp\viramacheck}
\catcode`\थ=\active
\protected\def थ{\bgroup\doulo t̪ʰ\futurelet\tmp\viramacheck}
\catcode`\द=\active
\protected\def द{\bgroup\doulo d̪\futurelet\tmp\viramacheck}
\catcode`\ध=\active
\protected\def ध{\bgroup\doulo d̪ʱ\futurelet\tmp\viramacheck}
\catcode`\न=\active
\protected\def न{\bgroup\doulo n̪\futurelet\tmp\viramacheck}
\catcode`\प=\active
\protected\def प{\bgroup\doulo p\futurelet\tmp\viramacheck}
\catcode`\फ=\active
\protected\def फ{\bgroup\doulo pʰ\futurelet\tmp\viramacheck}
\catcode`\ब=\active
\protected\def ब{\bgroup\doulo b\futurelet\tmp\viramacheck}
\catcode`\भ=\active
\protected\def भ{\bgroup\doulo bʱ\futurelet\tmp\viramacheck}
\catcode`\म=\active
\protected\def म{\bgroup\doulo m\futurelet\tmp\viramacheck}
\catcode`\य=\active
\protected\def य{\bgroup\doulo j\futurelet\tmp\viramacheck}
\catcode`\र=\active
\protected\def र{\bgroup\doulo ɾ\futurelet\tmp\viramacheck}
\catcode`\ऱ=\active
\protected\def ऱ{\bgroup\doulo ɾ\futurelet\tmp\viramacheck}
\catcode`\ल=\active
\protected\def ल{\bgroup\doulo l\futurelet\tmp\viramacheck}
\catcode`\व=\active
\protected\def व{\bgroup\doulo w\futurelet\tmp\viramacheck}
\catcode`\श=\active
\protected\def श{\bgroup\doulo ʃ\futurelet\tmp\viramacheck}
\catcode`\ष=\active
\protected\def ष{\bgroup\doulo ʂ\futurelet\tmp\viramacheck}
\catcode`\स=\active
\protected\def स{\bgroup\doulo s\futurelet\tmp\viramacheck}
\catcode`\ह=\active
\protected\def ह{\bgroup\doulo h\futurelet\tmp\viramacheck}
\catcode`\ळ=\active
\protected\def ळ{\bgroup\doulo ɭ\futurelet\tmp\viramacheck}
\catcode`\अ=\active
\protected\def अ{\bgroup\doulo ə}
\catcode`\ा=\active
\protected\def ा{\doulo a}
\catcode`\आ=\active
\protected\def आ{\doulo a}
\catcode`\ि=\active
\protected\def ि{\doulo i}
\catcode`\इ=\active
\protected\def इ{\doulo i}
\catcode`\ी=\active
\protected\def ी{\doulo iː}
\catcode`\ई=\active
\protected\def ई{\doulo iː}
\catcode`\ु=\active
\protected\def ु{\doulo u}
\catcode`\उ=\active
\protected\def उ{\doulo u}
\catcode`\ू=\active
\protected\def ू{\doulo uː}
\catcode`\ऊ=\active
\protected\def ऊ{\doulo uː}
\catcode`\े=\active
\protected\def े{\doulo e}
\catcode`\ए=\active
\protected\def ए{\doulo e}
\catcode`\ै=\active
\protected\def ै{\doulo ə͡i}
\catcode`\ऐ=\active
\protected\def ऐ{\doulo ə͡i}
\catcode`\ो=\active
\protected\def ो{\doulo o}
\catcode`\ओ=\active
\protected\def ओ{\doulo o}
\catcode`\ौ=\active
\protected\def ौ{\doulo ə͡u}
\catcode`\औ=\active
\protected\def औ{\doulo ə͡u}
\catcode`\ं=\active
\protected\def ं{\doulo ũ}
\protected\def\viramacheck{%
\ifischar{्}{\egroup\@gobble}{%
\ifischar{ा}{\egroup}{%
\ifischar{ी}{\egroup}{%
\ifischar{ू}{\egroup}{%
\ifischar{ि}{\egroup}{%
\ifischar{ु}{\egroup}{%
\ifischar{े}{\egroup}{%
\ifischar{ै}{\egroup}{%
\ifischar{ो}{\egroup}{%
\ifischar{ौ}{\egroup}{%
\ifischar{अ}{\egroup}{%
\ifischar{आ}{\egroup}{%
\ifischar{ई}{\egroup}{%
\ifischar{ई}{\egroup}{%
\ifischar{उ}{\egroup}{%
\ifischar{ऊ}{\egroup}{%
\ifischar{ए}{\egroup}{%
\ifischar{ऐ}{\egroup}{%
\ifischar{ओ}{\egroup}{%
\ifischar{औ}{\egroup}{%
ə\egroup
}}}}}}}}}}}}}}}}}}}}%
}
\makeatother
\begin{document}
काखीडूअए क की ा क्\\
क् क का कि की कु कू के कै को कौ कं\\
ढ ढा ढि ढी ढु ढू ढे ढै ढो ढौ ढह\\
\end{document}