Module:Val/units/doc explained

The list of Val units is published at, and here is the place that produces that report. So preview from the edit box to see your changes before saving them. The file format and syntax are mostly self explanatory.

Questions or requests related to Val units are welcomed at . For feedback specifically about the terminology or procedural steps seen on this page, please use the talk page.

Below are the detailed procedures, examples, descriptions of testing and previewing, explanations about sorting Val expressions, and links to helpful pages. There's also further information about Val/Convert relations.

Introduction

An entry defining a unit for Val is a single line under a section heading.[1] It starts with the unit code, followed by at least two spaces and a link. If you are adding a group of related units, you can enter a blank line around them to group them in the report at Val/list. An entry is ignored if it lacks at least two adjacent space characters.

code[<nowiki/>[ ''pagename'' | ''symbol'' ]]

unit code
  • The keyboard typeable name of the symbol that users give Val's,, or parameters.
    unit pagename
  • Title or section of an article. When linked with ul or upl, the title or one of its redirects can expand the abbreviation for the unit.[2]
    unit symbol
  • Verifiable, standard symbol, formatted in accordance with .
    unit code alias
  • The same unit/pagename/symbol, but by way of a different unit code.
  • Unit code aliases are commonly applied for
    Preview page with this template/module
  • A feature, similar to a sandbox and testcases, that provides a preview of how the code currently in the edit box (sandbox) will look when applied to any page (testcases).

    The preview of main interest is Template:Val/list[3], but previewing other your own page of interest with your newly added unit in a val call and in a sorting table are also part of this procedure.

    How to add a unit

    To maintain Val units,

    1. and make your changes.
    2. Preview .
      • Look for any messages. An "Invalid definition" message is available automatically.
      • Prove the intended link from the preview.
      • Hover the mouse over the link, and read the hover-text or URL display somewhere in the browser.
    3. Add any unit-code aliases.
    4. Add any sorting if needed. Details about sorting are covered below.
    5. Preview a test page. It will have template Val calls on it, and it may have a sortable table to test sorting.
    6. Show changes to prove no accidental edits occurred.
    7. Save the page. Saving the page activates the changes immediately, and they go live. You're done adding your unit.

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

    Changing or removing existing unit codes is possible by employing to see how Val unit codes may or may not be in use on the wiki. For example, to see about changing or removing unit code J.s, do a

    . Put any unit code in quotes if it contains dash, dot, or slashanything but a letter or number.

    Examples

    Say you're creating a new page or revamping an old page, and discover the need for a convenient way to make several entries containing c0, and link that symbol to the page Speed of light. 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.

    c0Speed of light#Numerical value, notation, and unit symbol''c''<sub>0</sub>or as explained below at §Advanced unit entry formats, you can also write

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

    Then preview with Template:Val/list, and 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 that uses the other format to make a Val/unit entry.

    1. Put this in a sandbox:
    2. Edit and insert a line like the following (do not save yet):

    tinstinsContins unities

    1. Under "Preview page with this module" enter Template:Val/list, and click Show preview. It shows Val/list through the version of Val/units in the edit box. Say there are no errors, the markup and hover-text look good, and the link navigates to the unit's page.
    2. Then in the same way of previewing, put the fullpagename of the sandbox from step 1, and click Show preview.
    3. 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. There are many articles that could use a new Val unit, such as molarity at Resveratrol.

    Either of the test pages of these examples could have the sortable test-table shown in the next section.

    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 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=      }} 
    |}
    

    This table falls into place unsorted, so when 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:

    Advanced unit-entry format

    In the usual format

    ''code''{{spaces|4}}[<nowiki/>[''pagename''|''symbol'']]

    the wikilink represents two fields itself, for a total of three fields per entry.But you cannot use a wikilink for composite units that need more than one pagename.

    The other record type for adding a unit entry is also three fields. It has the same three fields, but they are in a different order.

    ''code''{{spaces|4}}''symbol''{{spaces|8}}''pagename''This format separates each field with whitespace, and also takes tabs between fields two and three.

    For a new composite unit you should probably link the whole composition, or link the largest portion which could have its own page.

    ".

    For example says m.s-1&nbsp;&nbsp;'''{{big|[<nowiki/>[}}'''Metre per second|m&amp;sdot;s&lt;sup>&amp;minus;1&lt;/sup>'''{{big|]<nowiki/>]}}''' linking to an article titled Metre per second, not

    m.s-1&nbsp;&nbsp;'''{{big|[<nowiki/>[}}'''Metre|m'''{{big|]<nowiki/>]}}'''&amp;sdot;'''{{big|[<nowiki/>[}}'''Second|s'''{{big|]<nowiki/>]}}'''&lt;sup>&amp;minus;1&lt;/sup> which has separate links to already existing unit codes.

    Fourth field flags

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

    There is an optional field that goes at the end after two or more spaces or one or more tabs. It is a flag mainly used to provide for that unit to be sorted in a table. Flags are mainly for sorting, and they work for either record type. Just add two or more spaces, or one or more tabs, and then the flag field. (Optional flags ALIAS and NOSPACE and ANGLE are for even more advanced users. See §Advanced unit flags below.)

    Using SI requires that the unit symbol compare precisely to the unit code, and so never allows HTML or other characters in the symbol. Any difference between the unit symbol and unit code must be an SI prefix, such as k, M, or G.

    Sorting

    Val's sorting scale factor is for comparison to other Val units that might be sorted with it.

    Where Sorting is done on the wiki, it is done in sortable tables. Val entries in a sortable table will need a fourth field sorting flag. It can be a number, an equation, or an SI, but it flags the same function: a wikitable sorting "scale".

    To display the sort key use . For example

    999 µV 99 V 1 kV

    Scale

    For scaling a unit to sort properly, you need to pick a number for a sorting factor. There are numerous examples at . A system of units will have its base units, for example 1 bit; then the scale for sorting a kilobyte unit is then 8000 (eight bits per byte, times a kilo, or thousand). Or a year scale is seconds so that all times sort by seconds, which is a base unit. In general the scale shows to be "base unit" of the same type times the "SI prefix", and if it's not that simple, then the unit system's number has associated a number to it, such as Avogadro's number.

    For example, the following defines a unit with code billion, symbol billion, link 1,000,000,000, and scale 1e9 . 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 flag

    SI is used because it scales Val expressions automatically, and it is a clean indicator that the unit will sort properly. It correctly scales any SI prefix for sorting, but not other unit codes.

    For SI the unit symbol will not accept HTML, but will accept μ. HTML is not accepted at this time because in order to validate the entry, the unit code must differ from the unit symbol by exactly one valid SI prefix. If there is no difference, or too much difference, it is an invalid definition for sorting purposes. The exception is for the Greek letter μ: if you used a character input application to "install" the Greek letter &mu; in your symbol, for your "easy to type" unit code,, these two are not a character mismatch.

    All unit entries that use SI will have the same base unit as the symbol at Val/units, but they will display properly at Val/list.

    For example, kilo is a thousand, but you're defining km2 for kilometers squared, and need HTML. You can't use SI with HTML, so use 1000*1000, or 1000000 in the sorting field. Use 1e-6 or 0.000001 or 1/100000 instead.

    If the unit you are maintaining has SI prefixes and they are all likely to be sorted in a table, add up to twelve entries, one for each common SI unit. Some of these, like Meter in the example, may have their own article, but usually all go to the base unit's pagename. Here is how meter is defined.

    m     [[Metre|m]]         SI
    cm    [[Centimetre|m]]    SI
    dam   [[Decametre|m]]     SI
    dm    [[Decimetre|m]]     SI
    hm    [[Hectometre|m]]    SI
    km    [[Kilometre|m]]     SI
    Mm    [[Megametre|m]]     SI
    mm    [[Millimetre|m]]    SI
    um    [[Micrometre|µm]]   1/1000000
    µm    [[Micrometre|m]]    SI
    nm    [[Nanometre|m]]     SI
    pm    [[Picometre|m]]     SI
    

    The information that was in the unit symbol is now fully specified in, and exhibited at, the unit code. SI specifies that the unit's symbol has been transformed from a symbol to a string for use in string comparison that will finally result in calculating a sorting factor. It conveniently uses the idea that the unit code is often equal to the symbol, especially with SI units. The field definitions are sacrificed for a simplicity in the user presentation, user calculation, and user entry.

    In the other format, the following defines three unit codes for volts, V for sorting. V is the base unit with the SI prefix removed. A unit code defined in this manner will have its sort key scaled by the software according to the SI prefix produced by the difference between the unit code and unit symbol.

    kV&nbsp;&nbsp;&nbsp;V&nbsp;&nbsp;&nbsp;Kilovolt&nbsp;&nbsp;&nbsp;&nbsp;SI

    µV&nbsp;&nbsp;&nbsp;V&nbsp;&nbsp;&nbsp;Microvolt&nbsp;&nbsp;&nbsp;SI

    uV&nbsp;&nbsp;&nbsp;V&nbsp;&nbsp;&nbsp;Microvolt&nbsp;&nbsp;&nbsp;SINow {{val|1|u=kV}} will sort after {{val|999|u=V}} without having to resort to using a number, and with the clean representation at Val/list.

    The symbol column shows "V" for each, but it is not the symbol—it is the base unit after removing the SI prefix so convert can work out what is intended to be the prefix. The following would give identical results:

    kV&nbsp;&nbsp;&nbsp;kV&nbsp;&nbsp;&nbsp;Kilovolt&nbsp;&nbsp;&nbsp;&nbsp;1e3

    µV&nbsp;&nbsp;&nbsp;µV&nbsp;&nbsp;&nbsp;Microvolt&nbsp;&nbsp;&nbsp;1e-6

    uV&nbsp;&nbsp;&nbsp;µV&nbsp;&nbsp;&nbsp;Microvolt&nbsp;&nbsp;&nbsp;1e-6As you can see, without "SI", you define both the symbol, and the scale. You define the symbol with HTML or the Greek letter or other symbol, and you define the scale with a number or an equation. When "SI" is used, convert just does the right thing for the symbol and scale.

    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 . In that case you can change the unit code to whatever you'd prefer, and it will achieve your goal. For example, if is going to Celsius instead of Coulombs, 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
    

    File format

    If you want to reorganize sections here, 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.

    The file format is two Lua strings and a return statement with them in it: a string in quotes [=[ ... builtin_units ... ]=], and another string in quotes [=[ ... builtin_units_long_scale ... ]=]. The first string, builtin_units, is short-scale, second string is long scale. The reason there are two strings is because of the difference between British and US terms surrounding "billion", "billionth", etc.

    For each string there must be a blank line before the first line of the string and after the last line of the string. In other words the first two and last two characters of each string must be newlines.

    There is one record per line, starting in first column, having 2-4 fields. The field separator is two or more spaces. Between first and second fields, use two or more spaces. Between all other fields, use two or more spaces, or one or more tabs. Entries without two spaces in them are ignored.

    Advanced unit flags

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

    For spacing and aliasing:

    Interaction with Convert

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

    See also

    Notes and References

    1. Module pages don't have section editing.
    2. A redirect page is easy to make; there are tools on the editor toolbars.
    3. The special relation between Val/units and Val/list is that the wikitext of Val/list is always generated by Val/units when that page is viewed, so when you preview page with this module, Val/list is generated using the contents of the edit box of Val/units.