Jump to content

Module:Val/units/doc

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Cpiral (talk | contribs) at 06:08, 15 August 2015 (Defining a unit: fmt). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Val units are published at Template:Val/list, but here is where they are configured.

Just edit this page and preview with   Template:Val/list.

The common reference for a unit on the wiki is the unit code, which equates to the markup and link of a unit.

Anyone can just add a unit here, and it will work for Val. Many details are given in the next section in there order of importance.

Details

For such a simple and quick operation as editing Val units by just mimicking the existing format when you get there, there sure is a lot of information here. It has to do with professional touches like thorough testing, and adding features to the unit. Anyone can get as involved with Val units as they wish, because here are all the gory details, in order of importance.

  • You can enter any units in the "Unsorted units" section if you are not sure where else.
  • If the same unit code is defined twice on this page, the later one overrides the earlier one.
  • Entries here override Convert. Enter a unit code and a wikilink. Done.

You can alias Convert or Val units. But these are different things.

  • A "unit code alias" is when the same unit pagename and unit symbol are defined twice. Unit code aliases are an important step in defining unit codes with alternate capitalization or dimensional attributes.
  • A "unit alias" is when Val or Convert alias one the another. A unit of measurement is here denoted ALIAS to mean "they are defined there". Val defaults to Convert, but it's good to this explicit for certain Val units: the ones tempting to define here, but that you don't want defined here because, says ALIAS, they are already defined there.
  • If your unit code is not listed at {{Val/list}}, you can check for it at {{Val/unitsfromconvert}}, or at {{Convert#Units}}

Val and Convert share unit codes, but their units of measurement are different.

  • Most of the wiki's unit codes are managed by {{Convert}}. At Convert the procedure for defining a unit is much more involved than it is here, because there every unit defined must reference associated units, conversion factors, alternate spellings, and many other attributes. An entry at Convert is defined as a multi-line, multi-attribute Lua table with its attendant syntax, and inside a larger Lua script.
  • Some very few unit codes here, like C and F, mean something different there. Val caters to Coulombs and Farads, while Convert caters to Celsius and Fahrenheit. Convert and Val unit codes are mostly identical, like they are for degC and for degF.
  • Val could need any unit, while not all units are needed in conversions, so Val needs all of Convert's units and some of its own.

Customization may be a worthwhile risk.

  • Although units used in articles have definite stylistic standards, there remains room for depending on Val for markup (but see WP:Accessibility about color, link, and text).
  • You may want to customize some Val unit codes that will automate some Val markup for special articles, the talk page, etc. See WP:HTML#formatting for possibilities.
  • If you want to reorganize sections, note that the two lines local builtin_units and local builtin_units_long_scale require a blank line after them. The section long scale, with all the units like "billions" and "trillions", is under the latter, near the bottom of the page. All the rest of the units are in the former.

Defining a unit

To define a unit you edit this page and preview it with   Template:Val/list.   Preview your changes or additions before saving. That is done at the bottom of the edit box where it says Show preview. The Page title: next to Show preview should be set to the text   Template:Val/list.

Previewing this page with Val/list is different from previewing it with other pages. You can preview your new settings on any page. Val/list is a transclusion of this page, so previewing Val/list previews this page and it previews the edit box of this page, showing all changes immediately on what only seems to be another page.

A preview on Val/list is required, and previewing this module on other pages is recommended because it can prove your changes through Val, not just Val/units. Just run another Show preview on the fullpagename that uses Val with your modified unit code entry. If that fullpagename also has your Val unit code in a sortable table, this is a plus for a test through Val.

To maintain Module:Val/units:

  1. Edit this page.
  2. Make your changes or additions. The format is explained below.
  3. Show preview with   Template:Val/list   and view your changes. An "invalid definition" message is available automatically. Visit the link to the unit pagename, and return back in your browser.
  4. Make any further changes, and Show preview again.
  5. Show preview on any other fullpagename with the Val call on it.
  6. Show changes, and then save your changes to this page.

Before changing or removing any Val unit codes, you can check to see how unit codes may or may not be in use on the wiki by employing {{Template usage}}. For example, to see about changing or removing unit code J.s, do a {{tlusage|val|"J.s"|0}}hastemplate:"val" insource:/\{\{ *[Vv]al *\|[^}]*"J.s"/ prefix::. (Put the unit code in quotes.)

Testing a new unit

To test a newly added unit not used on any page, you will need to run the preview on a sandbox page you have already created. Here are all the test cases you can preview there before saving your changes here; they are the four |u= parameters:

{{Val|9|u =            }}
{{Val|9|ul =           }}
{{Val|9|u=foo|up =     }}
{{Val|9|u=foo|upl =    }}

and the sortable table:

{| class="wikitable sortable" summary="Sortable table to test Val sorting"
! Val number and unit
|-
| {{val|5|u=      }} 
|-
| {{val|3|u=      }} 
|-
| {{val|1|u=      }} 
|-
| {{val|2|u=      }} 
|-
| {{val|4|u=      }} 
|}

If your unit accepts an SI prefix you can test, say, k, m, and G, with your unit, and compare with e notations 1e3, 1e6, and 1e9 in the number. For example, Val sorts these two as equal: 1e3 m (standard e notation) and 1 km.

What to look for
  • The linked and non-linked markup should look exactly the same.
  • Navigate to the new link. It is safe: you can go back in your browser to here.
  • The two |up= versions should have no space in front of them.
  • For SI prefixes sorting 2e3 (or 2000) should be greater than k (kilo prefix).

Format of the config file

An entry defining a unit for Val is a single line starting with the unit code, followed by at least two spaces, and then a wikilink:

code    [[pagename|symbol]]

The wikilink must supply the pagename and the unit symbol. (Unlike other wikilinks, this one accepts no templates at all, such as {{subsup}}.)

Also this line is a recognized entry format:

code    symbol        pagename

Both of these lines are equivalent and contain the same three elements (although note the difference in their order):

unit code
Unit abbreviation. Composite units have dimensions, and use a dot . to multiply or a slash / to divide and a -1 to divide (or greater) to divide powers.
unit pagename
Title (or section) of an article.
unit symbol
Standard abbreviation. The symbol is either a simple abbreviation or contains Wikipedia HTML formatting for superscript, or subscript, the multiplication dot, etc. (Templates cannot be applied here.) Always use abbreviation tags to indicate the full name of the unit. (The full name of the unit can also be hover-text via a redirect, but prefer the tag.)

You can add unit-code aliases for:

  • capitalization: unit codes are case sensitive
  • divisor units: the -2 version for inverse squared, etc., so we end up with both the slash a/b and inversion ab-1 forms. For example when adding a unit like m/s, add the m⋅s−1 version as well.
  • multiplier units: consider using the * version as well as the . version.

The entry is ignored if it lacks at least two adjacent space characters. The second format also takes tabs in the second delimiter in order to help with the greater need for alignment there.

Flags

The module must be told directly about sorting factors, spacing, and aliasing for a unit code.

At the end of an entry, after the given unit pagename plus a tab character or two or more spaces, any of several indicators may be placed. This works for either of the two entry formats.

For spacing and aliasing:

  • ALIAS specifies that the unit's symbol is the code for a unit defined in {{convert}}}.
  • NOSPACE prevents the default insertion of a non-breaking space before the unit symbol.

If you see the ANGLE flag, this identifies those special units that must displayed after the number and uncertainty values.(ANGLE also implies NOSPACE.)

The other two indicators are for sorting.

Sorting

Where Sorting is done on the wiki, it is done in sortable tables. (Sorting functionality is handled for Val by {{convert}}.)

If a physical unit of measurement needs to be sorted, there is an indicator of this at the end of the entry. If the indicator is SI, that means to look at the unit code for the SI prefix, and apply that to the unit's number.

If the indicator is a number, (instead of "SI"), it is for "units" that are just a name or number (not a physical unit of measurement). That number is applied to the unit's associated number, such as the the "30" of "{{val|30|ul=billion}}".

Scale

A number that sets the sorting scales for the unit code may be entered following the link. For example, the following defines a unit with code billion, symbol billion, link 1,000,000,000, and scale 1e9 (1×109). After the following entry is saved to the database

billion            billion          1,000,000,000          1e9

{{val|2|u=billion}} would start sorting after {{val|98.7|e=3}}.

SI

Prefix Symbol Factor Power
tera T 1000000000000 1012
giga G 1000000000 109
mega M 1000000 106
kilo k 1000 103
hecto h 100 102
deca da 10 101
(none) (none) 1 100
deci d 0.1 10−1
centi c 0.01 10−2
milli m 0.001 10−3
micro μ 0.000001 10−6
nano n 0.000000001 10−9
pico p 0.000000000001 10−12

A unit code may be flagged with the SI designation. which means that the unit code begins with an SI prefix.

If the unit you are maintaining has SI prefixes and is likely to be sorted in a table, add up to twelve entries, one for each SI unit. Some of these may have there own article, but usually all go to the base unit's pagename. Here is how meter is defined. Note that the base unit does not need the SI sort-marker.

m                  m                     Metre
cm                 cm                    Centimetre         SI
dam                dam                   Decametre          SI
dm                 dm                    Decimetre          SI
hm                 hm                    Hectometre         SI
km                 km                    Kilometre          SI
Mm                 Mm                    Megametre          SI
mm                 mm                    Millimetre         SI
mum                µm                    Micrometre         SI
µm                 µm                    Micrometre         SI
nm                 nm                    Nanometre          SI
pm                 pm                    Picometre          SI

For example, the following sets kV to sort in a table., base symbol V, and link Volt. The symbol V refers to the base unit with the SI prefix removed. A unit defined in this manner will have its sort key scaled by convert according to the SI prefix: for example, {{val|1|u=kV}} would sort after {{val|999|u=V}}.

kV  [[Volt|V]]  SI

Alias a Convert unit

If you are here to change the link or markup of a unit, but it is not listed at Val/units, sometimes you can find the unit markup and link that you do want, already existing at Template:Convert#Units. In that case you can change the unit code to whatever you'd prefer, and it will achieve your goal. For example, if {{Val|1|C}} is going to Celsius instead of Colombs, you can define your own unit code, say "degC".

The following defines degC to refer to the unit known as °C in convert. There is no link because a link is defined at Convert.

degC               °C               ALIAS

Examples

See Template:Val/list for examples.

Say you are adding c0, the speed of light in a vacuum, for example. The following entry will define your unit code as c0, your unit symbol as ''c''<sub>0</sub>, and the unit's article as Speed of light#Numerical value, notation, and units.

c0  [[Speed of light#Numerical value, notation, and unit symbol|''c''<sub>0</sub>]]

or

c0  ''c''<sub>0</sub>      Speed of light#Numerical value, notation, and units

Then preview with Template:Val/list , check for an error message next to the new unit, and test the link you gave.

After that the page with the (saved) Val calls is used to test the linked and non-linked versions of the normal and the per units:

For an entire example:

  1. Put this in a sandbox: {{val/sandboxlua|1.23|ul=wocky}}Template:Val/sandboxlua
  2. Edit Module:Val/units and insert a line like the following (do not save yet):
    wocky   wocky   Jabberwocky
  3. Under "Preview page with this module" enter Template:Val/list, and click Show preview. It shows all of Val/units in the Val/list format, as it will become when you save this page. Say there are no errors, the markup looks good, and the link navigates to the best explanation of the unit.
  4. Then in the same way of previewing, put the fullpagename of the sandbox from step 1, and click Show preview. It shows the whole page including the val under test.
  5. If wanted, click "Save page" to save the edit to Module:Val/units.

If you want a unit to add for practice, add one from List of common physics notations, or from SI units#Units and prefixes.

There are many examples of composite units that have their own page, so adding a unit code for one of those should link to its page.

For a new composite unit you should probably link the whole composition, not individual parts of it. At least link the largest portion which could have its own page.

  • The val user can compose a divisor unit on the fly from existing unit codes, and with individually linked numerator and denominator. For example:
{{val|99|ul=m|upl=d}}99 m/d
  • The val user can compose a multiplier unit on the fly by using the |end= parameter to prepend to the unit, and these can also be individually linked. For example (in geology) there is already 333 14C yr BP to use with |end=:
{{val|333|ul=uBP|end=&nbsp;[[megaannum|Ma]]}}333 Ma 14C yr BP".

For example Val/units says

m.s-1  [[Metre per second|m&sdot;s<sup>&minus;1</sup>]] linking to an article titled Metre per second, not

m.s-1  [[Metre|m]]&sdot;[[Second|s]]<sup>&minus;1</sup> which has separate links to already existing unit codes.