fractions.pl 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright (C) 2013 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('fractions.pl', 'Fractions');
  18. our (@MyRules);
  19. push(@MyRules, \&FractionsRule);
  20. # usage: ^1/32
  21. sub FractionsRule {
  22. if (/\G\^([0-9]+)\/([0-9]+)/cg) {
  23. if ($1 == 1 and $2 == 4) { return "\&#x00bc;"; }
  24. elsif ($1 == 1 and $2 == 2) { return "\&#x00bd;"; }
  25. elsif ($1 == 3 and $2 == 4) { return "\&#x00be;"; }
  26. elsif ($1 == 1 and $2 == 7) { return "\&#x2150;"; }
  27. elsif ($1 == 1 and $2 == 9) { return "\&#x2151;"; }
  28. elsif ($1 == 1 and $2 == 10) { return "\&#x2152;"; }
  29. elsif ($1 == 1 and $2 == 3) { return "\&#x2153;"; }
  30. elsif ($1 == 2 and $2 == 3) { return "\&#x2154;"; }
  31. elsif ($1 == 1 and $2 == 5) { return "\&#x2155;"; }
  32. elsif ($1 == 2 and $2 == 5) { return "\&#x2156;"; }
  33. elsif ($1 == 3 and $2 == 5) { return "\&#x2157;"; }
  34. elsif ($1 == 4 and $2 == 5) { return "\&#x2158;"; }
  35. elsif ($1 == 1 and $2 == 6) { return "\&#x2159;"; }
  36. elsif ($1 == 5 and $2 == 6) { return "\&#x215a;"; }
  37. elsif ($1 == 1 and $2 == 8) { return "\&#x215b;"; }
  38. elsif ($1 == 3 and $2 == 8) { return "\&#x215c;"; }
  39. elsif ($1 == 5 and $2 == 8) { return "\&#x215d;"; }
  40. elsif ($1 == 7 and $2 == 8) { return "\&#x215e;"; }
  41. else {
  42. my $html;
  43. # superscripts
  44. for my $char (split(//, $1)) {
  45. if ($char eq '1') { $html .= "\&#x00b9;"; }
  46. elsif ($char eq '2') { $html .= "\&#x00b2;"; }
  47. elsif ($char eq '3') { $html .= "\&#x00b3;"; }
  48. else { $html .= "\&#x207$char;"; }
  49. }
  50. # fraction slash
  51. $html .= '&#x2044;';
  52. # subscripts
  53. for my $char (split(//, $2)) {
  54. $html .= "\&#x208$char;";
  55. }
  56. return $html;
  57. }
  58. }
  59. return;
  60. }