2

Using CONTEXT MkIV, is it possible to add custom/virtual OTF features to a font used in math mode? Here is a simplified version of what I want to do. I want to change all occurrences of 1.2 in math mode to 1/2, that is, the period should change to forward slash when occurring between digits 1 and 2. (My ultimate goal is to change period U+2E to U+66B when sandwiched between any two digits.)

Here is how I tried to achieve this.

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

\definefontfeature[mathperiod][mpf=yes]

\starttypescript[math][xits][name]
\definefontsynonym[MathRoman][file:xits-math.otf][features=mathperiod,goodies=xits-math]
\stoptypescript

\setupbodyfont[xits]

\starttext
\startformula
  1.2.  %% does not work here
\stopformula
\addff{mathperiod}
1.2.    %% but works here
\stoptext

This does not work in math mode. However, the same font feature works in text mode.

If I replace mps=yes with ss08=yes, I get the upright integral, showing that the list of features is indeed applied to the math font, and suggesting that the problem is that mps does not trigger for the sequence 1.2 in math mode.

Math fonts use an extended encoding, however, my investigation shows that the normal digits still occupy the range 0x30-0x39 and period has the code 0x2E (more precisely, \Umathchar"0"0"002E). Is that correct?

I can guess that OpenType features are only applied in mode=node. Adding this to the font feature definition not only does not solve the problem, but it also nullifies the upright integral feature. (At this point I do not care much about the upright integral, but an additional question would be about how to get both mode=base and mode=node features working together.)

  • 1
    Imho you should better ask your question on the context mailing. – Ulrike Fischer Aug 3 '16 at 14:06
  • I did send the question there first, but have not gotten any response yet :( I wanted to try my luck here as well...specially given that similar math font-related questions have been answered here before. – MHB Aug 3 '16 at 14:53
  • Perhaps Hans is in holiday. But imho you are right: math use mode=base and so it doesn't work. I have no idea what side-effects it would have to use mode=node instead, or if there is some way to get such substituations with base mode. – Ulrike Fischer Aug 3 '16 at 15:24
  • @MHB There is a lot of noise on the mailing list so some things just go unnoticed. This is an interesting question though, so I think you should bump the thread or just ask the question again. – Henri Menke Aug 4 '16 at 20:47
  • Are there any news here (did you receive an answer)? – TeXnician Mar 3 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.