Template:Numbered block 2
![]() | This template uses Lua: |
This template is {{Numbered block}}'s wrapper template. Roughly speaking, this template can be thought of as a combination of {{Numbered block}} and {{EquationRef}}. Therefore, in general, this template can be used directly with {{EquationNote}} and avoids the use of {{EquationRef}}.
This template provides destination highlighting similar to {{Visible anchor}}—by specifying id
attribute to make the entire {{Numbered block 2}} template an HTML anchor, that is, a target that can be linked to. When clicking on a self-link displayed to the right of the {{Numbered block 2}} template or links elsewhere pointing to the {{Numbered block 2}} template (for example, [[#id|...]]
), the background color of the {{Numbered block 2}} template will change, visually highlighting the entire template.
Warning: Since this template is a wrapper template for {{Numbered block}}, lint errors may result when it is used with leading colons
:
, leading asterisks *
, or leading hash symbols #
. For more information, see the warning for {{Numbered block}}.
Parameters
[edit]Parameters |1=
, |2=
, and |3=
of this template are required. In addition, there are nine optional parameters |Id=
, |IdPfx=
, |IdSfx=
, |Lbl=
, |Attr=
, |RawN=
, |LnSty=
, |Border=
, |Cl=
and |FmtN=
.
Originally, the block number of {{Numbered block}} was directly specified by its own parameter |3=
. However, by wrapping {{Numbered block}} with this template, the block number is now determined by this template's interface. By default, it will generate a self-link based on the values of |Id=
and |Lbl=
and use this link as the block number for {{Numbered block}}. But if |FmtN=
is valid, the block number will be determined according to the parameter description of |FmtN=
.
|3=
- This parameter is used as the basis for determining the
id
attribute and label by default. Leading and trailing whitespace will not be trimmed from this parameter value. See the descriptions of related parameters|IdSfx=
and|Lbl=
for more about theid
attribute and label. See § Example 4 for handling leading and trailing whitespace around this parameter values.
- This parameter is used as the basis for determining the
|Id=
- Specify the
id
attribute of the template. The default value of this parameter is the string obtained by concatenating the value of|IdPfx=
and the value of|IdSfx=
in that order. Theid
attribute must be unique in an HTML document.
- Specify the
|IdPfx=
- Specify the default prefix for the
id
attribute. Default ismath_
.
- Specify the default prefix for the
|IdSfx=
- Specify the default suffix for the
id
attribute. Default is the value of|3=
.
- Specify the default suffix for the
|Lbl=
- Specify the label, which is the content to be displayed in the self-link on the right side of the template. Default is the value of
|3=
.
- Specify the label, which is the content to be displayed in the self-link on the right side of the template. Default is the value of
|FmtN=
- If the value specified is an empty string or consists entirely of whitespace, this parameter will be considered invalid; otherwise, this parameter will be considered valid. When this parameter is valid, the template will convert the value specified for this parameter into the block number of the {{Numbered block}}. The process of converting from the specified value for parameter
|FmtN=
to the block number of {{Numbered block}} involves three steps in sequence:- The specified value for
|FmtN=
is processed usingmw.text.unstripNoWiki
to extract text from any<nowiki>...</nowiki>
tags. - The result from the previous step is treated as a format string and converted to plain text. The format string is similar to a
printf
-style format description. Within the format string, all characters except for conversion specifiers remain unchanged when converted to plain text. Conversion specifiers are converted as follows:%i
- This specifier will be converted to the value specified for
|Id=
. %l
- This specifier will be converted to the value specified for
|Lbl=
. %L
- This specifier will be converted to a less-than sign
<
. %G
- This specifier will be converted to a greater-than sign
>
. %c
- This specifier will be converted to character c, where c represents any character except for
i
,l
,L
, andG
.
- The plain text result from the previous step is treated as wikitext and expanded using
frame:preprocess
. The expanded result is then used as the block number for {{Numbered block}}.
- The specified value for
- If the value of
|FmtN=
contains tags like<math>...</math>
or other parser extension tags, you may use#tag
parser function to help get the expected results. See 2F for an example. - Tests have shown that the
mw.text.unstripNoWiki
function used in the first step may replace<
with<
and replace>
with>
. Therefore, to avoid such replacement behavior and obtain unwanted character entity references, you can replace<
or>
within<nowiki>...</nowiki>
with conversion specifiers%L
or%G
, respectively. See 2G and 2H for examples.
- If the value specified is an empty string or consists entirely of whitespace, this parameter will be considered invalid; otherwise, this parameter will be considered valid. When this parameter is valid, the template will convert the value specified for this parameter into the block number of the {{Numbered block}}. The process of converting from the specified value for parameter
|Attr=
- The default value is some appropriate attribute settings to make the template comply with the description of this document. It is not recommended for ordinary users to specify a value other than the default for this parameter, as it may lead to unexpected results.
The meanings of parameters |1=
, |2=
, |RawN=
, |Cl=
, |LnSty=
and |Border=
remain basically unchanged. Please refer to the description of {{Numbered block}}, which will not be repeated here.
Examples
[edit]This section's examples will include both the original {{Numbered block}} and rewritten versions using {{Numbered block 2}} for comparison. Links to the {{Numbered block}} and {{Numbered block 2}} examples may also be provided.
Remark: The numbering may be modified and different from the numbering in the source to ensure that the
id
attributes are unique. The original template names may be replaced with clearer names.
Example 1
[edit]This example contains a comparison between the following two approaches:
- {{Numbered block}} + {{EquationRef}} + {{EquationNote}}
- {{Numbered block 2}} + {{EquationNote}}
Numbered block
[edit]{{Numbered block|:|<math>\Delta E = W + Q + E_\text{matter} .</math>|{{EquationRef|1A}}}}
1A |
Numbered block 2
[edit]{{Numbered block 2|:|<math>\Delta E = W + Q + E_\text{matter} .</math>|1B}}
1B |
You can see that the rendered {{Numbered block 2}} has a label on the right that is a self-link displayed as number (1B). Because no values are specified for |Id=
, |IdPfx=
and |IdSfx=
, their values are all default values. |IdPfx=
defaults to math_
. |IdSfx=
defaults to the value of |3=
, which is 1B
. |Id=
defaults to the concatenation of |IdPfx=
and |IdSfx=
, which is math_1B
. Therefore, the id
attribute of the {{Numbered block 2}} template here is math_1B
.
You can also get similar results by specifying a value for |FmtN=
:
{{Numbered block 2|:|<math>\Delta E = W + Q + E_\text{matter} .</math>|1C|RawN=y|FmtN=<nowiki>'''([[#%i|%l]])'''</nowiki>}}
(1C) |
Links
[edit]We can use {{EquationNote}} or directly use [[#id|...] ]
to link to the template.
- 1A
- 1B
- 1C
Example 2
[edit]Numbered block
[edit]{{Numbered block|:|<math>F_\text{net} = F_\text{external} - F_\text{friction}</math>|<math>(\text{2A})</math>|RawN=y}}
Numbered block 2
[edit]{{Numbered block 2|:|<math>F_\text{net} = F_\text{external} - F_\text{friction}</math>|(no effect)|RawN=y|IdSfx=2B|Lbl=<math>(\text{2B})</math>}}
In the example above, the number (label) on the right is still a clickable link. In fact, the following examples demonstrate that nearly identical results can be achieved using different parameter settings:
{{Numbered block 2|:|<math>F_\text{net} = F_\text{external} - F_\text{friction}</math>|2C|RawN=y|Lbl=<math>(\text{2C})</math>}}
{{Numbered block 2|:|<math>F_\text{net} = F_\text{external} - F_\text{friction}</math>|<math>(\text{2D})</math>|RawN=y|IdSfx=2D}}
{{Numbered block 2|:|<math>F_\text{net} = F_\text{external} - F_\text{friction}</math>|<math>(\text{2E})</math>|RawN=y|Id=math_2E}}
You can also get similar results by specifying a value for |FmtN=
. The following example uses the #tag
parser function:
{{Numbered block 2|:|<math>F_\text{net} = F_\text{external} - F_\text{friction}</math>|2F|RawN=y|FmtN=<nowiki>[[#%i|{{#tag:math|(\text{%l})}}]]</nowiki>}}
You can also use the conversion specifiers %L
and %G
to get a result similar to 2F:
{{Numbered block 2|:|<math>F_\text{net} = F_\text{external} - F_\text{friction}</math>|2G|RawN=y|FmtN=<nowiki>[[#%i|%Lmath%G(\text{%l})%L/math%G]]</nowiki>}}
If you do not use the conversion specifiers %L
and %G
in 2G but use the <
and >
characters directly, you will get unexpected results:
{{Numbered block 2|:|<math>F_\text{net} = F_\text{external} - F_\text{friction}</math>|2H|RawN=y|FmtN=<nowiki>[[#%i|<math>(\text{%l})</math>]]</nowiki>}}
<math>(\text{2H})</math> |
Links
[edit]- (2A) does not use {{EquationRef}} and cannot be linked.
{{EquationNote|2B}}
produces 2B.[[#math_2B|2B]]
produces 2B.{{EquationNote|2C}}
produces 2C.[[#math_2C|2C]]
produces 2C.{{EquationNote|2D}}
produces 2D.[[#math_2D|2D]]
produces 2D.{{EquationNote|2E}}
produces 2E.[[#math_2E|2E]]
produces 2E.{{EquationNote|2F}}
produces 2F.[[#math_2F|2F]]
produces 2F.{{EquationNote|2G}}
produces 2G.[[#math_2G|2G]]
produces 2G.{{EquationNote|2H}}
produces 2H.[[#math_2H|2H]]
produces 2H.
Example 3
[edit]Numbered block
[edit]{{Numbered block|:|<chem>CO2(aq) + H2O -> H2CO3</chem>|{{EquationRef|3A}}}}
3A |
Numbered block 2
[edit]{{Numbered block 2|:|<chem>CO2(aq) + H2O -> H2CO3</chem>|3B|IdPfx=chem-}}
3B |
Because we are numbering a chemical formula rather than a mathematical formula, we may use another id
attribute prefix chem-
instead of the original math_
. This can be achieved by specifying a value for |IdPfx=
.
Links
[edit]'''[[#math_3A|3A]]'''
produces 3A.{{EquationNote|3A}}
produces 3A.'''[[#chem-3B|3B]]'''
produces 3B.
Example 4
[edit]Some users may add newlines or other whitespace around values of |3=
to improve readability of source code. The extra whitespace around values of |3=
does not affect the rendering of the template in some cases, but may cause unexpected results in other cases. This example shows some ways to handle leading and trailing whitespace around values of |3=
.
Numbered block
[edit]{{Numbered block|:|
<math>\mathbb{E}[\mathbf{n}(c, a)] \propto f(c)\mu(c, a)^{\beta}</math>|
{{EquationRef|beta1A}}
}}
beta1A |
Numbered block 2
[edit]{{Numbered block 2|:|
<math>\mathbb{E}[\mathbf{n}(c, a)] \propto f(c)\mu(c, a)^{\beta}</math>|
beta1B
}}
[[#math_
beta1B | beta1B ]] |
It can be seen that line breaks appear around |3=
in beta1A and beta1B above. The result of beta1A using {{Numbered block}} is normal, but beta1B uses {{Numbered block 2}}, which does not trim the leading and trailing whitespace from the value of |3=
, resulting in unexpected results.
One solution is to use HTML comments to wrap the leading and trailing whitespace characters (such as line breaks) around |3=
so that the parser ignores the whitespace characters. For consistency and readability, the following example also comments out whitespace characters that are not relevant to |3=
:
<!--
-->{{Numbered block 2|:|<!--
--><math>\mathbb{E}[\mathbf{n}(c, a)] \propto f(c)\mu(c, a)^{\beta}</math>|<!--
-->beta1C<!--
-->}}<!--
-->
beta1C |
A simpler solution is to use named parameters instead. Whitespace around parameter names and values is automatically collapsed when using named parameters, and named parameters have the form name=value
. The parameter discussed here is named 3
, so it can be changed to the form 3=value
. The whitespace characters around 3
and value
will be automatically collapsed:
{{Numbered block 2|:|
<math>\mathbb{E}[\mathbf{n}(c, a)] \propto f(c)\mu(c, a)^{\beta}</math>|
3=beta1D
}}
beta1D |