Template:FormatName: Difference between revisions

No edit summary
mNo edit summary
Line 1: Line 1:
{{#if:{{{1|}}}|
{{#lua:
{{#lua:
   replacements = {
   replacements = {
Line 31: Line 30:


   name = stdin:match(".+")
   name = stdin:match(".+")
---SUPER AND SUBSCRIPTS---
---SUPER AND SUBSCRIPTS (SINGLE LETTER)---
   name = string.gsub( name, "_([%d.]+)^([%d.]+) ", '<span style="line-height: 1em; font-size: x-small; position: absolute; font-family: monospace">%2<br>%1</span><span style="font-family: monospace; font-size: x-small">{{#createstring:&nbsp;|{{#max:{{#length:%1}}|{{#length:%2}}}}}}</span>')
   name = string.gsub( name, "_([-+%p%w])^([-+%p%w]) ", '<span style="line-height: 1em; font-size: x-small; position: absolute; font-family: monospace">%2<br>%1</span><span style="font-family: monospace; font-size: x-small">{{#createstring:&nbsp;|{{#max:{{#length:%1}}|{{#length:%2}}}}}}</span>')
   name = string.gsub( name, "%^([%d.]+)_([%d.]+) ", '<span style="line-height: 1em; font-size: x-small; position: absolute; font-family: monospace">%1<br>%2</span><span style="font-family: monospace; font-size: x-small">{{#createstring:&nbsp;|{{#max:{{#length:%1}}|{{#length:%2}}}}}}</span>')
   name = string.gsub( name, "%^([-+%p%w])_([-+%p%w]) ", '<span style="line-height: 1em; font-size: x-small; position: absolute; font-family: monospace">%1<br>%2</span><span style="font-family: monospace; font-size: x-small">{{#createstring:&nbsp;|{{#max:{{#length:%1}}|{{#length:%2}}}}}}</span>')
 
---SUPER AND SUBSCRIPTS (MULTIPLE LETTERS)---
   name = string.gsub( name, "%^{([-%p%w]+)}_{([-%p%w]+)}", '<span style="line-height: 1em; font-size: x-small; position: absolute; font-family: monospace">%1<br>%2</span><span style="font-family: monospace; font-size: x-small">{{#createstring:&nbsp;|{{#max:{{#length:%1}}|{{#length:%2}}}}}}</span>')
   name = string.gsub( name, "%^{([-+%p%w]+)}_{([-+%p%w]+)}", '<span style="line-height: 1em; font-size: x-small; position: absolute; font-family: monospace">%1<br>%2</span><span style="font-family: monospace; font-size: x-small">{{#createstring:&nbsp;|{{#max:{{#length:%1}}|{{#length:%2}}}}}}</span>')
  name = string.gsub( name, "_{([-+%p%w]+)}^{([-+%p%w]+)}", '<span style="line-height: 1em; font-size: x-small; position: absolute; font-family: monospace">%2<br>%1</span><span style="font-family: monospace; font-size: x-small">{{#createstring:&nbsp;|{{#max:{{#length:%1}}|{{#length:%2}}}}}}</span>')
---SUPER/SUBSCRIPTS---
---SUPER/SUBSCRIPTS---
   name = string.gsub( name, "([%a ])_{([-%p%w]+)}", "%1<sub>%2</sub>" )
   name = string.gsub( name, "_{([-+%p%w]+)}", "<sub>%1</sub>" )
   name = string.gsub( name, "([%a ])^{([-%p%w]+)}", "%1<sup>%2</sup>" )
   name = string.gsub( name, "%^{([-+%p%w]+)}", "<sup>%1</sup>" )
   name = string.gsub( name, "([%a%] ])_([D%d.]+)", "%1<sub>%2</sub>" )
   name = string.gsub( name, "_([-+%p%w]) ", "<sub>%1</sub>" )
   name = string.gsub( name, "([%a%] ])^([D%d.]+)", "%1<sup>%2</sup>" )
   name = string.gsub( name, "%^([-+%p%w]) ", "<sup>%1</sup>" )
---GREEK LETTERS---
---GREEK LETTERS---
   name = string.gsub (name, '([%a"]+)',  
   name = string.gsub (name, '([%a"]+)',  
Line 65: Line 65:
Use "_" for subscripts, "^" for superscripts. To show both, '''write the longer super/sub-script first'''. Some word must follow after a space when both ^ and _ are used.
Use "_" for subscripts, "^" for superscripts. To show both, '''write the longer super/sub-script first'''. Some word must follow after a space when both ^ and _ are used.
; Example.
; Example.
* <nowiki>D_10^20 (next word)</nowiki> &rarr; D_1^2 (next word)
* <nowiki>_1^2 (next word)</nowiki> &rarr; _1^2 (next word)
* <nowiki>D_10000^1 (next word)</nowiki> &rarr; D_10000^1 (next word)
* <nowiki>D_{10}^{20} (next word)</nowiki> &rarr; D_{10}^{20} (next word)
* <nowiki>D^10000_1 (next word)</nowiki> &rarr; D^10000_1 (next word)
* <nowiki>D_{10000}^{1} (next word)</nowiki> &rarr; D_{10000}^{1} (next word)
* <nowiki>D^10_10000 (bad example)</nowiki> &rarr; D^10_10000 (bad example)
* <nowiki>D^{10000}_{1} (next word)</nowiki> &rarr; D^{10000}_{1} (next word)
* <nowiki>D_1</nowiki> &rarr; D_1
* <nowiki>D^{10}_{10000} (bad example)</nowiki> &rarr; D^{10}_{10000} (bad example)
* <nowiki>D^2</nowiki> &rarr; D^2
* <nowiki>D_1</nowiki> &rarr; D_1  
* <nowiki>Delta^{12.13}</nowiki> &rarr; Delta^{12.13}
* <nowiki>D^2</nowiki> &rarr; D^2  
* <nowiki>Delta^{12.13}</nowiki> &rarr; Delta^{12.13}  
}}}}}
}}}}}
}}

