#! /usr/bin/perl # Makes a collection of font sample pages for the MathJax fonts # # Usage: ./makeTable %fonts = ( 'MathJax_Main' => "font-family: MathJax_Main;", 'MathJax_Main-Bold' => "font-family: MathJax_Main; font-weight:bold;", 'MathJax_Main-Italic' => "font-family: MathJax_Main; font-style:italic;", 'MathJax_Math-Italic' => "font-family: MathJax_Math; font-style:italic;", 'MathJax_Math-Bold-Italic' => "font-family: MathJax_Math; font-style:italic; font-weight:bold", 'MathJax_Size1' => "font-family: MathJax_Size1;", 'MathJax_Size2' => "font-family: MathJax_Size2;", 'MathJax_Size3' => "font-family: MathJax_Size3;", 'MathJax_Size4' => "font-family: MathJax_Size4;", 'MathJax_Caligraphic' => "font-family: MathJax_Caligraphic;", 'MathJax_Caligraphic-Bold' => "font-family: MathJax_Caligraphic; font-weight:bold;", 'MathJax_Greek' => "font-family: MathJax_Greek;", 'MathJax_Greek-Bold' => "font-family: MathJax_Greek; font-weight:bold", 'MathJax_Greek-Italic' => "font-family: MathJax_Greek; font-style:italic", 'MathJax_Greek-Bold-Italic' => "font-family: MathJax_Greek; font-style:italic; font-weight:bold", 'MathJax_WinChrome' => "font-family: MathJax_WinChrome;", 'MathJax_WinIE6' => "font-family: MathJax_WinIE6;", 'MathJax_AMS' => "font-family: MathJax_AMS;", 'MathJax_Fraktur' => "font-family: MathJax_Fraktur;", 'MathJax_Fraktur-Bold' => "font-family: MathJax_Fraktur; font-weight:bold", 'MathJax_SansSerif' => "font-family: MathJax_SansSerif;", 'MathJax_SansSerif-Bold' => "font-family: MathJax_SansSerif; font-weight:bold", 'MathJax_SansSerif-Italic' => "font-family: MathJax_SansSerif; font-style:italic", 'MathJax_Script' => "font-family: MathJax_Script;", 'MathJax_Typewriter' => "font-family: MathJax_Typewriter;", ); require "unicode.pl"; sub byName { my ($A,$B) = ($a,$b); $A =~ s/Greek/V2_Greek/; $B =~ s/Greek/V2_Greek/; $A =~ s/_(AMS|Caligraphic|Fraktur|Script|SansSerif|Typewriter)/_V1_\1/; $B =~ s/_(AMS|Caligraphic|Fraktur|Script|SansSerif|Typewriter)/_V1_\1/; $A =~ s/-Bold-/-XBold-/; $B =~ s/-Bold-/-XBold-/; return $A cmp $B; } @fonts = sort byName (keys %fonts); sub GetTableData { foreach $font (split(/\n/,`find -L ../../AFM/TeX/fonts -name "*.js"`)) {GetFileData($font)} CountRangeEntries(); } sub GetFileData { my $file = shift; open(INFILE,$file); my @lines = ; close(INFILE); chomp(@lines); FindChars(@lines); } sub FindChars { my $font = ""; my $char; foreach my $line (@_) { if ($line =~ m/FONTDATA.FONTS\['([^']*)'\]/) { $font = $1; $font =~ s/bold/Bold/; $font =~ s/italic/Italic/; } elsif ($font ne "MathJax_Math" && $line =~ m/^ +0x([A-F0-9]*):/) { $char = sprintf("%05X",hex($1)); $CHAR{$char}{$font} = 1; } } } sub CountRangeEntries { foreach my $range (@ranges) { my ($name,$start,$end) = @{$range}; my $N = 0; foreach my $font (@fonts) { my $n = 0; foreach $c ($start..$end) { my $C = sprintf("%05X",$c); $n++ if $CHAR{$C} && $CHAR{$C}{$font}; } $N += $n unless $font =~ m/Greek|_Win/; $count{$font} += $n; $frcount{$font}{$name} = $n; $frcount{$font}{MathJax_All} += $n unless $font =~ m/Greek|_Win/; } $count{MathJax_All} += $N; $frcount{MathJax_All}{$name} = $N; } } sub MakeHeader { my $FONT = shift; my $range = (shift) || ""; @HEADER = ( '', '', 'MathJax Font Table for '.($FONT || "All Fonts").$range.'', '', '', '', '
', '
', '

