Template:FormatName: Difference between revisions

No edit summary
No edit summary
(27 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{#lua:
{{#lua:
   name = stdin:match("[^&]+")
   replacements = {
  name = string.gsub( name, " alpha%-", " α-" )
  ["alpha"] = "α",
  name = string.gsub( name, " beta%-", " β-" )
  ["beta"] = "β",
  name = string.gsub( name, " gamma%-", " γ-" )
  ["chi"]  = "χ",
  name = string.gsub( name, " delta%-", " δ-" )
  ["delta"] = "δ",
  name = string.gsub( name, " Delta%-", " Δ-" )
  ["Delta"] = "Δ",
  name = string.gsub( name, "_(%d%d?) ", "<sub>%1</sub> " )
  ["epsilon"] = "&epsilon;",
  name = string.gsub( name, "^(%d%d?]) ", "<sup>%1</sup> " )
  ["zeta"] = "&zeta;",
  ["phi"] = "&phi;",
  ["gamma"] = "&gamma;",
  ["Gamma"] = "&Gamma;",
  ["eta"] = "&eta;",
  ["kappa"] = "&kappa;",
  ["lambda"] = "&lambda;",
  ["mu"] = "&mu;",
  ["nu"] = "&nu;",
  ["pi"] = "&pi;",
  ["Pi"] = "&Pi;",
  ["theta"] = "&theta;",
  ["tau"] = "&tau;",
  ["upsilon"] = "&upsilon;",
  ["Upsilon"] = "&Upsilon;",
  ["phi"] = "&phi;",
  ["psi"] = "&psi;",
  ["xi"] = "&xi;",
  ["omega"] = "&omega;",
  ["sigma"] = "&sigma;",
  }
 
  if string.len(stdin) > 0 then
    name = stdin:match(".+")
---SUPER AND SUBSCRIPTS (SINGLE LETTER)---
    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>')
---SINGLE AND MULTIPLE---
    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>')
---SUPER/SUBSCRIPTS---
    name = string.gsub( name, "_{([-+%p%w]+)}", "<sub>%1</sub>" )
    name = string.gsub( name, "_([-+%p%w]) ", "<sub>%1</sub>" )
    name = string.gsub( name, "_([-+%p%w])$", "<sub>%1</sub>" )
    name = string.gsub( name, "%^{([-+%p%w]+)}", "<sup>%1</sup>" )
    name = string.gsub( name, "%^([-+%p%w]) ", "<sup>%1</sup>" )
---GREEK LETTERS---
    name = string.gsub (name, '([%a"]+)',
    function (str)
      return replacements[str] or str
    end
    )
  else
    name = ""
  end
 
   print(name)
   print(name)
|{{{1|foo Delta-foo_21 fdol}}}}}
 
|{{{1|==Greek Letters==
{{Twocolumn|
To display Greek letters, simply write "alpha", "beta", or "gamma", followed by a space.
|
ギリシャ文字を記述するには、alpha, beta, gamma とそのまま書いてください。
}}
; Example.
* <nowiki>alpha</nowiki> &rarr; alpha
* <nowiki>beta</nowiki> &rarr; beta
* <nowiki>chi</nowiki> &rarr; chi
* <nowiki>delta</nowiki> &rarr; delta
* <nowiki>epsilon</nowiki> &rarr; epsilon
* <nowiki>gamma</nowiki> &rarr; gamma
* <nowiki>eta</nowiki> &rarr; eta
* and so on.
 
==Super/subscripts==
{{Twocolumn|
Use " _ " for subscripts, " ^ " for superscripts. To add both, write " ^ " first (super-, then subscript). For only one letter, you can directly write the letter whereas for multiple letters, use { }. If without { }, at least one space is needed after the script.
|
下付文字は _ 上付き文字は ^ の後に書いてください。両方つけるときは、^ _ (上付き、下付き)の順番で書いてください。1文字の場合はそのまま記述し、複数文字の場合は、{ } でくくってください。{ }でくくらない場合は直後にスペース(空白)が必要です。
}}
; Example.
* <nowiki>D^2_1 (next word)</nowiki> &rarr; D^2_1 (next word)
* <nowiki>D^{20}_{10} (next word)</nowiki> &rarr; D^{20}_{10} (next word)
* <nowiki>D^1_{10000} (next word)</nowiki> &rarr; D^{1}_{10000} (next word)
* <nowiki>D^{10000}_1 (next word)</nowiki> &rarr; D^{10000}_{1} (next word)
* <nowiki>D^{10}_{10000} (next word)</nowiki> &rarr; D^{10}_{10000} (next word)
* <nowiki>D_1</nowiki> &rarr; D_1
* <nowiki>D^2</nowiki> &rarr; D^2
* <nowiki>Delta^{12.13}</nowiki> &rarr; Delta^{12.13}
}}}}}

Revision as of 23:13, 7 September 2014

{{#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"] = "σ",
 }
 if string.len(stdin) > 0 then
   name = stdin:match(".+")

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

   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
  ')

---SINGLE AND MULTIPLE---

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

---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" )
   name = string.gsub( name, "%^([-+%p%w]) ", "%1" )

---GREEK LETTERS---

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

|==Greek Letters==

To display Greek letters, simply write "alpha", "beta", or "gamma", followed by a space.

ギリシャ文字を記述するには、alpha, beta, gamma とそのまま書いてください。

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 add both, write " ^ " first (super-, then subscript). For only one letter, you can directly write the letter whereas for multiple letters, use { }. If without { }, at least one space is needed after the script.

下付文字は _ 上付き文字は ^ の後に書いてください。両方つけるときは、^ _ (上付き、下付き)の順番で書いてください。1文字の場合はそのまま記述し、複数文字の場合は、{ } でくくってください。{ }でくくらない場合は直後にスペース(空白)が必要です。

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

}}