Template:SI multiples 2/doc

From Wikipedia, the free encyclopedia

This template is a bit more flexible than Template:SI multiples; it can suppress prefixes that are less common.

Contents

[edit] Example 1

SI multiples for metre (m)
Submultiples Multiples
Value Symbol Name Value Symbol Name
10-1 dm decimetre 101 dam decametre
10-2 cm centimetre 102 hm hectometre
10-3 mm millimetre 103 km kilometre
10-6 µm micrometre (micron) 106 Mm megametre
10-9 nm nanometre 109 Gm gigametre
10-12 pm picometre 1012 Tm terametre
10-15 fm femtometre (fermi) 1015 Pm petametre
10-18 am attometre 1018 Em exametre
10-21 zm zeptometre 1021 Zm zettametre
10-24 ym yoctometre 1024 Ym yottametre
Common prefixed units are in bold face.
{{SI multiples 2
|symbol=m
|unit=metre
|note=Common prefixed units are in bold face.
|n=|mc=|m=|n=|c=|k=
|xmc=[[micrometre]] (micron)|xf=femtometre (fermi)
|anchor=SI_prefixed_forms_of_metre
|right=
}}


[edit] Example 2

SI multiples for gram (g)
Submultiples Multiples
Value Symbol Name Value Symbol Name
101 dag decagram
10-2 cg centigram 102 hg hectogram
10-3 mg milligram 103 kg kilogram
10-6 µg microgram 106 Mg megagram (tonne)
10-9 ng nanogram 109 Gg gigagram (kilotonne)
10-12 pg picogram
10-15 fg femtogram
Common prefixed units are in bold face.
{{SI multiples 2 <!--don't forget to change into /sandbox if necessary-->
|symbol=g
|unit=gram
|note=Common prefixed units are in bold face.
|n=|mc=|m=|n=|h=|k=
|xM=megagram ([[tonne]])
|xG=gigagram ([[kilotonne]])
|anchor=SI_prefixed_forms_of_gram
|mlo=1
|smlo=2
|mhi=9
|smhi=15
|right=
}}


[edit] Usage

  • Empty arguments such as m=, c=, n= will turn the corresponding prefix in bold face.
  • Arguments prefixed by "x" will replace the default text for that prefix (for example for a link).
  • For µ use mc=.
  • Which multiples and submultiples are displayed can be controlled with the parameters smlo, smhi, mlo, mhi. These can take positive values between 1 and 24, forcing only display of the multiples 10^(-smhi)...10^(-smlo) and 10^(mlo)...10^(mhi). Note that mhi >= mlo and smhi >= smlo.
  • right= will make the template float right.
  • The anchor parameter can be used to enable linking to e.g. #SI prefixed forms of metre directly to whereever the template is on the page. Note that the anchor text should contain underscores (_) rather than whitespace.


[edit] Modification and generating script

Use Template:SI multiples 2/sandbox for testing layout changes. This convoluted template code is generated by the perl script below.

#!/usr/bin/perl -w

# script to generate Template:SI multiples 2
# by en:User:Hankwang
# multi-licensed CC-by, GFDL


@mvals = (1, 2, 3, 6, 9, 12, 15, 18, 21, 24);
@msyms = qw(da h k M G T P E Z Y);
@smsyms = qw(d c m mc n p f a z y);
@mnames = qw(deca hecto kilo mega giga tera peta exa zetta yotta);
@smnames = qw(deci centi milli micro nano pico femto atto zepto yocto);

sub getsmsym {
    my $smsym = $smsyms[$_[0]];
    if ($smsym eq "mc") {
        $smsym = 'µ';
    }
    return $smsym;
}

print(
      "<includeonly>".
      "{{#ifeq:{{{right|}}}|{{{right|u}}}|<div style=\"float:right; width:35em; margin:0.2em 0em 0.2em 1em;\">|}}".
      "<table class=\"wikitable\" style=\"text-align:center;margin:0em auto 0em auto;\">\n".
      "<caption>SI multiples for {{{unit}}} ({{{symbol}}})</caption>\n".
      "<tr style=\"color:#fff;\">\n".
      "<th colspan=\"3\" style=\"background:#3e3e3e;\">Submultiples</th>\n".
      "<th></th>\n".
      "<th colspan=\"3\" style=\"background:#3e3e3e;\">Multiples</th>\n".
      "</tr>\n".
      "<tr>\n".
      "<th style=\"background:#d4d4d4;\">Value</th>\n".
      "<th style=\"background:#d4d4d4;\">Symbol</th>\n".
      "<th style=\"background:#d4d4d4;\">Name</th>\n".
      "<th></th>\n".
      "<th style=\"background:#d4d4d4;\">Value</th>\n".
      "<th style=\"background:#d4d4d4;\">Symbol</th>\n".
      "<th style=\"background:#d4d4d4;\">Name</th>\n".
      "</tr>\n");

# cutoff parameters with defaults
$mlo = '{{{mlo|1}}}';
$mhi = '{{{mhi|24}}}';
$smlo = '{{{smlo|1}}}';
$smhi = '{{{smhi|24}}}';

foreach $i (0..$#mvals) {
    $mval = $mvals[$i];
    $smcond = "$mval>=$smlo and $mval<=$smhi";
    $mcond = "$mval>=$mlo and $mval<=$mhi";
    $linecond = "($smcond) or ($mcond)";

    $smvar = $smsyms[$i];
    $smname = $smnames[$i];
    $smtext1 = "10<sup>-$mval</sup>";
    $smtext2 = sprintf("{{#ifeq:{{{$smvar|}}}|{{{$smvar|u}}}|'''%s{{{symbol}}}'''|%s{{{symbol}}}}}",
                       getsmsym($i), getsmsym($i));
    $smtext3 = "{{#ifeq:{{{$smvar|}}}|{{{$smvar|u}}}|'''{{{x$smvar|$smname\{{{unit}}}}}}'''|{{{x$smvar|$smname\{{{unit}}}}}}}}";

    $mvar = $msyms[$i];
    $mname = $mnames[$i];
    $mtext1 = "10<sup>$mval</sup>";
    $mtext2 = "{{#ifeq:{{{$mvar|}}}|{{{$mvar|u}}}|'''$mvar\{{{symbol}}}'''|$mvar\{{{symbol}}}}}";
    $mtext3 = "{{#ifeq:{{{$mvar|}}}|{{{$mvar|u}}}|'''{{{x$mvar|$mname\{{{unit}}}}}}'''|{{{x$mvar|$mname\{{{unit}}}}}}}}";

    print("{{#ifexpr:$linecond|\n<tr>".
          "{{#ifexpr:$smcond|\n<td align=\"center\">$smtext1</td>".
          "<td align=\"center\">$smtext2</td>".
          "<td align=\"center\">$smtext3</td>|<td></td><td></td><td></td>}}".
          "<td></td>".
          "{{#ifexpr:$mcond|\n<td align=\"center\">$mtext1</td>".
          "<td align=\"center\">$mtext2</td>".
          "<td align=\"center\">$mtext3</td>|<td></td><td></td><td></td>}}".
          "</tr>\n}}");
}
print("{{#ifeq:{{{note|}}}|{{{note|u}}}|<tr><td colspan=\"9\">{{{note}}}</td></tr>\n}}");
print("</table>".
      "{{#ifeq:{{{right|}}}|{{{right|u}}}|</div>|}}".
      "</includeonly><noinclude>\n".
      "==Example==\n{{SI multiples 2|unit=UNIT|symbol=U}}\n".
      "For more information, see [[Template:SI multiples 2/doc]].\n".
      "</noinclude>");