ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Mohammad Hossein Bateni <bateni@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Changing decimals points to Persian ones via font features
Date: Mon, 1 Aug 2016 15:46:34 +0200	[thread overview]
Message-ID: <CAMHZ1dY_3_LM_K7hTRRButwuUF8dkLV91Cd1hb4d3=jAsxhcPg@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 3136 bytes --]

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

[-- Attachment #1.2: Type: text/html, Size: 3752 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

             reply	other threads:[~2016-08-01 13:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-01 13:46 Mohammad Hossein Bateni [this message]
2016-08-02 19:54 ` Mohammad Hossein Bateni
2016-08-08 14:44   ` Hans Hagen
2016-08-08 15:24     ` Mohammad Hossein Bateni
2016-08-08 15:36       ` Hans Hagen
2016-08-08 14:42 ` Hans Hagen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMHZ1dY_3_LM_K7hTRRButwuUF8dkLV91Cd1hb4d3=jAsxhcPg@mail.gmail.com' \
    --to=bateni@gmail.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).