Revision as of 14:10, 24 February 2010

{{#lua:

 replacements = {
 ["alpha"] = "α",
 ["beta"] = "β",
 ["chi"]  = "χ",
 ["delta"] = "δ",
 ["Delta"] = "Δ",
 ["epsilon"] = "ε",
 ["zeta"] = "ζ",
 ["phi"] = "φ",
 ["gamma"] = "γ",
 ["Gamma"] = "Γ",
 ["eta"] = "η",
 ["kappa"] = "κ",
 ["lambda"] = "λ", 
 ["mu"] = "μ", 
 ["nu"] = "ν", 
 ["pi"] = "π",
 ["Pi"] = "Π",
 ["theta"] = "θ",
 ["tau"] = "τ",
 ["upsilon"] = "υ",
 ["Upsilon"] = "Υ",
 ["phi"] = "φ",
 ["psi"] = "ψ",
 ["xi"] = "ξ",
 ["omega"] = "ω",
 ["sigma"] = "σ",
 }
 name = stdin:match(".+")

---SUPER AND SUBSCRIPTS (SINGLE LETTER)---

 name = string.gsub( name, "_([-+%p%w])^([-+%p%w]) ", '%2
%1
  ') name = string.gsub( name, "%^([-+%p%w])_([-+%p%w]) ", '%1
%2
  ')

---SUPER AND SUBSCRIPTS (MULTIPLE LETTERS)---

 name = string.gsub( name, "%^{([-+%p%w]+)}_{([-+%p%w]+)}", '%1
%2
  ') name = string.gsub( name, "_{([-+%p%w]+)}^{([-+%p%w]+)}", '%2
%1
  ')

---SUPER/SUBSCRIPTS---

 name = string.gsub( name, "_{([-+%p%w]+)}", "%1" )
 name = string.gsub( name, "%^{([-+%p%w]+)}", "%1" )
 name = string.gsub( name, "_([-+%p%w]) ", "%1" )
 name = string.gsub( name, "%^([-+%p%w]) ", "%1" )

---GREEK LETTERS---

 name = string.gsub (name, '([%a"]+)', 
 function (str)
   return replacements[str] or str
 end
 )
 print(name)

|==Greek Letters== Write "alpha", "beta", or "gamma" in lowercase.

Example.
  • alpha → alpha
  • beta → beta
  • chi → chi
  • delta → delta
  • epsilon → epsilon
  • gamma → gamma
  • eta → eta
  • and so on.

Super/subscripts

Use "_" for subscripts, "^" for superscripts. To show both, write the longer super/sub-script first. Some word must follow after a space when both ^ and _ are used.

Example.
  • _1^2 (next word) → _1^2 (next word)
  • D_{10}^{20} (next word) → D_{10}^{20} (next word)
  • D_{10000}^{1} (next word) → D_{10000}^{1} (next word)
  • D^{10000}_{1} (next word) → D^{10000}_{1} (next word)
  • D^{10}_{10000} (bad example) → D^{10}_{10000} (bad example)
  • D_1 → D_1
  • D^2 → D^2
  • Delta^{12.13} → Delta^{12.13}

}}