8

I learned today that while common fractions have dedicated Unicode values, in order to form less common fractions like ³/₁₆ you have to use superscript/subscript characters followed by a slash. This is confirmed here and here.

This works for ¹¹/₁₆ and ¹³/₁₆, but it gets messed up with ¹⁵/₁₆. Do you see how the 5 rises higher than the one? I imagine this is because in order to show the number 5 clearly as a superscript, it requires more height than 1 and 3.

Well, that creates a problem. How do you display the fraction 15/16 nicely as Unicode characters? Unfortunately I can't use the sup and sub tags. I'm not displaying it in an HTML page. Rather, we're passing a string to a Java application that will then render these values. I know it renders Unicode values fine, but it wouldn't recognize HTML tags. Is there a Unicode solution?

ktm5124
  • 11,861
  • 21
  • 74
  • 119
  • 12
    *Do you see how the 5 rises higher than the one?* No, I don't. It looks fine here. It sounds like you have a font issue, not a unicode issue. – user3942918 Mar 06 '19 at 22:54
  • 5
    note that [it's better to use U+2044 ⁄ FRACTION SLASH](https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts) because some font renderers can display it properly if you use superscript and subscript before and after the slash ⁷⁄₂₃ – phuclv Mar 07 '19 at 02:11

4 Answers4

20

The “proper” way of composing arbitrary vulgar fractions in Unicode is to not use the subscript and superscript digits at all, but to utilise the special properties of the character U+2044 FRACTION SLASH. You would simply type the regular ASCII digits and separate them with the slash like so: 15⁄16. The rendering engine will then automatically select the correct forms of the numbers, producing a clean, uniform look.

I put the word ‘proper’ in quotation marks because this method is not guaranteed to be supported on all systems, and some that do support it do so incorrectly or incompletely. If you absolutely need to make sure that 100% of recipients regardless of system will definitely see something that looks more or less right, I would therefore still (begrudgingly) recommend using the preformatted subscripts and superscripts as a substitute. As the other answer explained, the problem you are having is a font issue and cannot be solved if you do not have control over font settings.

CharlotteBuff
  • 3,389
  • 1
  • 16
  • 18
  • 2
    Ok, let's say you write `1 \u2044 16` (without spaces) as an attempt to display 1/16 as a fraction glyph. How does the rendering engine know that the fraction ends after 16 and not after 1. That is, how does it know that it's 1/16 and not 1/1 followed by a 6? – ktm5124 Mar 11 '19 at 15:03
  • 3
    The fraction ends once the text renderer encounters a character that cannot be part of a fraction, i.e. something that is not an ASCII digit. – CharlotteBuff Mar 11 '19 at 15:44
  • 1
    To extend on that question, what if I want to display one and fifteen sixteenths, rather than one hundred fifteen sixteenths? Is there a unicode character I can use to separate the "1" from the "15" so that the rendering engine knows that the "1" is separate from the "15⁄16"? – M. Justin Apr 24 '20 at 15:05
  • 8
    @M.Justin Any zero-width, invisible character will do the trick. I personally prefer using U+2064 INVISIBLE PLUS because it was encoded to represent exactly this type of semantic concept, but something like U+200C ZERO WIDTH NON-JOINER or U+2060 WORD JOINER will also work. – CharlotteBuff Apr 25 '20 at 16:52
6

This is indeed a font issue, however the problem arises from the fact that, in Unicode, ¹, ², and ³ belong to the Latin-1 Supplement block, while the other superscript digits belong to the Superscripts and Subscripts block, and some font substitution occurs.

Please see Why the display of Unicode characters for superscripted digits are not at the same height? for extra details; it is tagged as iOS, but I have the same problem on macOS too.

  • 2
    So `1`, `2`, and `3` are potentially displayed in a completely different font than the rest? That would definitely lead to some consistency issues. – Mark Ransom Mar 06 '19 at 23:49
6

I found this site, Unicode Fraction Creator: https://lights0123.com/fractions/

Here's an example: ³⁄₂

Which is:

U+00B3 superscript three

U+2044 fraction slash

U+2082 subscript two

js2010
  • 23,033
  • 6
  • 64
  • 66
2

For a general answer on displaying fractions nicely, copy, paste, and change.

ASCII Characters Name hexadecimal value
Fraction Slash 8260
0 digit 0 48
1 digit 1 49
2 digit 2 50
3 digit 3 51
4 digit 4 52
5 digit 5 53
6 digit 6 54
7 digit 7 55
8 digit 8 56
9 digit 9 57

example: 1/0 =

   1⁄0