tex.pl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. # Copyright (C) 2006, 2012 Alex Schroeder <alex@gnu.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. use strict;
  16. use v5.10;
  17. AddModuleDescription('tex.pl', 'TeX Extension');
  18. our (%RuleOrder, @MyRules);
  19. our ($TeXInit, %Tex);
  20. use utf8;
  21. %Tex = qw( !` ¡ {\pounds} £ \pounds £ {\S} § \S § \"{} ¨ {\copyright} ©
  22. \copyright © $^a$ ª \={} ¯ $\pm$ ± \pm ± $^2$ ² $^3$ ³ \'{} ´ {\P} ¶
  23. \P ¶ $\cdot$ · \cdot · \c{} ¸ $^1$ ¹ $^o$ º ?` ¿ \`{A} À \`A À \'{A} Á
  24. \'A Á \^{A} Â \^A Â \~{A} Ã \~A Ã \"{A} Ä \"A Ä \k{A} Ą {\AA} Å \AA Å
  25. {\AE} Æ \AE Æ \c{C} Ç \cC Ç \`{E} È \`E È \'{E} É \'E É \^{E} Ê \^E Ê
  26. \"{E} Ë \"E Ë \k{E} Ę \`{I} Ì \`I Ì \'{I} Í \'I Í \^{I} Î \^I Î \"{I}
  27. Ï \"I Ï \k{I} Į \~{N} Ñ \~N Ñ \`{O} Ò \`O Ò \'{O} Ó \'O Ó \^{O} Ô \^O
  28. Ô \~{O} Õ \~O Õ \"{O} Ö \"O Ö \k{O} Ǫ $\times$ × \times × {\O} Ø \O Ø
  29. \`{U} Ù \`U Ù \'{U} Ú \'U Ú \^{U} Û \^U Û \"{U} Ü \"U Ü \k{U} Ų \'{Y}
  30. Ý \'Y Ý {\ss} ß \ss ß \`{a} à \`a à \'{a} á \'a á \^{a} â \^a â \~{a}
  31. ã \~a ã \"{a} ä \"a ä \k{a} ą {\aa} å \aa å {\ae} æ \ae æ \c{c} ç \cc
  32. ç \`{e} è \`e è \'{e} é \'e é \^{e} ê \^e ê \"{e} ë \"e ë \k{e} ę
  33. \`{\i} ì \`i ì \'{\i} í \'i í \^{\i} î \^i î \"{\i} ï \"i ï \k{i} į
  34. \~{n} ñ \~n ñ \`{o} ò \`o ò \'{o} ó \'o ó \^{o} ô \^o ô \~{o} õ \~o õ
  35. \"{o} ö \"o ö \k{o} ǫ $\div$ ÷ \div ÷ {\o} ø \o ø \`{u} ù \`u ù \'{u}
  36. ú \'u ú \^{u} û \^u û \"{u} ü \"u ü \k{u} ų \'{y} ý \'y ý \"{y} ÿ \"y
  37. ÿ \={A} Ā \=A Ā \={a} ā \=a ā \u{A} Ă \uA Ă \u{a} ă \ua ă \'{C} Ć \'C
  38. Ć \'{c} ć \'c ć \^{C} Ĉ \^C Ĉ \^{c} ĉ \^c ĉ \.{C} Ċ \.C Ċ \.{c} ċ \.c
  39. ċ \v{C} Č \vC Č \v{c} č \vc č \v{D} Ď \vD Ď \v{d} ď \vd ď \={E} Ē \=E
  40. Ē \={e} ē \=e ē \u{E} Ĕ \uE Ĕ \u{e} ĕ \ue ĕ \.{E} Ė \.E Ė \e{e} ė \ee
  41. ė \v{E} Ě \vE Ě \v{e} ě \ve ě \^{G} Ĝ \^G Ĝ \^{g} ĝ \^g ĝ \u{G} Ğ \uG
  42. Ğ \u{g} ğ \ug ğ \.{G} Ġ \.G Ġ \.{g} ġ \.g ġ \c{G} Ģ \cG Ģ \c{g} ģ \cg
  43. ģ \^{H} Ĥ \^H Ĥ \^{h} ĥ \^h ĥ \~{I} Ĩ \~I Ĩ \~{\i} ĩ \~i ĩ \={I} Ī \=I
  44. Ī \={\i} ī \=i ī \u{I} Ĭ \uI Ĭ \u{\i} ĭ \ui ĭ \.{I} İ \.I İ {\i} ı \i
  45. ı \^{J} Ĵ \^J Ĵ \^{\j} ĵ \^j ĵ \c{K} Ķ \cK Ķ \c{k} ķ \ck ķ \'{L} Ĺ \'L
  46. Ĺ \'{l} ĺ \'l ĺ \c{L} Ļ \cL Ļ \c{l} ļ \cl ļ {\L} Ł \L Ł {\l} ł \l ł
  47. \'{N} Ń \'N Ń \'{n} ń \'n ń \c{N} Ņ \cN Ņ \c{n} ņ \cn ņ \v{N} Ň \vN Ň
  48. \v{n} ň \vn ň \={O} Ō \=O Ō \={o} ō \=o ō \u{O} Ŏ \uO Ŏ \u{o} ŏ \uo ŏ
  49. \H{O} Ő \HO Ő \U{o} ő \Uo ő {\OE} Œ \OE Œ {\oe} œ \oe œ \'{R} Ŕ \'R Ŕ
  50. \'{r} ŕ \'r ŕ \c{R} Ŗ \cR Ŗ \c{r} ŗ \cr ŗ \v{R} Ř \vR Ř \v{r} ř \vr ř
  51. \'{S} Ś \'S Ś \'{s} ś \'s ś \^{S} Ŝ \^S Ŝ \^{s} ŝ \^s ŝ \c{S} Ş \cS Ş
  52. \c{s} ş \cs ş \v{S} Š \vS Š \v{s} š \vs š \c{T} Ţ \cT Ţ \c{t} ţ \ct ţ
  53. \v{T} Ť \vT Ť \v{t} ť \vt ť \~{U} Ũ \~U Ũ \~{u} ũ \~u ũ \={U} Ū \=U Ū
  54. \={u} ū \=u ū \u{U} Ŭ \uU Ŭ \u{u} ŭ \uu ŭ \H{U} Ű \HU Ű \H{u} ű \Hu ű
  55. \^{W} Ŵ \^W Ŵ \^{w} ŵ \^w ŵ \^{Y} Ŷ \^Y Ŷ \^{y} ŷ \^y ŷ \"{Y} Ÿ \"Y Ÿ
  56. \'{Z} Ź \'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̄ \=G Ḡ \=g ḡ ^( ⁽ ^) ⁾ ^+ ⁺ ^- ⁻ ^0 ⁰ ^1 ¹ ^2 ² ^3 ³
  69. ^4 ⁴ ^5 ⁵ ^6 ⁶ ^7 ⁷ ^8 ⁸ ^9 ⁹ ^= ⁼ ^\gamma ˠ ^h ʰ ^j ʲ ^l ˡ ^n ⁿ ^o º
  70. ^r ʳ ^s ˢ ^w ʷ ^x ˣ ^y ʸ ^{SM} ℠ ^{TEL} ℡ ^{TM} ™ _( ₍ _) ₎ _+ ₊ _- ₋
  71. _0 ₀ _1 ₁ _2 ₂ _3 ₃ _4 ₄ _5 ₅ _6 ₆ _7 ₇ _8 ₈ _9 ₉ _= ₌ \~ ̃ \~E Ẽ \~V
  72. Ṽ \~Y Ỹ \~e ẽ \~v ṽ \~y ỹ \" ̈ \"H Ḧ \"W Ẅ \"X Ẍ \"h ḧ \"t ẗ \"w ẅ \"x
  73. ẍ \^ ̂ \^Z Ẑ \^z ẑ \` ̀ \`W Ẁ \`Y Ỳ \`w ẁ \`y ỳ \b ̱ \c ̧ \c{D} Ḑ
  74. \c{H} Ḩ \c{d} ḑ \c{h} ḩ \d ̣ \d{A} Ạ \d{B} Ḅ \d{D} Ḍ \d{E} Ẹ \d{H} Ḥ
  75. \d{I} Ị \d{K} Ḳ \d{L} Ḷ \d{M} Ṃ \d{N} Ṇ \d{O} Ọ \d{R} Ṛ \d{S} Ṣ \d{T}
  76. Ṭ \d{U} Ụ \d{V} Ṿ \d{W} Ẉ \d{Y} Ỵ \d{Z} Ẓ \d{a} ạ \d{b} ḅ \d{d} ḍ
  77. \d{e} ẹ \d{h} ḥ \d{i} ị \d{k} ḳ \d{l} ḷ \d{m} ṃ \d{n} ṇ \d{o} ọ \d{r}
  78. ṛ \d{s} ṣ \d{t} ṭ \d{u} ụ \d{v} ṿ \d{w} ẉ \d{y} ỵ \d{z} ẓ \rq ’ \u ̆
  79. \v ̌ \v{L} Ľ \v{i} ǐ \v{j} ǰ \v{l} ľ \yen ¥ \Box □ \Bumpeq ≎ \Cap ⋒
  80. \Cup ⋓ \Delta Δ \Diamond ◇ \Downarrow ⇓ \Gamma Γ \H ̋ \H{o} ő \Im ℑ
  81. \Join ⋈ \Lambda Λ \Leftarrow ⇐ \Leftrightarrow ⇔ \Ll ⋘ \Lleftarrow ⇚
  82. \Longleftarrow ⇐ \Longleftrightarrow ⇔ \Longrightarrow ⇒ \Lsh ↰ \Omega
  83. Ω \Phi Φ \Pi Π \Psi Ψ \Re ℜ \Rightarrow ⇒ \Rrightarrow ⇛ \Rsh ↱ \Sigma
  84. Σ \Subset ⋐ \Supset ⋑ \Theta Θ \Uparrow ⇑ \Updownarrow ⇕ \Upsilon Υ
  85. \Vdash ⊩ \Vert ‖ \Vvdash ⊪ \Xi Ξ \aleph א \alpha α \amalg ∐ \angle ∠
  86. \approx ≈ \approxeq ≊ \ast ∗ \asymp ≍ \backcong ≌ \backepsilon ∍
  87. \backprime ‵ \backsim ∽ \backsimeq ⋍ \backslash \ \barwedge ⊼ \because
  88. ∵ \beta β \beth ב \between ≬ \bigcap ⋂ \bigcirc ◯ \bigcup ⋃ \bigstar ★
  89. \bigtriangledown ▽ \bigtriangleup △ \bigvee ⋁ \bigwedge ⋀
  90. \blacklozenge ✦ \blacksquare ▪ \blacktriangle ▴ \blacktriangledown ▾
  91. \blacktriangleleft ◂ \blacktriangleright ▸ \bot ⊥ \bowtie ⋈ \boxminus
  92. ⊟ \boxplus ⊞ \boxtimes ⊠ \bullet • \bumpeq ≏ \cap ∩ \cdots ⋯
  93. \centerdot · \checkmark ✓ \chi χ \circ ○ \circeq ≗ \circlearrowleft ↺
  94. \circlearrowright ↻ \circledR ® \circledS Ⓢ \circledast ⊛ \circledcirc
  95. ⊚ \circleddash ⊝ \clubsuit ♣ \colon : \coloneq ≔ \complement ∁ \cong ≅
  96. \coprod ∐ \cup ∪ \curlyeqprec ⋞ \curlyeqsucc ⋟ \curlypreceq ≼
  97. \curlyvee ⋎ \curlywedge ⋏ \curvearrowleft ↶ \curvearrowright ↷ \dag †
  98. \dagger † \daleth ד \dashv ⊣ \ddag ‡ \ddagger ‡ \ddots ⋱ \delta δ
  99. \diamond ⋄ \diamondsuit ♢ \digamma Ϝ \divideontimes ⋇ \doteq ≐
  100. \doteqdot ≑ \dotplus ∔ \dotsquare ⊡ \downarrow ↓ \downdownarrows ⇊
  101. \downleftharpoon ⇃ \downrightharpoon ⇂ \ell ℓ \emptyset ∅ \epsilon ε
  102. \eqcirc ≖ \eqcolon ≕ \eqslantgtr ⋝ \eqslantless ⋜ \equiv ≡ \eta η
  103. \euro € \exists ∃ \fallingdotseq ≒ \flat ♭ \forall ∀ \frac1 ⅟ \frac12
  104. ½ \frac13 ⅓ \frac14 ¼ \frac15 ⅕ \frac16 ⅙ \frac18 ⅛ \frac23 ⅔ \frac25
  105. ⅖ \frac34 ¾ \frac35 ⅗ \frac38 ⅜ \frac45 ⅘ \frac56 ⅚ \frac58 ⅝ \frac78
  106. ⅞ \frown ⌢ \gamma γ \ge ≥ \geq ≥ \geqq ≧ \geqslant ≥ \gets ← \gg ≫
  107. \ggg ⋙ \gimel ג \gnapprox ⋧ \gneq ≩ \gneqq ≩ \gnsim ⋧ \gtrapprox ≳
  108. \gtrdot ⋗ \gtreqless ⋛ \gtreqqless ⋛ \gtrless ≷ \gtrsim ≳ \gvertneqq ≩
  109. \hbar ℏ \heartsuit ♥ \hookleftarrow ↩ \hookrightarrow ↪ \iff ⇔ \imath
  110. ı \in ∈ \infty ∞ \int ∫ \intercal ⊺ \iota ι \kappa κ \lambda λ \langle
  111. 〈 \lbrace { \lbrack [ \lceil ⌈ \ldots … \le ≤ \leadsto ↝ \leftarrow ←
  112. \leftarrowtail ↢ \leftharpoondown ↽ \leftharpoonup ↼ \leftleftarrows ⇇
  113. \leftparengtr 〈 \leftrightarrow ↔ \leftrightarrows ⇆
  114. \leftrightharpoons ⇋ \leftrightsquigarrow ↭ \leftthreetimes ⋋ \leq ≤
  115. \leqq ≦ \leqslant ≤ \lessapprox ≲ \lessdot ⋖ \lesseqgtr ⋚ \lesseqqgtr
  116. ⋚ \lessgtr ≶ \lesssim ≲ \lfloor ⌊ \lhd ◁ \rhd ▷ \ll ≪ \llcorner ⌞
  117. \lnapprox ⋦ \lneq ≨ \lneqq ≨ \lnsim ⋦ \longleftarrow ←
  118. \longleftrightarrow ↔ \longmapsto ↦ \longrightarrow → \looparrowleft ↫
  119. \looparrowright ↬ \lozenge ✧ \lq ‘ \lrcorner ⌟ \ltimes ⋉ \lvertneqq ≨
  120. \maltese ✠ \mapsto ↦ \measuredangle ∡ \mho ℧ \mid ∣ \models ⊧ \mp ∓
  121. \multimap ⊸ \nLeftarrow ⇍ \nLeftrightarrow ⇎ \nRightarrow ⇏ \nVDash ⊯
  122. \nVdash ⊮ \nabla ∇ \napprox ≉ \natural ♮ \ncong ≇ \ne ≠ \nearrow ↗
  123. \neg ¬ \neq ≠ \nequiv ≢ \newline 
 \nexists ∄ \ngeq ≱ \ngeqq ≱
  124. \ngeqslant ≱ \ngtr ≯ \ni ∋ \nleftarrow ↚ \nleftrightarrow ↮ \nleq ≰
  125. \nleqq ≰ \nleqslant ≰ \nless ≮ \nmid ∤ \not ̸ \notin ∉ \nparallel ∦
  126. \nprec ⊀ \npreceq ⋠ \nrightarrow ↛ \nshortmid ∤ \nshortparallel ∦
  127. \nsim ≁ \nsimeq ≄ \nsubset ⊄ \nsubseteq ⊈ \nsubseteqq ⊈ \nsucc ⊁
  128. \nsucceq ⋡ \nsupset ⊅ \nsupseteq ⊉ \nsupseteqq ⊉ \ntriangleleft ⋪
  129. \ntrianglelefteq ⋬ \ntriangleright ⋫ \ntrianglerighteq ⋭ \nu ν \nvDash
  130. ⊭ \nvdash ⊬ \nwarrow ↖ \odot ⊙ \oint ∮ \omega ω \ominus ⊖ \oplus ⊕
  131. \oslash ⊘ \otimes ⊗ \par 
 \parallel ∥ \partial ∂ \perp ⊥ \phi φ \pi π
  132. \pitchfork ⋔ \prec ≺ \precapprox ≾ \preceq ≼ \precnapprox ⋨ \precnsim
  133. ⋨ \precsim ≾ \prime ′ \prod ∏ \propto ∝ \psi ψ \quad   \rangle 〉
  134. \rbrace } \rbrack ] \rceil ⌉ \rfloor ⌋ \rightarrow → \rightarrowtail ↣
  135. \rightharpoondown ⇁ \rightharpoonup ⇀ \rightleftarrows ⇄
  136. \rightleftharpoons ⇌ \rightparengtr 〉 \rightrightarrows ⇉
  137. \rightthreetimes ⋌ \risingdotseq ≓ \rtimes ⋊ \sbs ﹨ \searrow ↘
  138. \setminus ∖ \sharp ♯ \shortmid ∣ \shortparallel ∥ \sigma σ \sim ∼
  139. \simeq ≃ \smallamalg ∐ \smallsetminus ∖ \smallsmile ⌣ \smile ⌣
  140. \spadesuit ♠ \sphericalangle ∢ \sqcap ⊓ \sqcup ⊔ \sqsubset ⊏
  141. \sqsubseteq ⊑ \sqsupset ⊐ \sqsupseteq ⊒ \square □ \squigarrowright ⇝
  142. \star ⋆ \straightphi φ \subset ⊂ \subseteq ⊆ \subseteqq ⊆ \subsetneq ⊊
  143. \subsetneqq ⊊ \succ ≻ \succapprox ≿ \succcurlyeq ≽ \succeq ≽
  144. \succnapprox ⋩ \succnsim ⋩ \succsim ≿ \sum ∑ \supset ⊃ \supseteq ⊇
  145. \supseteqq ⊇ \supsetneq ⊋ \supsetneqq ⊋ \surd √ \swarrow ↙ \tau τ
  146. \therefore ∴ \theta θ \thickapprox ≈ \thicksim ∼ \to → \top ⊤
  147. \triangle ▵ \triangledown ▿ \triangleleft ◃ \trianglelefteq ⊴
  148. \triangleq ≜ \triangleright ▹ \trianglerighteq ⊵ \twoheadleftarrow ↞
  149. \twoheadrightarrow ↠ \ulcorner ⌜ \uparrow ↑ \updownarrow ↕
  150. \upleftharpoon ↿ \uplus ⊎ \uprightharpoon ↾ \upsilon υ \upuparrows ⇈
  151. \urcorner ⌝ \u{i} ĭ \vDash ⊨ \varkappa ϰ \varphi ϕ \varpi ϖ \varprime
  152. ′ \varpropto ∝ \varrho ϱ \varsigma ς \vartheta ϑ \vartriangleleft ⊲
  153. \vartriangleright ⊳ \vdash ⊢ \vdots ⋮ \vee ∨ \veebar ⊻ \vert | \wedge
  154. ∧ \wp ℘ \wr ≀ \xi ξ \zeta ζ \Bbb{N} ℕ \Bbb{P} ℙ \Bbb{R} ℝ \Bbb{Z} ℤ --
  155. – --- — \mu μ \rho ρ \mathscr{I} ℐ \Smiley ☺ \blacksmiley ☻
  156. \Frowny ☹ \Letter ✉ \permil ‰ \registered ® \currency ¤ \dh ð \DH Ð
  157. \th þ \TH Þ \micro µ \lnot ¬ \ordfeminine ª \ordmasculine º \lambdabar
  158. ƛ \celsius ℃ \ldq “ \rdq ” \minus − \defs ≙ \llbracket 〚 \rrbracket 〛
  159. \ldata 《 \rdata 》 \glq ‚ \grq ‘ \glqq „ \"` „ \grqq “ \"' “ \flq ‹
  160. \frq › \flqq « \"< « \frqq » \"> » \- ­ \textmu µ \textfractionsolidus
  161. ⁄ \textbigcircle ⃝ \textmusicalnote ♪ \textdied ✝ \textcolonmonetary ₡
  162. \textwon ₩ \textnaira ₦ \textpeso ₱ \textlira ₤ \textrecipe ℞
  163. \textinterrobang ‽ \textpertenthousand ‱ \textbaht ฿ \textnumero №
  164. \textdiscount ⁒ \textestimated ℮ \textopenbullet ◦ \textlquill ⁅
  165. \textrquill ⁆ \textcircledP ℗ \textreferencemark ※ );
  166. $Tex{'~'} = ' ';
  167. my $TexRe = '(' . join('|', map {quotemeta} sort { $b cmp $a } keys %Tex) . ')';
  168. $TexRe = qr{$TexRe};
  169. push(@MyRules, \&TexRule);
  170. # use of -- conflicts with MarkupRules such as the following:
  171. # $MarkupForcedPairs{'--'} = 'del';
  172. $RuleOrder{\&TexRule} = 160;
  173. sub TexRule {
  174. if (m/\G$TexRe/cg) {
  175. return $Tex{$1};
  176. }
  177. return;
  178. }