Template:Val/doc: Difference between revisions

From Zoophilia Wiki
Jump to navigationJump to search
meta>Cpiral
(→‎How to add units: ce, + paragraph about up and upl)
meta>Cpiral
(→‎How to add units: ce: formatting, word-choice, add an example, remove unnecessary self-refs, clean-up)
Line 102: Line 102:


==How to add units==
==How to add units==
The unit is required to have a link version and a non-linked version for stylistic reasons (including the ability of editors to avoid [[WP:OVERLINKING|overlinking]]).  The linked version will be implemented by ''{{tl|Val/unitswithlink}}'' (processing Val's "ul=" and "upl=" parameters).  The non-linked version may or may not need to be implemented by ''{{tl|Val/units}}'' (processing Val's "u=" and "up="parameter); it depends on whether or not the unit wants any special [[Help:Wiki markup#Format|markup]]: if the characters given to the ''ul'' or ''u'' [[m:Templates#Parameters|parameter]] are same as what is rendered, then you can skip the last step.
The unit is required to have a link version and a non-link version for stylistic reasons (including the ability of editors to avoid [[WP:OVERLINKING|overlinking]]).  The link version will be added to '''''unitswithlink''''' to process the <code>ul</code> and <code>upl</code> parameters.  The non-link version ''might'' need to be added to '''''units''''' to process the <code>u</code> and <code>up</code> parameter; it depends on whether or not the unit needs [[Help:Wiki markup#Format|markup]]: if the characters users will give to the <code>ul</code> or <code>u</code> [[m:Templates#Parameters|parameter]] are the same characters as what are rendered, then you don't need to edit '''''units'''''.


Before creating a complex unit with numerator and [[denominator]], note that users can construct ''there own'' unit from existing simpler units, to achieve the formatting and spacing advantages val offers:  <nowiki>{{</nowiki>val|3|e=7|ul=W|'''upl'''=m2}}, which renders {{val|3|e=7|ul=W|upl=m2}} uses the existing val unit "W" to link to ''[[Watt]]'', and the existing val unit "m" to link to ''[[Meter]]''. But for linking this "Watts per meter squared" to its meaning at ''[[Intensity (physics)]]'' using a single parameter, say <code>Wm-2</code> (for ''u'' or ''ul''), you may need to add the unit.  (See ''[[List of common physics notations]]'' for other examples.)  
Linking is important. Before creating a [[unit of measurement|unit]] having "numerator '''per''' [[denominator]]", note that Val users can construct ''their own'' unit fraction from existing simpler units (by using <code>upl</code>):  <nowiki>{{</nowiki>val|33|ul=W|'''upl'''=m2}}, which renders as {{val|33|ul=W|upl=m2}}, has two links: one to ''Watt'', and one to ''Square meter''. Now to link "Watts '''per''' meter squared" to ''Intensity (physics)'' with the user code, say "<code>ul=Wm-2</code>", then you add <code><nowiki>Wm-2=[[Intensity (physics)|W·m{{sup|&minus;2}}]]</nowiki></code> to '''''unitswithlink''''' and <code><nowiki>Wm-2=W·m{{sup|&minus;2}}</nowiki></code> to '''''units'''''.  (See ''[[List of common physics notations]]'' for other examples.)


The technique should involve activating '''[[WP:Show changes|Show changes]]''' in order to find-out any inadvertent changes.
The technique involves activating "'''[[WP:Show changes|Show changes]]'''" in order to display any unintended changes.  The sorting and grouping of the data is unimportant.  Note the needed "|" symbol, and stay inside the header and footer.
# Edit {{tl|Val/unitswithlink/test}}.  The [[Sides of an equation|LHS]] of the "=" sign is what users will give to the ''ul'' (and ''upl'') parameter. [[WP:Show preview|Preview]].  Because ''Val/unitswithlink/test'' data is process through ''Val/unitswithlink'' the preview is the same test as running val itself in a sandbox. Prove the intended markup and link for your newly added unit, show changes, and save the change.   
# Edit {{tl|Val/unitswithlink/test}}.  The [[Sides of an equation|LHS]] of the "=" sign is what users will give to the <code>ul</code> (or <code>upl</code>) parameter. Because '''''unitswithlink/test''''' data is process through '''''unitswithlink''''' [[WP:Show preview|a preview]] is similar to running val itself in a sandbox. Show preview. [[Wikipedia:TESTLINK|Prove the intended link]] and markup.  Show changes.  Save the page.   
# Edit {{tl|Val/unitswithlink}}.  Provide the wiki with the identical entry proven in step 1.  Show changes.  Save the change.
# Edit {{tl|Val/unitswithlink}}.  Provide the wiki with the identical entry proven in step 1.  Show changes, and save.
# Edit {{tl|Val/units}}, but only if the unit required markup. The RHS of the "=" sign has no [[help:wikilinks|wikilinks]], it has only markup, including using templates that supply the markup. Provide the proven unit, show changes, and save the change.
# Edit {{tl|Val/units}}, but only if the unit required markup. The RHS of the "=" sign has no [[help:wikilinks|wikilinks]], it has only markup or templates that supply markup. Provide the proven markup, show changes, and save.


You can then verify a ''u'' and a ''ul'' instance of val, side by side in a [[WP:sand|sandbox]].  They should render the same characters for the unit, and ''one should supply a plain unit without the link''
You can then verify a <code>u=</code> and a <code>ul=</code> instance, side by side in a [[WP:sand|sandbox]].  These should render the same, except ''one should supply a plain unit without the link''.
 
Note that sorting and grouping of the data you are editing does not matter.
The whole file becomes an instant blob of data for the template.


== See also ==
== See also ==

Revision as of 06:08, 15 October 2012

Purpose

This template is used to easily present values in scientific notation, including uncertainty and/or units, as prescribed by Wikipedia's Manual of Style. It wraps the entire result in a {{nowrap}} block, so that it never gets broken into separate pieces at the end of a line. (See WP:NBSP for more information on the usage of non-breaking spaces.)

Arguments

There are four ways this template can be used:

  • {{val|number}} - for displaying values without uncertainty/significance.
  • {{val|number|uncertainty}} - for displaying values with uncertainty like so 1234±56.
  • {{val|number|upper uncertainty|lower uncertainty}} - for displaying values with uncertainty like so 1234+56
    −78
    .
  • {{val|number|(significance)}} - for displaying values with significance like so 1234(56).

They all take roughly the same arguments

1 The value (must be a valid number)
2 The (upper limit of) uncertainty (must be a valid number) or significance (must be a valid number in parenthesis)
3 The lower limit of uncertainty (must be a valid negative number)
e The exponent for the power of 10 (optional). This will show up in the result as " × 10e
".
Values (arguments 1-3 and e) are run through code copied from {{delimitnum}} for readability, except for argument 2 when it is surrounded by parenthesis. This currently causes an error for large numbers, numbers that require high precision and numbers that have zeros after the decimal point. This last issue is being addressed, the other issues require changes to the Wikipedia software.
u / ul Activate units and their formatting and spacing / with a link to a page about the unit (optional / optional)
up / upl Construct units, and this is the "per" unit that is the denominator / with a link to a page about the denominator (requires numerator from u or ul)
Units for the number, specified by u and ul (and up and upl), are replaced by a more aesthetically pleasing HTML representation and can get a link (ul and upl only) if they are in the list found in {{val/unitswithlink}} or if they are supported by {{convert}}). You can specify units using just u; a good example is "ul=m/s", which gets translated to "m·s-1", or you can use u and up, as in "u/up"; a good examples if "ul=m|up=s", which gets translated to "m/s".
p A prefix for the value (such as ∆, ⌀, etc.; optional).
s A suffix for the value (such as %, optional).
Prefixes (specified by p) and suffixes (specified by s) are put in front of or behind the value as is: this includes spaces. They are inside the nowrap block and will always be on the same line as the value. The parameters that previously provided this functionality (h for header and f for footer) are deprecated and will be ignored.
end Appends something after the main value. For example, {{val|123.24|end=...}} gives 123.24...
errend Appends something after the uncertainty. For example, {{val|123.23|end=...|2.34|errend=...}} gives 123.23...±2.34...
+errend & -errend Appends something after the positive/negative uncertainties. For example, {{val|123.23|end=...|+2.34|+errend=...|-1.23|-errend=...}} gives 123.23...+2.34...
−1.23...
nocategory If set to any value, errors in the use of this template will not cause the page to be added to the Pages with incorrect formatting templates use category. This is useful for documentation and test pages that do not need to be fixed.

See {{val/test}} for a list of examples of the correct output of {{val}} and the errors it may return when incorrectly used.

Errors

There is strict checking on the validity of arguments; any incorrect use will result in an error, which is displayed using {{FormattingError}}. Pages that contain incorrect use of this template will show up on Category:Pages with incorrect formatting templates use.

Format convention

As mentioned before, {{val}} should produce formatting compliant with Wikipedia's Manual of Style. It currently produces formatting compliant with the U.S. Government Printing Office Style Manual, in rules 12.9e and 12.14, which requires that the decimal separator be a full stop; i.e. “decimal point” (.), requires comma-delimiting to the left of the decimal point for numbers with four or more digits to the left (values of 1000 or more), and also requires space-delimiting to the right of the decimal point for numbers containing five or more digits to the right (e.g., 0.12345 and 5.12345 and 125.12345).

Note that if {{val}} is used on numbers simultaneously comprising four or more digits to the left of the decimal point and five or more digits to the right, the resultant expression will delimited with commas left and spaces (actually non-selectable, non-breaking, narrow gaps) right (see below).

Examples

{{val|1234567890}}  →  1234567890
{{val|1.23456789}}  →  1.23456789
Template:Xpdop3c
Uncertainty/significance
{{val|1.234|0.005}}  →  1.234±0.005
{{val|1.234|+0.005|-0.006}}  →  1.234+0.005
−0.006
{{val|1.234|(5)}}  →  1.234(5)
Exponents/units
{{val|1.234|e=5|u=m}}  →  1.234×105 m
{{val|1.234|e=5|u=m2}}  →  1.234×105 m2
{{val|1.234|e=5|ul=m}}  →  1.234×105 m
{{val|1.234|0.056|e=7}}  →  (1.234±0.056)×107
{{val|1.23456|+0.00007|-0.00008|e=-9|ul=m/s}}  →  1.23456+0.00007
−0.00008
×10−9 m/s
{{val|1.234|0.056|e=7|ul=psi}}  →  (1.234±0.056)×107 psi
{{val|123.4|ul=USgal}}  →  123.4 US gal
{{val|12.34|ul=mpgimp}}  →  12.34 mpgimp
Prefix/suffix
{{val|p=Δ&nbsp;|12.34|s=%}}  →  Δ 12.34%
Numerator/Denominator
{{val|1.234|e=7|ul=W|up=m2}}  →  1.234×107 W/m2
More examples
See the testcases at Val/test.

Performance impact

For most uses, in the text of articles, Template:Val will not restrict performance, but when used inside the wikitext markup of large templates, there are some restrictions. When displaying integer amounts, Template:Val has an internal expansion depth of 15 levels, but for numbers with decimal portions, it uses 22 levels, or more.

How to add units

The unit is required to have a link version and a non-link version for stylistic reasons (including the ability of editors to avoid overlinking). The link version will be added to unitswithlink to process the ul and upl parameters. The non-link version might need to be added to units to process the u and up parameter; it depends on whether or not the unit needs markup: if the characters users will give to the ul or u parameter are the same characters as what are rendered, then you don't need to edit units.

Linking is important. Before creating a unit having "numerator per denominator", note that Val users can construct their own unit fraction from existing simpler units (by using upl): {{val|33|ul=W|upl=m2}}, which renders as 33 W/m2, has two links: one to Watt, and one to Square meter. Now to link "Watts per meter squared" to Intensity (physics) with the user code, say "ul=Wm-2", then you add Wm-2=[[Intensity (physics)|W·m{{sup|−2}}]] to unitswithlink and Wm-2=W·m{{sup|−2}} to units. (See List of common physics notations for other examples.)

The technique involves activating "Show changes" in order to display any unintended changes. The sorting and grouping of the data is unimportant. Note the needed "|" symbol, and stay inside the header and footer.

  1. Edit {{Val/unitswithlink/test}}. The LHS of the "=" sign is what users will give to the ul (or upl) parameter. Because unitswithlink/test data is process through unitswithlink a preview is similar to running val itself in a sandbox. Show preview. Prove the intended link and markup. Show changes. Save the page.
  2. Edit {{Val/unitswithlink}}. Provide the wiki with the identical entry proven in step 1. Show changes, and save.
  3. Edit {{Val/units}}, but only if the unit required markup. The RHS of the "=" sign has no wikilinks, it has only markup or templates that supply markup. Provide the proven markup, show changes, and save.

You can then verify a u= and a ul= instance, side by side in a sandbox. These should render the same, except one should supply a plain unit without the link.

See also

  • {{Valid}} : number validity checking (for parameters 1, 2, 3, e : value, and uncertainties, base-10 exponent)
  • {{FormattingError}} : for reporting inconsistent parameters
  • {{Val/delimitnum}} : for formatting a decimal number with delimiters between groups of digits
  • {{Su}} : for formatting exponents, or two-values incertainty one below the other (monospaced : currently not printable to PDF)
  • Template:T1 : for positive <sup> and negative <sub>
  • {{Val/units}} : for formatting unit names (contents of parameters u or up)
  • {{Val/unitswithlink}} : for formatting unit names with links (contents of parameters ul or upl)