Skip to content

Commit

Permalink
chore(build): Setup actual regeneration rules for Unicode XML to Lua …
Browse files Browse the repository at this point in the history
…conversion
  • Loading branch information
alerque committed Nov 23, 2024
1 parent fc7633f commit 84c0654
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 56 deletions.
6 changes: 3 additions & 3 deletions Makefile-fonts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

if FONT_DOWNLOAD_TOOLS

# Target defined in Makefile.am, just adding a dependency here
.sources: fonttooling

.fonts: fonttooling
[ -h .fonts ] || mkdir -p $@

.sources: fonttooling
[ -h .sources ] || mkdir -p $@

fonttooling:
$(if $(BSDTAR),,$(error Please set BSDTAR with path or `./configure --enable-developer-mode`))
$(if $(CURL),,$(error Please set CURL with path or `./configure --enable-developer-mode`))
Expand Down
17 changes: 17 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ dist_license_DATA = LICENSE.md
EXTRA_DIST = spec tests documentation sile-dev-1.rockspec fontconfig.conf
EXTRA_DIST += build-aux/action-updater.js build-aux/cargo-updater.js build-aux/config.ld build-aux/decore-automake.sh build-aux/git-version-gen
EXTRA_DIST += Dockerfile build-aux/docker-bootstrap.sh build-aux/docker-fontconfig.conf hooks/build
EXTRA_DIST += build-aux/xml-entities-to-lua.xsl
EXTRA_DIST += default.nix flake.nix flake.lock shell.nix build-aux/pkg.nix
EXTRA_DIST += package.json # imported by both Nix and Docker
EXTRA_DIST += $(FIGURES)
Expand All @@ -94,6 +95,10 @@ else !SHARED
EXTRA_RUNTIME_DEPS =
endif

MATHML_ENTITIES = packages/math/mathml-entities.lua
EXTRA_DIST += $(MATHML_ENTITIES)
BUILT_SOURCES += $(MATHML_ENTITIES)

CLEANFILES = $(MANUAL)