'.($FONT || "MathJax Font").' Character Tables

', ); } @FOOTER = ( '
', '', '', ); @TABLEstart = ( '', '', '', '', '', '', '', '', '', '', '', ); @TABLEfoot = ( '
', ); @TABLEhead = ( '
0123456789ABCDEF
', '

' ); @ROWstart = (''); @ROWend = (''); sub PrintTOC { mkdir "TeX" unless -d "TeX"; open(HTML,">TeX/index.html"); PrintHTML( '', '', 'MathJax Fonts Unicode Block Table of Contents', '', '', '', '

', '', '', ); my @names = ('Main','Math','Sizen','AMS','Cal',"Frak","SS","Scr","Type",'Greek','Chr','IE6','All'); my @rows = (1,1,1,1,1,1,1,1,1,1,1,1,2); my @columns = (3,2,4,1,2,2,3,1,1,4,1,1,1); my $rows = scalar(@ranges) + 5; print HTML "\n"; print HTML '',"\n"; foreach my $i (0..$#names) { print HTML '',"\n" if $rows[$i]; print HTML '',"\n"; } print HTML "\n"; print HTML "\n"; foreach my $name ('','B','I', 'I','BI', '1','2','3','4', '', '','B', '','B', '','B','I', '', '','B','I','BI', '', '', '') { print HTML '',"\n"; } print HTML "\n"; print HTML '',"\n"; foreach my $range (@ranges) { my ($name,$start,$end) = @{$range}; next unless $frcount{MathJax_All}{$name}; my $file = sprintf("/%04X-%04X.html",$start,$end); print HTML '',"\n"; print HTML '',"\n"; foreach my $font (@fonts) { print HTML '',"\n"; } print HTML ''; print HTML "\n"; } print HTML '',"\n"; print HTML '',"\n"; print HTML '',"\n"; foreach my $font (@fonts,"MathJax_All") { print HTML '',"\n" } print HTML "\n"; PrintHTML( '', '', '', ); close(HTML); } sub PrintFullTable { my $i = shift; my $FONT = ($i ne '' ? $fonts[$i] : ''); my $dir = "TeX/".(substr($FONT,8) || "All"); my $file = "$dir/All.html"; mkdir "TeX" unless -d "TeX"; mkdir $dir unless -d $dir; open(HTML,">",$file); MakeHeader($FONT); PrintHTML(@HEADER); foreach my $j (0..$#ranges) {PrintRange($i,$j)} PrintNavigation($i,''); PrintHTML(@FOOTER); close(HTML); } sub PrintRangeTable { my $i = shift; my $j = shift; my $FONT = ($i ne '' ? $fonts[$i] : ''); my ($name,$start,$end) = @{$ranges[$j]}; return if $frcount{($i eq '' ? "MathJax_All" : $FONT)}{$name} == 0; my $chars = sprintf("%04X-%04X",$start,$end); my $dir = "TeX/".($FONT ? substr($FONT,8) : "All"); my $file = "$dir/$chars.html"; mkdir "TeX" unless -d "TeX"; mkdir $dir unless -d $dir; open(HTML,">",$file); MakeHeader($FONT," ($chars)"); PrintHTML(@HEADER); PrintRange($i,$j); PrintNavigation($i,$j); PrintHTML(@FOOTER); close(HTML); } sub PrintRange { my $i = shift; my $j = shift; my $FONT = ($i ne '' ? $fonts[$i] : ''); my ($name,$start,$end) = @{$ranges[$j]}; return if $frcount{($i eq '' ? "MathJax_All" : $FONT)}{$name} == 0; PrintHTML(@TABLEstart); print HTML sprintf("%s: %04X - %04X",$name,$start,$end); PrintHTML(@TABLEhead); while ($start < $end && !defined($CHAR{sprintf("%05X",$start)})) {$start++} while ($end > $start && !defined($CHAR{sprintf("%05X",$end)})) {$end--} foreach my $row (int($start/0x10)..int($end/0x10)) {PrintRow($FONT,$row,(($name =~ m/Combining/i) ? 'a' : ''))} PrintHTML(@TABLEfoot); } sub PrintRow { my $FONT = shift; my $row = shift; my $combine = shift; my $COMBINE = $combine; $combine = ''.$combine.'' if $combine && $FONT =~ /Size|_AMS/; my $r = sprintf("%03X",$row); $row *= 0x10; PrintHTML(@ROWstart); print HTML '',"\n"; foreach my $i (0x00..0x0F) { my $c = sprintf("%05X",$row+$i); if (defined($CHAR{$c})) { my $title = $CHARNAME{$c}." (".sprintf("0x%X",$row+$i).")"; if ($FONT) { if ($CHAR{$c}{$FONT}) { print HTML ''."\n"; } else { print HTML ''."\n"; } } else { print HTML ''."\n"; } } else { print HTML ''."\n"; } print HTML ''."\n" if $i == 7; } PrintHTML(@ROWend); } sub PrintNavigation { my $i = shift; my $j = shift; my $FONT = ($i ne '' ? $fonts[$i] : 'MathJax_All'); my ($name,$start,$end) = ($j ne '' ? @{$ranges[$j]} : ('MathJax_All',0,0)); my ($pfont,$nfont,$prange,$nrange); my ($pi,$ni,$pj,$nj); if ($i ne "") { ($pi,$ni) = ($i-1,$i+1); ($pfont,$nfont) = ($fonts[$pi],$fonts[$ni]); while ($j && $ni <= $#fonts && $frcount{$nfont}{$name} == 0) {$nfont = $fonts[++$ni]} } else { $pi = $#fonts; $pfont = $fonts[$#fonts]; $ni = 0; $nfont = ""; } while ($j && $pi >= 0 && $frcount{$pfont}{$name} == 0) {$pfont = $fonts[--$pi]} $pfont = "" if $pi < 0; $nfont = "MathJAx_All" if $ni > $#fonts; $pfont = substr($pfont,8); $nfont = substr($nfont,8); my $pfurl = "../".$pfont.($j ne '' ? sprintf("/%04X-%04X.html",$start,$end) : '/All.html'); my $nfurl = "../".$nfont.($j ne '' ? sprintf("/%04X-%04X.html",$start,$end) : '/All.html'); if ($j ne "") { ($pj,$nj) = ($j-1,$j+1); ($prange,$nrange) = ($ranges[$pj],$ranges[$nj]); while ($nj <= $#ranges && $frcount{$FONT}{$nrange->[0]} == 0) {$nrange = $ranges[++$nj]} } else { $pj = $#ranges; $prange = $ranges[$pj]; $nj = 0; $nrange = ['',0,0]; } while ($pj >= 0 && $frcount{$FONT}{$prange->[0]} == 0) {$prange = $ranges[--$pj]} $prange = ['',0,0] if $pj < 0; $nrange = ['All',0,0] if $nj > $#ranges; my $prurl = sprintf("%04X-%04X.html",$prange->[1],$prange->[2]); my $nrurl = ($nrange->[2] ? sprintf("%04X-%04X.html",$nrange->[1],$nrange->[2]) : "All.html"); PrintHTML( '
', '

