File: compileschema

package info (click to toggle)
latexml 0.8.8-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,920 kB
  • sloc: xml: 109,048; perl: 30,224; sh: 179; javascript: 28; makefile: 13
file content (90 lines) | stat: -rwxr-xr-x 4,304 bytes parent folder | download | duplicates (3)
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
#!/bin/bash
# /=====================================================================\ #
# |  compileschema                                                      | #
# | Convert compact RelaxNG (rnc) to various required formats           | #
# |=====================================================================| #
# | 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=/ #

#======================================================================
# Convert & Compile LaTeXML's schema from the RelaxNG Compact Form
# generating the rng forms;
# the compiled model list
#======================================================================

# bash analog of FindBin::RealBin
TOOLSDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# We're assuming this script is in latexml/tools
LATEXMLDIR=$TOOLSDIR/..
# Note that we go to lengths to work in the source lib directory,
# NOT in the blib/lib directory.
# We are pre-compiling schema that will be commited to the repository.
RESOURCEDIR=$LATEXMLDIR/lib/LaTeXML/resources
RELAXNGDIR=$RESOURCEDIR/RelaxNG

TRANG="trang -C $LATEXMLDIR/lib/LaTeXML/LaTeXML.catalog"

TMP=/tmp/LaTeXML$$
mkdir $TMP

SCHEMA=LaTeXML

# Point to catalog in lib directory (NOT in blib/lib)
export XML_CATALOG_FILES=$LATEXMLDIR/lib/LaTeXML/LaTeXML.catalog

#======================================================================
# Conversion of rnc (easy to write) to rng (easy to use)
# This is the important part.
#======================================================================
echo "Converting $SCHEMA.rnc to $SCHEMA.rng"
# Assuming trang executes trang-20091111
$TRANG $RELAXNGDIR/$SCHEMA.rnc $TMP/$SCHEMA.rng

# Silly trang puts all converted rng for all the modules in the same directory.
# Also mungs up the urn's naming them.
# Move them back into the lib (NOT blib/lib) directory & fix up the URN's

for RNG in $TMP/LaTeXML*.rng; do
  sed \
      -e "s/include href=\"LaTeXML-/include href=\"urn:x-LaTeXML:RelaxNG:LaTeXML-/" \
      -e "s/include href=\"svg/include href=\"urn:x-LaTeXML:RelaxNG:svg:svg/" \
      $RNG > $RELAXNGDIR/$(basename $RNG)
done

for RNG in $TMP/svg*.rng; do
  sed \
      -e "s/include href=\"LaTeXML-/include href=\"urn:x-LaTeXML:RelaxNG:LaTeXML-/" \
      -e "s/include href=\"svg/include href=\"urn:x-LaTeXML:RelaxNG:svg:svg/" \
      $RNG > $RELAXNGDIR/svg/$(basename $RNG)
done

#======================================================================
# Compiling schema to quick loading form.
#======================================================================
echo "Precompiling $SCHEMA.rng schema to $SCHEMA.model"
 perl -I $LATEXMLDIR/blib/lib -MLaTeXML -MLaTeXML::Common::Error \
       -e "UseSTDERR(); my \$latexml = LaTeXML::Core->new(searchpaths=>['$RELAXNGDIR'], verbosity=>2);
              \$latexml->withState( sub{                             \
              \$latexml->initializeState(); \
              my \$state = \$_[0];                        \
              my \$model = \$state->getModel;             \
              \$model->registerNamespace(ltx=>'http://dlmf.nist.gov/LaTeXML');\
              \$model->registerNamespace(svg=>'http://www.w3.org/2000/svg');  \
              \$model->registerNamespace(xhtml => 'http://www.w3.org/1999/xhtml'); \
              \$model->registerNamespace(xlink => 'http://www.w3.org/1999/xlink'); \
              \$model->setRelaxNGSchema('$SCHEMA');         \
              \$model->compileSchema;                       \
              print STDERR \$state->getStatusMessage.\"\n\";});" \
       > $RELAXNGDIR/$SCHEMA.model

#======================================================================
# If ok...
echo "==============================="
echo "If that appears to have worked,"
echo "run make; make test and commit"
#======================================================================