1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#!/usr/bin/perl -w
# /=====================================================================\ #
# | compilemetrics | #
# | Convert Tex Font Metrics to internal format | #
# |=====================================================================| #
# | support tools for LaTeXML: | #
# | Public domain software, produced as part of work done by the | #
# | United States Government & not subject to copyright in the US. | #
# |---------------------------------------------------------------------| #
# | Bruce Miller <bruce.miller@nist.gov> #_# | #
# | http://dlmf.nist.gov/LaTeXML/ (o o) | #
# \=========================================================ooo==U==ooo=/ #
use strict;
use warnings;
use FindBin;
# Assume we're in the tools directory of a development version of latexml (next to lib, blib..)
use lib "$FindBin::RealBin/../blib/lib";
use LaTeXML;
use LaTeXML::Package;
use LaTeXML::Common::Error;
use LaTeXML::Common::Font::Metric;
use Data::Dumper;
#======================================================================
# Convert a set of TeX Font Metrics into a prepared module
#======================================================================
# A little awkwardness in that we have to run within LaTeXML,
# since the needed font encodings are embedded within (or only findable within) LaTeXML.
my $MODULEPATH = "$FindBin::RealBin/../lib/LaTeXML/Common/Font/StandardMetrics.pm";
my $FONTDIR = '/usr/share/texlive/texmf-dist/fonts/tfm/public';
# Should be using kpsewhich, but...
my $SIZE = 10;
my $HEADER;
SetVerbosity(1);
UseSTDERR();
my $latexml = LaTeXML::Core->new();
$latexml->withState(sub {
my ($state) = @_;
$latexml->initializeState();
LoadPool('LaTeX');
my $metrics = {
# Core TeX font/encodings
cmr => read_tfm('OT1', "$FONTDIR/cm/cmr$SIZE.tfm"),
cmm => read_tfm('OML', "$FONTDIR/cm/cmmi$SIZE.tfm"),
cmsy => read_tfm('OMS', "$FONTDIR/cm/cmsy$SIZE.tfm"),
cmex => read_tfm('OMX', "$FONTDIR/cm/cmex$SIZE.tfm"),
# AMS fonts
amsa => read_tfm('AMSa', "$FONTDIR/amsfonts/symbols/msam$SIZE.tfm"),
amsb => read_tfm('AMSb', "$FONTDIR/amsfonts/symbols/msbm$SIZE.tfm"),
# Could include others; italic, bold,... How to access them?
};
my $dumper = Data::Dumper->new([$metrics], [qw(STDMETRICS)]);
$dumper->Indent(0);
$dumper->Sortkeys(1);
my $FH;
open($FH, ">", $MODULEPATH);
print $FH $HEADER;
print $FH "our " . $dumper->Dump();
print $FH "1;\n";
close($FH);
print STDERR "Wrote Standard font metrics to $MODULEPATH\n";
return; });
sub read_tfm {
my ($encoding, $file) = @_;
LoadFontMap($encoding);
return LaTeXML::Common::Font::Metric->new($encoding, $file); }
#======================================================================
BEGIN {
$HEADER = << 'EoHeader';
#!/usr/bin/perl -w
# /=====================================================================\ #
# | Standard Font Metrics | #
# | Converted Tex Font Metrics for LaTeXML | #
# |=====================================================================| #
# | Bruce Miller <bruce.miller@nist.gov> #_# | #
# | http://dlmf.nist.gov/LaTeXML/ (o o) | #
# \=========================================================ooo==U==ooo=/ #
# THIS IS A GENERATED FILE! DO NOT EDIT
# (see LaTeXML/tools/compilemetrics)
use strict;
use warnings;
package LaTeXML::Common::Font::StandardMetrics;
EoHeader
}
|