Difference between revisions of "Template:Italics correction/calc"
(Completed documentation table, including four Greek letter variants (ε/ϵ, ϑ/θ, ς/σ, and φ/ϕ) sometimes used in mathematics. Next: Greek spacing) |
(Add a few more Greek letter variants that are used as technical symbols, and one Latin (∂). Fill in Greek spacing.) |
||
Line 1: | Line 1: | ||
{{#switch:0 | {{#switch:0 | ||
− | |{{#expr:not{{#invoke:String|find| | + | |{{#expr:not{{#invoke:String|find|dijkrtvwxyzCDEFGHIJKMNUVWXYZγδζξϖπστΕΖΗΙΚΜΝΞΠΣΥϒΧΨ|{{{1}}}}}}}=0.1em |
− | |{{#expr:not{{#invoke:String|find| | + | |{{#expr:not{{#invoke:String|find|cgsuBGOPQRSαβϑθκμνςυχψωΒΘΟΡΩ|{{{1}}}}}}}=0.05em |
− | |{{#expr:not{{#invoke:String|find| | + | |{{#expr:not{{#invoke:String|find|ab∂ehmnopqALεϵηιλοϱρφϕΑΔΛΦ|{{{1}}}}}}}=0em |
− | |{{#expr:not{{#invoke:String|find| | + | |{{#expr:not{{#invoke:String|find|flTΓΤ|{{{1}}}}}}}=0.15em |
|0=0.1em | |0=0.1em | ||
− | }}<noinclude>{{documentation|content= | + | }}<noinclude><!-- |
+ | Greek lower-case: αβγδεϵζηϑθικλμνξοϖπϱρςστυφϕχψω | ||
+ | Greek upper-case: ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥϒΦΧΨΩ | ||
+ | -->{{documentation|content= | ||
This template takes one parameter, a single letter, and returns an amount of space (in units of "em", so something like "0.1em") that should be added after an italic version of that letter to prevent tall characters from colliding with its top-right corner. It is large for letters like ''f'', ''l'' and ''T'', and zero for letters like ''o'', ''A'' and ''L'' which do not protrude to the top right. | This template takes one parameter, a single letter, and returns an amount of space (in units of "em", so something like "0.1em") that should be added after an italic version of that letter to prevent tall characters from colliding with its top-right corner. It is large for letters like ''f'', ''l'' and ''T'', and zero for letters like ''o'', ''A'' and ''L'' which do not protrude to the top right. | ||
Line 51: | Line 54: | ||
{{!}} {{mvar|λ′ Λ′}} {{!!}} {{mvar|1=λ<span style="padding-left:{{{{ARTICLEPAGENAME}}|λ}}">′</span> Λ<span style="padding-left:{{{{ARTICLEPAGENAME}}|Λ}}">′</span>}} | {{!}} {{mvar|λ′ Λ′}} {{!!}} {{mvar|1=λ<span style="padding-left:{{{{ARTICLEPAGENAME}}|λ}}">′</span> Λ<span style="padding-left:{{{{ARTICLEPAGENAME}}|Λ}}">′</span>}} | ||
{{!}}- | {{!}}- | ||
− | {{!}} '' | + | {{!}} ''∂′d′ D′'' {{!!}} ''∂<span style="padding-left:{{{{ARTICLEPAGENAME}}|∂}}">′</span>d<span style="padding-left:{{{{ARTICLEPAGENAME}}|d}}">′</span> D<span style="padding-left:{{{{ARTICLEPAGENAME}}|D}}">′</span>'' |
− | {{!}} {{mvar| | + | {{!}} {{mvar|∂′d′ D′}} {{!!}} {{mvar|1=∂<span style="padding-left:{{{{ARTICLEPAGENAME}}|∂}}">′</span>d<span style="padding-left:{{{{ARTICLEPAGENAME}}|d}}">′</span> D<span style="padding-left:{{{{ARTICLEPAGENAME}}|D}}">′</span>}} |
{{!}} ''u′ U′'' {{!!}} ''u<span style="padding-left:{{{{ARTICLEPAGENAME}}|u}}">′</span> U<span style="padding-left:{{{{ARTICLEPAGENAME}}|U}}">′</span>'' | {{!}} ''u′ U′'' {{!!}} ''u<span style="padding-left:{{{{ARTICLEPAGENAME}}|u}}">′</span> U<span style="padding-left:{{{{ARTICLEPAGENAME}}|U}}">′</span>'' | ||
{{!}} {{mvar|u′ U′}} {{!!}} {{mvar|1=u<span style="padding-left:{{{{ARTICLEPAGENAME}}|u}}">′</span> U<span style="padding-left:{{{{ARTICLEPAGENAME}}|U}}">′</span>}} | {{!}} {{mvar|u′ U′}} {{!!}} {{mvar|1=u<span style="padding-left:{{{{ARTICLEPAGENAME}}|u}}">′</span> U<span style="padding-left:{{{{ARTICLEPAGENAME}}|U}}">′</span>}} | ||
Line 83: | Line 86: | ||
{{!}} ''y′ Y′'' {{!!}} ''y<span style="padding-left:{{{{ARTICLEPAGENAME}}|y}}">′</span> Y<span style="padding-left:{{{{ARTICLEPAGENAME}}|Y}}">′</span>'' | {{!}} ''y′ Y′'' {{!!}} ''y<span style="padding-left:{{{{ARTICLEPAGENAME}}|y}}">′</span> Y<span style="padding-left:{{{{ARTICLEPAGENAME}}|Y}}">′</span>'' | ||
{{!}} {{mvar|y′ Y′}} {{!!}} {{mvar|1=y<span style="padding-left:{{{{ARTICLEPAGENAME}}|y}}">′</span> Y<span style="padding-left:{{{{ARTICLEPAGENAME}}|Y}}">′</span>}} | {{!}} {{mvar|y′ Y′}} {{!!}} {{mvar|1=y<span style="padding-left:{{{{ARTICLEPAGENAME}}|y}}">′</span> Y<span style="padding-left:{{{{ARTICLEPAGENAME}}|Y}}">′</span>}} | ||
− | {{!}} '' | + | {{!}} ''ϖ′π′ Π′'' {{!!}} ''ϖ<span style="padding-left:{{{{ARTICLEPAGENAME}}|ϖ}}">′</span>π<span style="padding-left:{{{{ARTICLEPAGENAME}}|π}}">′</span> Π<span style="padding-left:{{{{ARTICLEPAGENAME}}|Π}}">′</span>'' |
− | {{!}} {{mvar| | + | {{!}} {{mvar|ϖ′π′ Π′}} {{!!}} {{mvar|1=ϖ<span style="padding-left:{{{{ARTICLEPAGENAME}}|ϖ}}">′π<span style="padding-left:{{{{ARTICLEPAGENAME}}|π}}">′</span> Π<span style="padding-left:{{{{ARTICLEPAGENAME}}|Π}}">′</span>}} |
{{!}}- | {{!}}- | ||
{{!}} ''i′ I′'' {{!!}} ''i<span style="padding-left:{{{{ARTICLEPAGENAME}}|i}}">′</span> I<span style="padding-left:{{{{ARTICLEPAGENAME}}|I}}">′</span>'' | {{!}} ''i′ I′'' {{!!}} ''i<span style="padding-left:{{{{ARTICLEPAGENAME}}|i}}">′</span> I<span style="padding-left:{{{{ARTICLEPAGENAME}}|I}}">′</span>'' | ||
Line 90: | Line 93: | ||
{{!}} ''z′ Z′'' {{!!}} ''z<span style="padding-left:{{{{ARTICLEPAGENAME}}|z}}">′</span> Z<span style="padding-left:{{{{ARTICLEPAGENAME}}|Z}}">′</span>'' | {{!}} ''z′ Z′'' {{!!}} ''z<span style="padding-left:{{{{ARTICLEPAGENAME}}|z}}">′</span> Z<span style="padding-left:{{{{ARTICLEPAGENAME}}|Z}}">′</span>'' | ||
{{!}} {{mvar|z′ Z′}} {{!!}} {{mvar|1=z<span style="padding-left:{{{{ARTICLEPAGENAME}}|z}}">′</span> Z<span style="padding-left:{{{{ARTICLEPAGENAME}}|z}}">′</span>}} | {{!}} {{mvar|z′ Z′}} {{!!}} {{mvar|1=z<span style="padding-left:{{{{ARTICLEPAGENAME}}|z}}">′</span> Z<span style="padding-left:{{{{ARTICLEPAGENAME}}|z}}">′</span>}} | ||
− | {{!}} '' | + | {{!}} ''ϱ′ρ′ Ρ′'' {{!!}} ''ϱ<span style="padding-left:{{{{ARTICLEPAGENAME}}|ϱ}}">′</span>ρ<span style="padding-left:{{{{ARTICLEPAGENAME}}|ρ}}">′</span> Ρ<span style="padding-left:{{{{ARTICLEPAGENAME}}|Ρ}}">′</span>'' |
− | {{!}} {{mvar| | + | {{!}} {{mvar|ϱ′ρ′ Ρ′}} {{!!}} {{mvar|1=ϱ<span style="padding-left:{{{{ARTICLEPAGENAME}}|ϱ}}">′</span>ρ<span style="padding-left:{{{{ARTICLEPAGENAME}}|ρ}}">′</span> Ρ<span style="padding-left:{{{{ARTICLEPAGENAME}}|Ρ}}">′</span>}} |
{{!}}- | {{!}}- | ||
{{!}} ''j′ J′'' {{!!}} ''j<span style="padding-left:{{{{ARTICLEPAGENAME}}|j}}">′</span> J<span style="padding-left:{{{{ARTICLEPAGENAME}}|J}}">′</span>'' | {{!}} ''j′ J′'' {{!!}} ''j<span style="padding-left:{{{{ARTICLEPAGENAME}}|j}}">′</span> J<span style="padding-left:{{{{ARTICLEPAGENAME}}|J}}">′</span>'' | ||
Line 111: | Line 114: | ||
{{!}} ''γ′ Γ′'' {{!!}} ''γ<span style="padding-left:{{{{ARTICLEPAGENAME}}|γ}}">′</span> Γ<span style="padding-left:{{{{ARTICLEPAGENAME}}|Γ}}">′</span>'' | {{!}} ''γ′ Γ′'' {{!!}} ''γ<span style="padding-left:{{{{ARTICLEPAGENAME}}|γ}}">′</span> Γ<span style="padding-left:{{{{ARTICLEPAGENAME}}|Γ}}">′</span>'' | ||
{{!}} {{mvar|γ′ Γ′}} {{!!}} {{mvar|1=γ<span style="padding-left:{{{{ARTICLEPAGENAME}}|γ}}">′</span> Γ<span style="padding-left:{{{{ARTICLEPAGENAME}}|Γ}}">′</span>}} | {{!}} {{mvar|γ′ Γ′}} {{!!}} {{mvar|1=γ<span style="padding-left:{{{{ARTICLEPAGENAME}}|γ}}">′</span> Γ<span style="padding-left:{{{{ARTICLEPAGENAME}}|Γ}}">′</span>}} | ||
− | {{!}} ''υ′ | + | {{!}} ''υ′ Υ′ϒ′'' {{!!}} ''υ<span style="padding-left:{{{{ARTICLEPAGENAME}}|υ}}">′</span> </span>Υ<span style="padding-left:{{{{ARTICLEPAGENAME}}|Υ}}">′</span>ϒ<span style="padding-left:{{{{ARTICLEPAGENAME}}|ϒ}}">′'' |
− | {{!}} {{mvar|υ′ | + | {{!}} {{mvar|υ′ Υ′ϒ′}} {{!!}} {{mvar|1=υ<span style="padding-left:{{{{ARTICLEPAGENAME}}|υ}}">′</span> Υ<span style="padding-left:{{{{ARTICLEPAGENAME}}|Υ}}">′</span>ϒ<span style="padding-left:{{{{ARTICLEPAGENAME}}|ϒ}}">′}} |
{{!}}- | {{!}}- | ||
{{!}} ''m′ M′'' {{!!}} ''m<span style="padding-left:{{{{ARTICLEPAGENAME}}|m}}">′</span> M<span style="padding-left:{{{{ARTICLEPAGENAME}}|M}}">′</span>'' | {{!}} ''m′ M′'' {{!!}} ''m<span style="padding-left:{{{{ARTICLEPAGENAME}}|m}}">′</span> M<span style="padding-left:{{{{ARTICLEPAGENAME}}|M}}">′</span>'' | ||
Line 152: | Line 155: | ||
: Since {{tlc|#invoke:String|find}} returns 0 if the argument is ''not'' found, and a non-zero string position if it is, the return value is inverted with {{tlc|#expr:not}} and then compared to 0 to indicate a match. | : Since {{tlc|#invoke:String|find}} returns 0 if the argument is ''not'' found, and a non-zero string position if it is, the return value is inverted with {{tlc|#expr:not}} and then compared to 0 to indicate a match. | ||
: For efficiency, the cases in the {{tlc|#switch}} should be sorted in decreasing order of likelihood. | : For efficiency, the cases in the {{tlc|#switch}} should be sorted in decreasing order of likelihood. | ||
− | : This ''could'' be written as one giant | + | : This ''could'' be written as one giant 108-way {{tlc|#switch}}, branching on the passed-in character, but I'm guessing (''verify this!'') that {{tlc|#invoke:String|find}} is faster than the general parser. |
}}</noinclude> | }}</noinclude> |
Revision as of 15:15, 17 November 2016
0.1em

This template takes one parameter, a single letter, and returns an amount of space (in units of "em", so something like "0.1em") that should be added after an italic version of that letter to prevent tall characters from colliding with its top-right corner. It is large for letters like f, l and T, and zero for letters like o, A and L which do not protrude to the top right.
Examples:
{{Template:Italics correction/calc|f}}
= 0.15em{{Template:Italics correction/calc|j}}
= 0.1em{{Template:Italics correction/calc|s}}
= 0.05em{{Template:Italics correction/calc|h}}
= 0em
Because it does not know what font is in use on the user's browser, it is a much cruder approximation than TeX's "italic correction" macro \/
, but it's still better than a fixed space.
The primary application is mathematics, where italic letters are often followed by a close parenthesis, superscript, or prime symbol. Thus, the Latin and Greek alphabets are covered, but not the entire Unicode space. Some Hebrew and Cyrillic characters could be added as required.
- Implementation
- The characters are grouped together based on the amount of space required. Then, using the
#switch
parser function, this steps through a number of{{#invoke:String|find}}
instances which look up the single-letter parameter in each of the groups. - Since
{{#invoke:String|find}}
returns 0 if the argument is not found, and a non-zero string position if it is, the return value is inverted with{{#expr:not}}
and then compared to 0 to indicate a match. - For efficiency, the cases in the
{{#switch}}
should be sorted in decreasing order of likelihood. - This could be written as one giant 108-way
{{#switch}}
, branching on the passed-in character, but I'm guessing (verify this!) that{{#invoke:String|find}}
is faster than the general parser.
Editors can experiment in this template's sandbox (create | mirror) and testcases (create) pages. Subpages of this template. |