I'm trying to code a function with the help of some characters in Devanagari script. I've replaced the characters with some other characters of a totally different script. This is the MWE to do it.
\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 font is necessary for the characters to appear and can be obtained from here
This produces the following -
Now I want 'ə' this character to be added conditionally. It should only be added when another diacritic of Devanagari i.e. '्' is absent. (Which in a way means whenever '्' comes 'ə' symbol should not be added and for every character which is not followed by the same 'ə' should be added.) For this conditional setting, I've coded this.
\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}
This provides -
This much is clear to me. Now what I wanted to know is, instead of having one conditional antecedent i.e. '्' I want to have an array of antecedents.
eg. To put it into a logical language, if x is followed by ् and 'a' and 'b' and 'c' do not add 'ə'
\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}
The output is -
and what I want is -
How to make an array of these conditionals i.e. '्', 'a', 'b' & 'c'?
As suggested by @siracusa I've edited the code in the following way. This is the final and fully ready code.
\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}
The output -
This solved the problem of adding character 'ə', but if we look at line number 23, 31 & 39 ा, ी & ू are defined as a, iː & uː respectively. They are not coming in the output. On the contrary if we look at line number 21 & 45 अ & ए are defined as ə & e respectively and they are coming in the output. Probably there is something wrong with the diacritics. Can we solve this?






\ifxtests to check for different characters. See also Check if a string contains a given character – siracusa Jul 11 '19 at 09:10l3regexengine may be a better option. – siracusa Jul 11 '19 at 15:27\ifischar{ा}{\egroup\@gobble}{%shouldn't have the\@gobblein it because you actually want your next (active) character to be exectuted. Something with the group nesting also seems to be wrong. – siracusa Jul 11 '19 at 16:24