[LON-CAPA-cvs] cvs: modules /gerd symbolfont.pl

www lon-capa-cvs@mail.lon-capa.org
Fri, 27 May 2005 01:49:07 -0000


www		Thu May 26 21:49:07 2005 EDT

  Modified files:              
    /modules/gerd	symbolfont.pl 
  Log:
  Seems to work now - not sure yet what to do with it, though.
  
  
Index: modules/gerd/symbolfont.pl
diff -u modules/gerd/symbolfont.pl:1.3 modules/gerd/symbolfont.pl:1.4
--- modules/gerd/symbolfont.pl:1.3	Thu May 26 15:46:55 2005
+++ modules/gerd/symbolfont.pl	Thu May 26 21:49:05 2005
@@ -1,130 +1,176 @@
-'±' => '\pm',
-'´' => '\times',
-'¸' => '\div',
-'Ò' => '(R)',
-'Ó' => '\copy',
-'Ø' => '\neg',
-'â' => '(R)',
-'ã' => '\copy',
-'¦' => 'f',
-'A' => '\Alpha',
-'B' => '\Beta',
-'G' => '\Gamma',
-'D' => '\Delta',
-'E' => '\Epsilon',
-'Z' => '\Zeta',
-'H' => '\Eta',
-'Q' => '\Theta',
-'I' => '\Iota',
-'K' => '\Kappa',
-'L' => '\Lambda',
-'M' => '\Mu',
-'N' => '\Nu',
-'X' => '\Xi',
-'O' => '\Omicron',
-'P' => '\Pi',
-'R' => '\Rho',
-'S' => '\Sigma',
-'T' => '\Tau',
-'U' => 'Y',
-'F' => '\Phi',
-'C' => '\Chi',
-'Y' => '\Psi',
-'W' => '\Omega',
-'a' => '\alpha',
-'b' => '\beta',
-'g' => '\gamma',
-'d' => '\delta',
-'e' => '\epsilon',
-'z' => '\zeta',
-'h' => '\eta',
-'q' => '\theta',
-'i' => '\iota',
-'k' => '\kappa',
-'l' => '\lambda',
-'m' => '\mu',
-'n' => '\nu',
-'x' => '\xi',
-'o' => '\omicron',
-'p' => '\pi',
-'r' => '\rho',
-'V' => '\sigmaf',
-'s' => '\sigma',
-'t' => '\tau',
-'u' => '\upsilon',
-'f' => '\phi',
-'c' => '\chi',
-'y' => '\psi',
-'w' => '\omega',
-'J' => '\vartheta',
-'j' => '\varphi',
-'v' => '\varpi',
-'¡' => '\Upsilon',
-'¢' => "'",
-'¤' => '/',
-'²' => '"',
-'¼' => '\ldots',
-'À' => '\aleph',
-'Á' => '\Im',
-'Â' => '\Re',
-'Ã' => '\wp',
-'Ô' => '^{TM}',
-'ä' => '^{TM}',
-'ð' => 'EUR',
-'«' => '\leftrightarrow',
-'¬' => '\leftarrow',
-'­' => '\uparrow',
-'®' => '\rightarrow',
-'¯' => '\downarraw',
-'¿' => '\hookleftarrow',
-'Û' => '\Leftrightarrow',
-'Ü' => '\Leftarrow',
-'Ý' => '\Uparrow',
-'Þ' => '\Rightarrow',
-'ß' => '\Downarrow',
-'"' => '\forall',
-'$' => '\exists',
-''' => '\ni',
-'*' => '\ast',
-'-' => '-',
-'@' => '\cong',
-'\' => '\therefore',
-'^' => '\perp',
-'~' => '\sim',
-'£' => '\leq',
-'¥' => '\infty',
-'³' => '\geq',
-'µ' => '\propto',
-'¶' => '\partial',
-'·' => '\cdot',
-'¹' => '\not=',
-'º' => '\equiv',
-'»' => '\approx',
-'Ä' => '\otimes',
-'Å' => '\oplus',
-'Æ' => '\emptyset',
-'Ç' => '\cap',
-'È' => '\cup',
-'É' => '\supset',
-'Ê' => '\supseteq',
-'Ë' => '\not\subset',
-'Ì' => '\subset',
-'Í' => '\subseteq',
-'Î' => '\in',
-'Ï' => '\not\in',
-'Ð' => '\angle',
-'Ñ' => '\nabla',
-'Õ' => '\prod',
-'Ö' => '\surd',
-'×' => '\cdot',
-'Ù' => '\wedge',
-'Ú' => '\wee',
-'å' => '\sum',
-'ò' => '\int',
-'á' => '\langle',
-'ñ' => '\rangle',
-'à' => '\diamondsuit',
-'§' => '\clubsuit',
-'¨' => '\diamondsuit',
-'©' => '\heartsuit',
-'ª' => '\spadesuit',
+sub latextrans {
+    my $symbolfont=shift;
+    my %latexsymb=(
+		   '±' => '\pm',
+		   '´' => '\times',
+		   '¸' => '\div',
+		   'Ò' => '(R)',
+		   'Ó' => '\copy',
+		   'Ø' => '\neg',
+		   'â' => '(R)',
+		   'ã' => '\copy',
+		   '¦' => 'f',
+		   'A' => '\Alpha',
+		   'B' => '\Beta',
+		   'G' => '\Gamma',
+		   'D' => '\Delta',
+		   'E' => '\Epsilon',
+		   'Z' => '\Zeta',
+		   'H' => '\Eta',
+		   'Q' => '\Theta',
+		   'I' => '\Iota',
+		   'K' => '\Kappa',
+		   'L' => '\Lambda',
+		   'M' => '\Mu',
+		   'N' => '\Nu',
+		   'X' => '\Xi',
+		   'O' => '\Omicron',
+		   'P' => '\Pi',
+		   'R' => '\Rho',
+		   'S' => '\Sigma',
+		   'T' => '\Tau',
+		   'U' => 'Y',
+		   'F' => '\Phi',
+		   'C' => '\Chi',
+		   'Y' => '\Psi',
+		   'W' => '\Omega',
+		   'a' => '\alpha',
+		   'b' => '\beta',
+		   'g' => '\gamma',
+		   'd' => '\delta',
+		   'e' => '\epsilon',
+		   'z' => '\zeta',
+		   'h' => '\eta',
+		   'q' => '\theta',
+		   'i' => '\iota',
+		   'k' => '\kappa',
+		   'l' => '\lambda',
+		   'm' => '\mu',
+		   'n' => '\nu',
+		   'x' => '\xi',
+		   'o' => '\omicron',
+		   'p' => '\pi',
+		   'r' => '\rho',
+		   'V' => '\sigmaf',
+		   's' => '\sigma',
+		   't' => '\tau',
+		   'u' => '\upsilon',
+		   'f' => '\phi',
+		   'c' => '\chi',
+		   'y' => '\psi',
+		   'w' => '\omega',
+		   'J' => '\vartheta',
+		   'j' => '\varphi',
+		   'v' => '\varpi',
+		   '¡' => '\Upsilon',
+		   '¢' => "'",
+		   '¤' => '/',
+		   '²' => '"',
+		   '¼' => '\ldots',
+		   'À' => '\aleph',
+		   'Á' => '\Im',
+		   'Â' => '\Re',
+		   'Ã' => '\wp',
+		   'Ô' => '^{TM}',
+		   'ä' => '^{TM}',
+		   'ð' => 'EUR',
+		   '«' => '\leftrightarrow',
+		   '¬' => '\leftarrow',
+		   '­' => '\uparrow',
+		   '®' => '\rightarrow',
+		   '¯' => '\downarraw',
+		   '¿' => '\hookleftarrow',
+		   'Û' => '\Leftrightarrow',
+		   'Ü' => '\Leftarrow',
+		   'Ý' => '\Uparrow',
+		   'Þ' => '\Rightarrow',
+		   'ß' => '\Downarrow',
+		   '"' => '\forall',
+		   '$' => '\exists',
+		   ''' => '\ni',
+		   '*' => '\ast',
+		   '-' => '-',
+		   '@' => '\cong',
+		   '\' => '\therefore',
+		   '^' => '\perp',
+		   '~' => '\sim',
+		   '£' => '\leq',
+		   '¥' => '\infty',
+		   '³' => '\geq',
+		   'µ' => '\propto',
+		   '¶' => '\partial',
+		   '·' => '\cdot',
+		   '¹' => '\not=',
+		   'º' => '\equiv',
+		   '»' => '\approx',
+		   'Ä' => '\otimes',
+		   'Å' => '\oplus',
+		   'Æ' => '\emptyset',
+		   'Ç' => '\cap',
+		   'È' => '\cup',
+		   'É' => '\supset',
+		   'Ê' => '\supseteq',
+		   'Ë' => '\not\subset',
+		   'Ì' => '\subset',
+		   'Í' => '\subseteq',
+		   'Î' => '\in',
+		   'Ï' => '\not\in',
+		   'Ð' => '\angle',
+		   'Ñ' => '\nabla',
+		   'Õ' => '\prod',
+		   'Ö' => '\surd',
+		   '×' => '\cdot',
+		   'Ù' => '\wedge',
+		   'Ú' => '\wee',
+		   'å' => '\sum',
+		   'ò' => '\int',
+		   'á' => '\langle',
+		   'ñ' => '\rangle',
+		   'à' => '\diamondsuit',
+		   '§' => '\clubsuit',
+		   '¨' => '\diamondsuit',
+		   '©' => '\heartsuit',
+		   'ª' => '\spadesuit'
+		   );
+    my $output='';
+    my $char='';
+    my $entitymode=0;
+    for (my $i=0; $i<length($symbolfont); $i++) {
+        my $newchar=substr($symbolfont,$i,1);
+        $char.=$newchar;
+        if ($newchar eq '&') { $entitymode=1; }
+        if (($entitymode) && ($newchar ne ';')) { next; }
+        my $latex=$latexsymb{$char};
+	if ($latex) {
+	    $output.=$latex;
+	} else {
+	    $output.=$char;
+	}
+        $char='';
+        $entitymode=0;
+    }
+    return $output;
+}
+
+sub insidetrans {
+    my @args=@_;
+    return '<font'.$args[0].$args[1].'><m>$'.&latextrans($args[2]).'$</m>';
+}
+
+sub symbolfontreplace {
+    my $text=shift;
+    my @fragments=split(/\<\/font\>/si,$text);
+    for (my $i=0; $i<=$#fragments;$i++) {
+	$fragments[$i]=~s/\<font([^\>]*)\s+face=[\"\']*symbol[\"\']*([^\>]*)\>(.*)$/&insidetrans($1,$2,$3)/gsie;
+    }
+    return join('</font>',@fragments);
+}
+
+print &symbolfontreplace(<<'ENDTEXT');
+<h1>Test</h1>
+This is a test <font face="symboL" size="+2">ab+de&#165;+a</FONT> and <font Face="symbol">X</font> end-of-line
+<font face="symboL" size="+2">abde</FONT> <font color="red">Hello World</font>
+Yes.
+ENDTEXT
+print &symbolfontreplace('Nothing in here.')."\n";
+