latex3 / xfrac

Split level fractions
LaTeX Project Public License v1.3c
1 stars 0 forks source link

\sfrac does not use OpenType fractions #3

Open adunning opened 5 years ago

adunning commented 5 years ago

The xfrac package does not provide any means of using OpenType fractions where these are available. Would it be possible to add an option that turns on \addfontfeature{Fractions=On} through fontspec?

Here's an example based on a StackExchange discussion:

screen shot 2019-02-15 at 23 16 35

\documentclass[12pt,a5paper]{article}
\usepackage{fontspec,xfrac}
\usepackage[osf,p]{libertinus}
\def\frc#1{{\addfontfeature{Fractions=On}#1}}

\begin{document}
\section{xfrac}
In Plato’s \textit{Timaeus,} the demiurge gives the world-soul a
structure based on two geometrical proportions, their arithmetic
means, and their harmonic means: 1, \sfrac{4}{3}, \sfrac{3}{2}, 2,
\sfrac{8}{3}, 3, 4, \sfrac{9}{2}, \sfrac{16}{3}, 6, 8, 9,
\sfrac{27}{3}, 18, and 27. Why do you suppose he did that?

\section{font feature}
In Plato’s \textit{Timaeus,} the demiurge gives the world-soul a
structure based on two geometrical proportions, their arithmetic
means, and their harmonic means: 1, \frc{4/3}, \frc{3/2}, 2,
\frc{8/3}, 3, 4, \frc{9/2}, \frc{16/3}, 6, 8, 9, \frc{27/3}, 18, and
27. Why do you suppose he did that?

\end{document}
wspr commented 5 years ago

Are OpenType fractions actually reliable? It’s been years since I did any testing but I remember poor results.

Perhaps more reliable would be for xfrac to have an OpenType mode added that looks for numerator and denominator glyphs and uses them. (Kind of like the realscripts package does for footnote symbols and so on.)

adunning commented 5 years ago

Some fonts attempt to add extra context detection to allow the option to be used globally, and that can get messy, though that's not really a problem here. I think the font is also responsible for converting a slash into a solidus, and things could theoretically go wrong there. But with a good font, you get a perfectly kerned fraction without additional work.

adunning commented 5 years ago

Ah, evidently many fonts have trouble with more complex fractions.

khaledhosny commented 5 years ago

BTW, with XeTeX <numbers><fraction slash><numbers> should automatically activate numr, dnom, and frac OpenType features for this range of characters (a feature of HarfBuzz, so any HarfBuzz-using engine should have it).

adunning commented 5 years ago

Very cool – though, alas, that does not seem to work with LuaLaTeX. It does seem as if @wspr's approach would be the most reliable way of having fractions that just work.

car222222 commented 5 years ago

@khaledhosny Thanks for this insight into HarfBuzz, and of course the anticipated luahbtex! One question: is harfbuzz itself configurable? For, example could a luahbtex user turn off features such as this one for fractions, or extend it to be used with single letters as well as numbers? Or must all configuration be done via the fonts in use?

khaledhosny commented 5 years ago

This particular behavior of HarfBuzz is not configurable; it follows the Unicode recommendation for handling fraction slash (U+2044). You can avoid the automatic fractions by not using fraction slash (regular slash does not activate this), and you can manually activate frac, numr and dnom as needed.