This is great. Thanks a lot, Hans!
Documented on the wiki: https://wiki.contextgarden.net/Input_and_compilation/Languages/Right-to-left_RTL

I tested the idea with all context math fonts. TeX Gyre, DejaVu, Modern, STIX Two, Libertinus, XCharter, Kp Fonts, EB Garamond, Concrete, and Erewhon work with different fallback fonts I tried.
On the other hand, I couldn't get Kurier and Plex to work (not important, just reporting). See note about Pennstander below.

My typescript looks something like this:

%%% beginning of demo
%%%
%%% some definitions for vazir, sahel and vazircode to set up rm, ss, mm
%%% followed by the following for math
 
% SEC A: fallback
\starttypescript [math] [fall:vazir] [name]
\definefontfallback [mathdig] [vazirregular]     [digitsextendedarabicindic] [check=yes,force=yes,offset=digitsnormal]
\definefontfallback [mathdig] [vazirbold] [digitsextendedarabicindic] [check=yes,force=yes,offset=digitsbold]
% I use the following to remap some other characters like Arabic decimal separator, etc.
\definefontfallback [mathdig] [vazirregular]     [arabic]                    [check=yes,force=yes]
\stoptypescript

% SEC B: base
\starttypescript [math] [main:modern] [name]
  \definefontsynonym[MathRoman]    [file:latinmodern-math][features={math\mathsizesuffix,lm:mathextra,lm-math},goodies=modern-math,fallbacks=mathdig]
  \definefontsynonym[MathRomanBold][file:latinmodern-math][features={math\mathsizesuffix,lm:mathextra,lm-math-bold,lm-math},goodies=modern-math,fallbacks=mathdig]
\stoptypescript

% SEC C: combination
\starttypescript  [myfont]
  \definetypeface [\typescriptone][rm] [serif][sahel]    [default]
  \definetypeface [\typescriptone][ss] [sans] [vazir]    [default]
  \definetypeface [\typescriptone][tt] [mono] [vazircode][default]
  %\definetypeface [\typescriptone][mm] [math] [modern]    [default]
  \definetypeface [\typescriptone][mm] [math] [fall:vazir,main:modern]      [default]
\stoptypescript

%%% end of demo

Still unresolved (less important mostly out of curiosity):

1. I'd have preferred something like "[math] [fall] [vazir] [default]" and "[math] [base] [modern] [default]" but couldn't get it to work. Is there any other way to make the above more readable? In my setup, I have copies of SEC A for each fallback font and a copy of SEC B for each base math font.
2. I don't understand how \definefontsynonym works. Does it have to be within a typescript? When (and how many times) are the definitions inside "executed"?
3. I couldn't get synonyms to work in the second argument of \definefontfallback.
4. Can we pass multiple fallbacks to \definefontsynonym definition like fallbacks={a,b}. I couldn't get this to work.
5. Can we do transitive definefontsynonyms and add features and fallback iteratively? I mean, define B from A with some features and fallbacks, and then C from B with some additional features and fallbacks.
6. I see that we have digitsnormal and digitsbold in the normal (non-bold) math font. Do we have the bold version of every character in there?
7. When I tried to apply fallback on Pennstander (https://github.com/juliusross1/Pennstander) I discovered that the fallback does not take effect unless I add "presets.fallbacks {}," instead of the tweaks of the goodies file.
8. What is a "font class". I couldn't make much sense of the magical code for \definefontsynonym, etc. though something I found there was that there exists a class fallbacks and a (non-class?) fallback for each font. In the logs, I always saw the class one output as empty.

--Mohammad

On Wed, Feb 12, 2025 at 7:37 AM Hans Hagen via ntg-context <ntg-context@ntg.nl> wrote:
On 2/8/2025 3:05 PM, Mohammad Hossein Bateni wrote:
> Hello,
>
> I use fallbacks to substitute "Arabic" digits in math to Indic ones. The
> mechanism doesn't work in the newest context. I tried it with mkxl
> version in 2025.02.04 17:52 in a clean install. The email is a bit long,
> but please bear with me, so I can learn a few other things along the way.

\definefontfallback [Math] [dejavusansmono] [0x0660-0x0669]
[check=yes,force=yes,offset=digitsnormal]

\setupbodyfont[dejavu,sans]

\starttext
\startlines
     1 : \im{3+2=5 \quad \bf 3+2=5} math with fallback
     2 : {\bf \im{3+2=5 \quad \bf 3+2=5} bold math}
     3 : {۳ + ۲ = ۵ \bf ۳ + ۲ = ۵ text Indic digits}
     4 : {3 + 2 = 5 \bf 3 + 2 = 5 text Arabic diigts}
     5 : \dm{\sum_{i=1}^{8} x^2 = \pi\alpha + e^{-\beta}}
\stoplines
\stoptext

>          %$$\sum_{i=1}^{8} x^2 = \pi\alpha + e^{-\beta}$$
 >
> If the last line is uncommented, I ran into the following error.

In ConTeXt the $$ is just seen as $ (inline math).

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________