Template:Italics correction/calc
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. |