Skip to content

Generated SVG images from MathML #6

Generated SVG images from MathML

Generated SVG images from MathML #6

name: generate-svg-from-mathml
run-name: "Generated SVG images from MathML"
on:
push:
branches-ignore:
- master
- development
paths:
- doc/equations/**.xml
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
DOCBOOK_SOURCE_DIR: ${{ github.workspace }}/doc
DOCBOOK_BUILD_DIR: ${{ github.workspace }}/build
JAVA_VERSION: openjdk-11-jdk
JAVA_HOME: /usr/lib/jvm/java-8-openjdk-amd64
jobs:
convert-mathml-to-svg:
strategy:
fail-fast: true
runs-on: ubuntu-24.04
steps:
- name: Install missing software
run: |
sudo apt update && sudo apt install $JAVA_VERSION fd-find
- name: Checkout sources
uses: actions/checkout@v3
- name: Download XML Calabash 3.0.32
uses: ethanjli/cached-download-action@v0.1.3
with:
url: https://codeberg.org/xmlcalabash/xmlcalabash3/releases/download/3.0.32/xmlcalabash-3.0.32.zip
destination: /tmp/xmlcalabash-3.0.32.zip
- name: Install XML Calabash 3.0.32
run: |
cd /tmp ; unzip /tmp/xmlcalabash-3.0.32.zip
- name: Test if it works
run: |
cd /tmp/xmlcalabash-3.0.32 ; java -jar xmlcalabash-app-3.0.32.jar helloWorld.xpl ; ls
echo '<?xml version="1.0" encoding="UTF-8"?><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow><mi>x</mi><mo>=</mo><mfrac><mrow><mo>−</mo><mi>b</mi><mo>±</mo><msqrt><msup><mi>b</mi><mn>2</mn></msup><mo>−</mo><mn>4</mn><mi>a</mi><mi>c</mi></msqrt></mrow><mrow><mn>2</mn><mi>a</mi></mrow></mfrac> </mrow></math>' > /tmp/xmlcalabash-3.0.32/equation.xml
echo '<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:cx="http://xmlcalabash.com/ns/extensions" version="3.0" name="main"><p:import href="https://xmlcalabash.com/ext/library/diagramming.xpl"/><p:input port="source" content-types="xml"/><p:output port="result" content-types="xml"/><cx:mathml-to-svg></cx:mathml-to-svg></p:declare-step>' > /tmp/xmlcalabash-3.0.32/pipeline.xpl
cd /tmp/xmlcalabash-3.0.32 ; java -jar xmlcalabash-app-3.0.32.jar pipeline.xpl --input:source=equation.xml --output:result=image.svg; ls
cat /tmp/xmlcalabash-3.0.32/image.svg
- name: Convert the equations to SVG
run: |
cd ${{ github.workspace }} ; fdfind -e xml . 'doc/equations' -x java -jar /tmp/xmlcalabash-3.0.32/xmlcalabash-app-3.0.32.jar /tmp/xmlcalabash-3.0.32/pipeline.xpl --input:source={} --output:result={.}.svg
cd ${{ github.workspace }} ; fdfind -e svg . 'doc/equations' -x sed -i 's/<?xml version="1.0" encoding="UTF-8"?>//g' {}
ls ${{ github.workspace }}/doc/equations
- name: Add and commit regenerated SVG files
uses: EndBug/add-and-commit@v9
with:
add: ${{ github.workspace }}/doc/equations/*.svg
message: 'Automatically generated SVG images'
committer_name: GitHub Actions
committer_email: actions@github.com