# Font and DeclareTextFontCommand problem

I have defined a command (mapcommand) to convert a given text into another form. However, in article after using the command it changes the font below of it. I mean, the font remains Times New Roman until I use the command, after using the command it changes font to CharisSil to all the text below of it. I want to use CharisSil font only the text inside the command. I tried \DeclareTextFontCommand but not working properly. Please see the MWE below. Thank you. Compiler: XeLatex

\documentclass{article}

\RequirePackage{CharisSIL}

\newfontface\mapfnt{CharisSIL-R.ttf}

\makeatletter
\def\zztable#1{#1}
\def\zzrow#1#2{\expandafter\gdef\csname B-#2\endcsname{#1}}
\def\mapcommand#1{\mapfnt\xxconvert#1@}
\def\xxconvert{\futurelet\tmp\xxxconvert}
\def\xxxconvert{%
\ifx\tmp\@sptoken\space\fi
\xxxxconvert
}
\def\xxxxconvert#1{%
\expandafter\ifx\csname B-#1\endcsname\relax?%
\expandafter\show\csname B-#1\endcsname
\fi
\csname B-#1\endcsname
\xxconvert}
\expandafter\def\csname B-@\endcsname#1{}
\input{maps}
\makeatother

\setmainfont{Times New Roman}

\begin{document}

The font of this line Times new roman as expected. \mapcommand{০১২৩৪}  However, from here font changes after the use of the command.

\end{document}


maps.text

\zztable{
\zzrow{0}{০}
\zzrow{1}{১}
\zzrow{2}{২}
\zzrow{3}{৩}
\zzrow{4}{৪}
}


## 2 Answers

You have to localize the font change:

\def\mapcommand#1{{\mapfnt\xxconvert#1@}}% <-- add braces!


You can also consider this simpler implementation:

\documentclass{article}
\usepackage{fontspec}

\setmainfont{Times New Roman}
\newfontface\mapfnt{Charis SIL}

\ExplSyntaxOn

\NewDocumentCommand{\conversiontable}{m}
{
\tl_set:Nn \l_israt_convert_table_tl { #1 }
\tl_reverse:N \l_israt_convert_table_tl
}

\NewExpandableDocumentCommand{\mapcommand}{m}
{
\str_map_function:nN { #1 } \israt_convert_token:n
}

\tl_new:N \l_israt_convert_table_tl

\cs_new:Nn \israt_convert_token:n
{
{ \mapfnt \str_case:nV { #1 } \l_israt_convert_table_tl }
}

\ExplSyntaxOff

\conversiontable{
{0}{০}
{1}{১}
{2}{২}
{3}{৩}
{4}{৪}
}

\begin{document}

The font of this line is Times New Roman as expected. \mapcommand{০১২৩৪}
The font is again Times.

\end{document}

• Thank you. It works. Jul 26 at 16:50
• The conversiontable works fine for all alphabets except 3. These 3 alphabets has two different case, for example, this ড় and this ড় are different though both looks exactly same. First, ড় is U+09dc and second ড় is a combination of U+09a1 and U+09bc. Your conversion table shows different results for these two characters. However, I want the same output for both ড় which is {ɽ}. Whichever ড় it is I want ɽ as output. Like {ড়}{ɽ} {ড়}{ɽ} Jul 27 at 5:27
• Egreg you can test this here mathml-refresh.github.io/xml-entities/unicode-names.html Jul 27 at 5:29

Although you don’t say what you’re trying to do, you might have an XY-problem. That is, if your actual goal here is to be able to display Assamese numerals that show as ASCII digits in your source, there are simpler ways to do it. This works in LuaLaTeX:

\documentclass{article}
\tracinglostchars=3 % Halt if a font cannot display a glyph.
\usepackage[english, bidi=basic]{babel}
\usepackage{fontspec}
\usepackage[paperwidth=10cm]{geometry} % To format the MWE for TeX.SX.

\babelprovide[import, mapdigits]{bengali}

\defaultfontfeatures{ Scale=MatchUppercase, Ligatures=TeX }

\babelfont{rm}
[Scale=1.0]{TeX Gyre Termes}
% Noto Serif Bengali is available at:
% https://www.google.com/get/noto/#sans-beng
\babelfont[bengali]{rm}
{Noto Serif Bengali}

\begin{document}
This text is in Termes. \foreignlanguage{bengali}{01234}
Now back to Termes.
\end{document}


If you really do want to perform the conversion the other way around, @egreg has provided a great answer. (But consider changing your input method.)