DISTCLEANFILES = @AMINCLUDE@
Expand Down Expand Up @@ -312,6 +317,18 @@ patterndeps = $(_FORCED) $(_TEST_DEPS) $(_DOCS_DEPS) | $(bin_PROGRAMS) $(EXTRA_R
$(DOT) -Tpdf $< -o $@.gs
$(GS) -q -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -o $@ $@.gs

XML_ENTITIES = .sources/unicode.xml
XML_ENTITIES_COMMIT = 77acf14428202e4e1dba54ff1e5ed43fe5ab474f

.sources:
[ -h .sources ] || mkdir -p $@

$(XML_ENTITIES):
$(CURL) https://raw.githubusercontent.com/w3c/xml-entities/$(XML_ENTITIES_COMMIT)/unicode.xml -o $@

$(MATHML_ENTITIES): build-aux/xml-entities-to-lua.xsl
$(XSLTPROC) $< $(XML_ENTITIES) | $(or $(STYLUA),cat) - > $@

.PHONY: force
force: ;

Expand Down
2 changes: 2 additions & 0 deletions build-aux/pkg.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
icu,
fontconfig,
libiconv,
libxslt,
stylua,
taplo,
typos,
Expand Down Expand Up @@ -125,6 +126,7 @@ stdenv.mkDerivation (finalAttrs: {
icu
fontconfig
libiconv
libxslt
stylua
taplo
typos
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
Stylesheet to convert the unicode.xml file to a SILE Lua file:
xsltproc unicode-xml-to-sile.xsl unicode.xml > ../packages/math/unicode-symbols-generated.lua
Where unicode.xml is:
https://raw.githubusercontent.com/w3c/xml-entities/gh-pages/unicode.xml
-->
<xsl:output method="text" indent="no"/>

<xsl:template name="format-value">
Expand Down Expand Up @@ -96,16 +90,16 @@
-- Originally designed by Sebastian Rahtz in conjunction with Barbara Beeton for the STIX project
--

local atoms = require("packages/math/atoms")
local atoms = require("packages.math.atoms")

--- Transform a list of codepoints into a string
local function U (...)
local t = { ... }
local str = ""
for i = 1, #t do
str = str .. luautf8.char(t[i])
end
return str
local t = { ... }
local str = ""
for i = 1, #t do
str = str .. luautf8.char(t[i])
end
return str
end

local symbols = {}
Expand All @@ -118,33 +112,33 @@ local operatorDict = {}
-- @tparam string _ Unicode name of the symbol (informative)
-- @tparam table ops List of operator forms and their properties
local function addSymbol (str, shortatom, mathlatex, _, ops)
if mathlatex then
SU.debug("math.symbols", "Registering symbol", str, "as", mathlatex)
symbols[mathlatex] = str
end
local op = {}
op.atom = atoms.types[shortatom]
if ops then
op.forms = {}
for _, v in pairs(ops) do
if v.form then
-- NOTE: At this point the mu unit is not yet defined, so keep it as a string.
v.lspace = v.lspace and ("%smu"):format(v.lspace) or "0mu"
v.rspace = v.rspace and ("%smu"):format(v.rspace) or "0mu"
op.forms[v.form] = v
else
SU.warn("No form for operator " .. str .. " (operator dictionary is probably incomplete)")
if mathlatex then
SU.debug("math.symbols", "Registering symbol", str, "as", mathlatex)
symbols[mathlatex] = str
end
local op = {}
op.atom = atoms.types[shortatom]
if ops then
op.forms = {}
for _, v in pairs(ops) do
if v.form then
-- NOTE: At this point the mu unit is not yet defined, so keep it as a string.
v.lspace = v.lspace and ("%smu"):format(v.lspace) or "0mu"
v.rspace = v.rspace and ("%smu"):format(v.rspace) or "0mu"
op.forms[v.form] = v
else
SU.warn("No form for operator " .. str .. " (operator dictionary is probably incomplete)")
end
end
end
end
operatorDict[str] = op
end
operatorDict[str] = op
end

<xsl:apply-templates select="charlist/character" />

return {
operatorDict = operatorDict,
symbols = symbols
operatorDict = operatorDict,
symbols = symbols,
}
</xsl:template>

Expand All @@ -160,42 +154,46 @@ return {
</xsl:call-template>
</xsl:variable>
<xsl:if test="$atom != 'ord' or $mathlatex or operator-dictionary">
<xsl:text>
addSymbol(</xsl:text>
<!-- Codepoints -->
<xsl:text>addSymbol(</xsl:text>
<!-- Codepoints -->
<xsl:call-template name="format-codepoint">
<xsl:with-param name="codepoint" select="@id" />
</xsl:call-template>
<!-- Atom type -->
<xsl:text>, "</xsl:text><xsl:value-of select="$atom" /><xsl:text>", </xsl:text>
<xsl:text>,"</xsl:text><xsl:value-of select="$atom" /><xsl:text>",</xsl:text>
<!-- Math latex name or nil -->
<xsl:call-template name="format-mathlatex">
<xsl:with-param name="mathlatex" select="$mathlatex" />
</xsl:call-template>
<!-- Description -->
<xsl:text>, "</xsl:text><xsl:value-of select="description" /><xsl:text>"</xsl:text>
<xsl:text>,"</xsl:text><xsl:value-of select="description" /><xsl:text>"</xsl:text>
<!-- Operator dictionary or nil -->
<xsl:choose>
<xsl:when test="operator-dictionary">
<xsl:text>, {</xsl:text>
<xsl:apply-templates select="operator-dictionary">
<xsl:sort select="@priority" data-type="number" order="descending" /><!-- sort by @priority -->
</xsl:apply-templates>
<xsl:text>,{</xsl:text>
<xsl:apply-templates select="operator-dictionary">
<!-- sort by @priority -->
<xsl:sort select="@priority" data-type="number" order="descending" />
</xsl:apply-templates>
<xsl:text>}</xsl:text>
</xsl:when>
<xsl:otherwise><xsl:text>, nil</xsl:text></xsl:otherwise>
<xsl:otherwise><xsl:text>,nil</xsl:text></xsl:otherwise>
</xsl:choose>
<xsl:text>)</xsl:text>
</xsl:if>
</xsl:template>

<xsl:template match="operator-dictionary">
{ <xsl:for-each select="@*">
{
<xsl:for-each select="@*">
<xsl:sort select="name()" />
<xsl:value-of select="name()" /> = <xsl:call-template name="format-value">
<xsl:with-param name="value" select="." />
</xsl:call-template><xsl:if test="position() != last()">, </xsl:if>
</xsl:for-each> }<xsl:if test="position() != last()">,</xsl:if>
<xsl:value-of select="name()" />
=
<xsl:call-template name="format-value">
<xsl:with-param name="value" select="." />
</xsl:call-template>,
</xsl:for-each>
},
</xsl:template>

</xsl:stylesheet>
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ AM_CONDITIONAL([ICU], [test "x$with_icu" = "xyes"])
# Required for downloading fonts for the manual and for tests
# Since the source tarball includes a prebuilt manual we only need this for Git source builds
AM_COND_IF([FONT_DOWNLOAD_TOOLS], [
QUE_PROGVAR([curl])
QUE_PROGVAR([bsdtar])
QUE_PROGVAR([curl])
])

AM_COND_IF([DEVELOPER_MODE], [
Expand All @@ -197,6 +197,7 @@ AM_COND_IF([DEVELOPER_TOOLS], [
QUE_PROGVAR([taplo])
QUE_PROGVAR([tr])
QUE_PROGVAR([typos])
QUE_PROGVAR([xsltproc])
])

AX_PROG_LUA([5.1], [], [], [], [prefer])
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions packages/math/unicode-symbols.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--- Extend the unicode-symbols-generated symbols with additional aliases.
local gen = require("packages/math/unicode-symbols-generated")
local symbols = gen.symbols
local operatorDict = gen.operatorDict
local mathml_entities = require("packages.math.mathml-entities")
local symbols = mathml_entities.symbols
local operatorDict = mathml_entities.operatorDict

--- Add aliases for symbols that have multiple names.
-- We check that the alias is already defined in the generated dictionary,
Expand Down

0 comments on commit 84c0654

Please sign in to comment.