5

I want to typeset text fractions with potentially arbitrary text instead of just numbers. A solution was presented here and this is my ConTeXt implementation:

\usetypescriptfile[ibmplex]
\setupbodyfont[ibmplex, 12pt]
\definefontfeature[numr][default][numr=yes]
\definefontfeature[dnom][default][dnom=yes]
\definehighlight[textnumr][default][style={\feature[+][numr]}]
\definehighlight[textdnom][default][style={\feature[+][dnom]}]

\definefontfeature[frac][default][frac=yes]
\definehighlight[textfrac][default][style={\feature[+][frac]}]

\def\fancyfrac#1#2{\textnumr{#1} \Uchar"2044 \textdnom{#2}}

\starttext
\fancyfrac{1}{8} % The 1 is not properly kerned
\textfrac{1/8} % Proper kerning
\stoptext

However, it seems that the numr feature is not working properly. In the log there is a line that reads:

system          > error: invalid parent default for textnumr, default defined too (best check it)

For the record I'm using the latest lmtx on Ubuntu 18.04. Does anyone know what the issue here is?

[EDIT]: I hacked together a solution based on the answer provided by Wolfgang that appears to work very well (even though I have no idea why):

\setupbodyfont [ibmplex]

\definefontfeature [f:numr] [numr=yes]
\definefontfeature [f:dnom] [dnom=yes]
\definefontfeature [f:frac] [frac=yes]
\define[2]\AugmentedVulgarFraction{\feature[+][f:frac]\vulgarfraction{{\feature[+][f:numr]#1}\:}{\:\feature[+][f:dnom]#2}}

[EDIT 2]: Upon further discussion with Wolfgang I ended up using the following macro:

\definesymbol[vulgarfraction][\textfraction]
\define[2]\TextFraction{\chardef\vulgarfractionmethod2\vulgarfraction{#1}{#2}}
  • The change the method for \vulgarfraction use \setconstant\vulgarfractionmethod=2 (the = is optional) or \setconstant\vulgarfractionmethod\plustwo (\plustwo = 2). – Wolfgang Schuster Jun 23 '20 at 12:58
5

The small space between the numerator and the slash appears because you have a space there in your definition for the \fancyfrac command.

\def\fancyfrac#1#2{\textnumr{#1} \Uchar"2044 \textdnom{#2}}

When you remove the space the gap disappears.

\def\fancyfrac#1#2{\textnumr{#1}\textfraction\textdnom{#2}}

The error message appears because your highlight defintions inherit it's values from the default instance but no instance with this name exists, when you change it to

\definehighlight [textnumr] [..,..=..,..]

the message disappears.

You can save a few lines when you drop the highlight commands and apply the features in the fraction command, there is also no need to inherit the default features for the numerator and denominator.

\setupbodyfont [ibmplex]

\definefontfeature [f:numr] [numr=yes]
\definefontfeature [f:dnom] [dnom=yes]

\define[2]\TextFraction
  {{\feature[+][f:numr]#1}%
    \textfraction
   {\feature[+][f:dnom]#2}}

\starttext

0123456789/0123456789

{\setfractions 0123456789/0123456789}

\TextFraction{1}{2}

\stoptext
  • Thank you very much for the prompt answer Wolfgang! But as I said in the question what I'm more interested in is the case \TextFraction{дин}{kg} which is still not typeset correctly. – blaze Jun 21 '20 at 21:10
  • 1
    @blaze The numr and dnom features are for numbers only. When you need fractions which work with text you can try the subs and sups features but the results are font dependent. A alternative to opentype features is the \vulgarfraction{...}{...} command but the spacing isn't perfect but you can ask on the ConTeXt mailing list to fix it. – Wolfgang Schuster Jun 21 '20 at 21:25
  • Actually, in the answer I linked in my question the exact behavior was demonstrated with numr and dnom. I'm reopening my question. – blaze Jun 21 '20 at 22:14
  • 1. Not all features are supported by each font and sometimes a font covers only a limited character set with a feature. 2. Can you reproduce the LaTeX example? I tries the mentioned fonts but wasn't able to get the same results but I don't know which version they used. – Wolfgang Schuster Jun 22 '20 at 13:11
  • 1
    @blaze The feature setting in your \AugmentedVulgarFraction are useless because the have no effect (the frac setting is even worse because you apply it to all text which comes after the command) and the small text is a result of the \vulgarfraction command. All you did was to add space around the slash (which can be changed with \definesymbol[vulgarfraction][\textfraction]) but this is something which should be fixed in the ConTeXt core. – Wolfgang Schuster Jun 22 '20 at 18:10

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.