Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Unicode vulgar fraction composition

by kcott (Archbishop)
on Sep 24, 2020 at 08:22 UTC ( [id://11122152]=note: print w/replies, xml ) Need Help??


in reply to Unicode vulgar fraction composition

G'day raygun,

As ++ikegami has explained, and you have accepted, there is no compatibility composition.

You have asked about modules. There are some available but I can't say whether they are suitable for your purposes (as you haven't explained that part). Here's a couple. If these aren't suitable, search MetaCPAN using terms reflecting your use case.

  • HTML::Fraction may do what you want if you're working with HTML.
  • Unicode::Fraction will render any vulgar fraction into something that's intended to look like a Unicode fraction: 12345/67890 becomes something like 12345/67890 (that's just a rough approximation).
"... write my own function to handle these fractions (there are only a dozen or so), ..."

There's actually 18 in total. Three have the codepoints U+00BC - U+00BE and can be found in the PDF Code Chart "C1 Controls and Latin-1 Supplement". The other 15 have the codepoints U+2150 - U+215E and can be found in the PDF Code Chart "Number Forms".

Writing your own function is pretty easy. I wrote one just for the fun of it: I've put it in a spoiler so as not to spoil your fun if you wanted to do this, but do feel free to look and take any code or ideas you want.

— Ken

Replies are listed 'Best First'.
Re^2: Unicode vulgar fraction composition
by raygun (Scribe) on Sep 24, 2020 at 17:28 UTC

    Thanks much, ikegami and Ken, for the additional explanations and ideas. Super helpful!

    Expanding on ikegami's explanation of why a "compatibility composition" might be ambiguous: I also see that, for instance, U+2168 ROMAN NUMERAL NINE has a compatibility decomposition into the capital letters "I" and "X," but even if no other Unicode character has that particular decomposition, that certainly doesn't mean that any "I" followed by an "X" represents the roman numeral and should thus be "compatibility composed" into it.

    So yes, I see now why the concept is fraught with peril—in general. But a string like "3\N{FRACTION SLASH}8" seems to have an unambiguous meaning that is always equivalent to U+215C VULGAR FRACTION THREE EIGHTHS. So it seems a compatibility_compose_where_it_makes_sense() function could be written. But it would require judgment calls for every possible "compatibility composition," potentially not all of which would be clear-cut, so I can see why no one's rushing to implement it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11122152]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-24 03:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found