MathJax Fonts Unicode Block
Table of Contents

', '
1 ? ' ROWSPAN="'.$rows[$i].'"' : ''), ($columns[$i] > 1 ? ' COLSPAN="'.$columns[$i].'"' : ''), '>',$names[$i],'
',$name,'
',$name,'', ($frcount{$font}{$name} ? ''.$frcount{$font}{$name}.'' : ''), '',$frcount{MathJax_All}{$name},'
All',$count{$font},'
'.$r.''.$combine.'&#x'.$c.';'.$combine.' '; foreach my $font (sort byName (keys %{$CHAR{$c}})) { next if $font =~ m/Greek|_Win/; $combine = $COMBINE; $combine = ''.$COMBINE.'' if $COMBINE && $font =~ /Size|_AMS/; print HTML ''. $combine.'&#x'.$c.';'.$combine.'
'; } print HTML '
 
', '', '', '', '', '', '', '', '', '', '', '', '
', ($prange->[0] ? (''.$prange->[0].'
'. '/\') : '..'), '
', ($pfont ? (''.$pfont.' ', '<') : ':'), 'O', ($nfont ? ('> ', ''.$nfont.'') : ':'), '
', ($nrange->[0] ? ('\/
'. ''.$nrange->[0].'') : '..'), '
', '', ); } sub PrintHTML { print HTML join("\n",@_),"\n"; } sub PrintAllTables { foreach my $font (0..$#fonts) { foreach my $range (0..$#ranges) {PrintRangeTable($font,$range)} PrintFullTable($font); } foreach my $range (0..$#ranges) {PrintRangeTable('',$range)} PrintFullTable(''); } GetTableData(); PrintTOC(); PrintAllTables(); 1;