Template talk:Fraction

(Redirected from Template talk:Frac)

Signing (plus or minus)

edit

Why does the Documentation section say "the optional integer (may be signed)" when it appears that all three arguments can be given a sign (which is displayed as expected)? Spel-Punc-Gram (talk) 22:45, 18 April 2024 (UTC)Reply

This template is rather simple and is just taking whatever inputs you give it and turning them into superscripts and subscripts. It does not actually understand the inputs. Eg, {{fraction|this|is|{{pi}}}} gives this+isπ . Be careful not to confuse the intent of the template (what we want it to do) with the current implementation of the template (what it actually does at the moment that might change in the future).  Stepho  talk  23:00, 18 April 2024 (UTC)Reply

Why is this still being used for common fractions?

edit

Okay, in 2024 are there really any browsers in use that can't display ½ or ¼? Can we make those fractions, at least, point to the characters? Chowbok 02:27, 20 April 2024 (UTC)Reply

MOS:FRAC has the guidelines. Using this template is not required in all circumstances. It would probably not be desirable for this template to output one style for a third and a different style for a half. If ½ is wanted (and MOS:FRAC applies), just type that. Johnuniq (talk) 03:04, 20 April 2024 (UTC)Reply

Need to improve legibility: add a NNBSP between the integer and the fraction?

edit

At template talk:convert#More readable fractions, user:71.230.16.111 asked

Using the fraction function such as 7 centimetres (2+34 in) with some browsers results in hard-to-read small font for the integer of the conversion as well as the fraction numerals. (The only difference is a different vertical position between the integer and numerator. The input value shows correctly in regular font.) Is there a work around to make it more browser-agnostic? Or at least to add whitespace between the integer & the fraction to make the result more readable?

In 2+34, for example, the 3 is uncomfortably close to the 2, for visitors with medium sight impairment. If a U+202F NARROW NO-BREAK SPACE were to intervene, (as in 234) I think it might be enough to help these users without upsetting regular uses too much. Although U+2009 THIN SPACE or U+200A HAIR SPACE might be better?

Comments? 𝕁𝕄𝔽 (talk) 10:27, 21 October 2024 (UTC)Reply

An example at the link above shows the identical output from {{frac|2|3|4}} and {{convert|7|cm|frac=8|disp=number}}. Following shows what it looks like, and the output wikitext:
2+34
<span class="frac">2<span class="sr-only">+</span><span class="num">3</span>&frasl;<span class="den">4</span></span>
The magic is done in Template:Fraction/styles.css. The + stuff means that (on many browsers) a copy/paste of the fraction generates 2+3⁄4 which is actual 2+3/4 except the slash is a fraction slash which makes many browsers display a fraction. Johnuniq (talk) 10:55, 21 October 2024 (UTC)Reply
Do you mean the browser "helpfully" converts it to U+00BE ¾ VULGAR FRACTION THREE QUARTERS? Oh wonderful. So is it fixable here then? 𝕁𝕄𝔽 (talk) 13:37, 21 October 2024 (UTC)Reply
I know very little about this topic but I suspect some MOS and accessibility issues have led to the current situation. Izno might like to comment on whether there should be a small space after the integer, or whether some alternative using fraction slash would be preferable. Johnuniq (talk) 20:55, 21 October 2024 (UTC)Reply
I see no problem with adding a space, that's something for math nerds to review. I'm not sure it's worth doing solely on the basis of "some browsers"; Firefox displays things fine for someone who isn't a math nerd. I think it's preferable to use the fraction slash to some other kind of slash. No, I don't think it turns the characters into U+00BE, there are 3 separate things I can highlight (num, den, slash) whereas the Unicode is a single character. Izno (talk) 21:05, 21 October 2024 (UTC)Reply
If nerds decided a space was wanted, is that something that could/should be done in Template:Fraction/styles.css? Johnuniq (talk) 21:34, 21 October 2024 (UTC)Reply
You would need to modify the core template (and any copies thereof floating around like in convert) to emit a new class at the top level for when there is an integer, and then sure, you could do it in CSS. The alternative change being insertion of the suggested non-breaking space, I'd probably prefer CSS since that will copy-paste nicer for arbitrary people. Izno (talk) 21:58, 21 October 2024 (UTC)Reply

Parentheses for clipboard copying and stylesheet-less browsers

edit

Currently when you flatten Δt - Δb/Δi by copying it to a clipboard, you get an inaccurate Δt - Δb/Δi. This is very likely how people on browsers without such fancy CSS support (or screen readers!) perceive uses of this template. It would be nice to add invisible parentheses so it instead copies as (Δt - Δb)/(Δi).

Replace the entire content of Template:Sfrac with:

{{ {{{|safesubst:}}}#invoke:Unsubst||$B=<templatestyles src="Sfrac/styles.css" /><span class="sfrac">&NoBreak;{{#if:{{{3|}}}|{{{1}}}<span class="sr-only">+</span>}}<!--
 --><span class="tion" {{#if:{{{font-size|}}}|style="font-size:{{{font-size}}}"}}><!--
  --><span class="sr-only">(<!--
  --><span class="num">{{#if:{{{3|}}}|{{{2}}}|{{#if:{{{2|}}}|{{{1}}}|1}}}}</span><!--
  --><span class="sr-only">)/(</span><!--
  --><span class="den">{{{3|{{{2|{{{1|1}}}}}}}}}</span><!--
  --><span class="sr-only">)<!--
 --></span><!--
-->&NoBreak;</span>}}<noinclude>
{{documentation}}
<!-- Add categories to /doc subpage, not here. -->
</noinclude>

A similar edit may be justifiable for Template:Fraction. Artoria2e5 🌉 13:08, 21 April 2026 (UTC)Reply

 Not done: please make your requested changes to the template's sandbox first. See WP:TESTCASES. P.I. Ellsworth, ed.  welcome!  14:13, 23 April 2026 (UTC)Reply