Thanks, Hans! 

I see; this does work except for the trouble of annotating with \digits macro.  Would it be possible if I wrote a processor in Lua to do the work?

nodes.tasks.appendaction ("processors", "before", "fix_persian_mathperiod")

Can I find out if a node is inside math?  If I look at the corresponding font, how can I find out if this is a math font or not?


I take it that in math fonts, kerning does not work, either?  In my case, the Persian decimal separator usually has a part below the baseline that extends to the left, and because all (Persian) digits are above the baseline, I get an ugly space in the middle.  If kerning is not possible at all, I can try to change the dimensions of Persian decimal separator symbol because the kern is always necessary.  Is it possible to change the dimensions of the symbol or is that also fixed and unchangeable?

Thanks a lot!
—MHB



On Mon, Aug 8, 2016 at 10:44 AM, Hans Hagen <pragma@wxs.nl> wrote:
On 8/2/2016 9:54 PM, Mohammad Hossein Bateni wrote:
Could the problem be because math fonts use mode=base instead of
mode=node?  Or is it because in math fonts, the digits and/or full-stop
have different codes?

math fonts are defined and then don't change i.e. they are quite static and all juggling with individual symbols of sequences is done using predictable methods

—MHB

On Mon, Aug 1, 2016 at 9:46 AM, Mohammad Hossein Bateni
<bateni@gmail.com <mailto:bateni@gmail.com>> wrote:

    Dear list,

    I want to add a customized font feature to the math font, to
    automatically change the decimal point (unicode 0x2E) to the
    Arabic/Farsi version (unicode 0x66B).  This will go well with the
    mapping from Latin digits to Farsi digits (done in a sample with
    mathdigits fallback).

    For instance, I want to code in $123.45$ and get a result like
    ۱۲۳٫۴۵.  However, I do not want to simply map 0x2E to 0x66B, because
    then "full stop" outside a number will also change.  In particular,
    I'd like to have the mapping only when full-stop is preceded and
    succeeded by a digit.  This will, among other things, leave the
    end-of-equation periods unchanged.

    Here is how I tried to achieve it.


    \startluacode
    digits = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39 }
    -- 0x66B instead of 0x2F gives an error!
    replacements = { [0x002E] = { 0x2F } }
    fonts.handlers.otf.addfeature {
      name = "mpf",
      type = "chainsubstitution",
      lookups = { {
        type = "multiple",
        data = replacements,
      } },
      data = {
        rules = {
          {
            current = { { 0x002E } },
            after   = { digits },
            before  = { digits },
            lookups = { 1 },
          }
        }
      }
    }
    \stopluacode

    \definefontfeature[mathperiod][mpf=yes]

    \resetfontfallback [mathdigits]
    %\definefontfallback[mathdigits][dejavusansmono][digitsextendedarabicindic][check=yes,force=yes,offset=digitsnormal]

    \definefontsynonym
    [MathRoman][name:modern][features={math\mathsizesuffix,mathperiod},goodies=lm-math,fallbacks=mathdigits]

    \starttext
    $123.45.$

    123.45.

    \addff{mathperiod}
    123.45.
    \stoptext


    Though this font feature works outside math, it does not seem to
    have any effect within the math font.  Why is that?  Can we add font
    feature to the math font?  Are the character codes different?

    Notice that I could not get it to work, so I commented out the
    fallback for Persian digits, to make things simpler.  To get the
    proof of concept, I am trying to change period to forward slash (see
    below).

    Is the syntax I use for having two features in \defontfontsynonym
    correct?  Actually, I did try with only mathperiod and it does not
    work, either.

    When I change 0x2F (slash) to 0x066B in "replacements", I get an
    error as follows.


    fonts           > otf chain > feature 'mpf', type
    'gsub_contextchain', chain lookup 'mpf': rule 1 matches at char
    U+0002E (period) for (1,1,1) chars, lookuptype 'gsub_multiple'

    error:
    ...ext/tex/texmf-context/tex/context/base/mkiv/font-ots.lua:1232:
    attempt to index field '?' (a nil value)

    tex error       > tex error on line 1 in file
    /Users/bateni/farsitex/context/bostan/examples/mathfa/1.tex: ?

    \page ->\par
                 \dosingleempty \page_breaks_process
    \strc_pagenumbers_flush_final_page ...\else \page

    [\p_strc_pagenumbers_page ...
    \dostoptext ...\strc_pagenumbers_flush_final_page
                                                      \page \the
    \everystoptext ...
    l.1 \dostoptext

    \clf_stoptext ->\luafunction \16>>clf_stoptext

    l.46 \stoptext



    Best,
    MHB




___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________



--

-----------------------------------------------------------------
                                          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 / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________