diff --git a/Gruntfile.js b/Gruntfile.js index 8d8300b..9c18386 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -144,13 +144,32 @@ module.exports = function(grunt) { }, options: { livereload: true + }, + // Fachschaft WIAI: Convert TeX to SVG once a file changes + tex: { + files: [ + 'sections/*/*/*.tex', + '!sections/*/*/tmp-pdfcrop*' + ], + tasks: 'tex2svg', + options: { nospawn: true } } }, retire: { js: [ 'js/reveal.js', 'lib/js/*.js', 'plugin/**/*.js' ], node: [ '.' ] - } + }, + + // Fachschaft WIAI: Necessary for tex2svg + + texFilepath: '', + + shell: { + tex2svg: { + command: './tex2svg-single.sh <%= texFilepath %>' + }, + }, }); @@ -166,6 +185,9 @@ module.exports = function(grunt) { grunt.loadNpmTasks( 'grunt-sass' ); grunt.loadNpmTasks( 'grunt-zip' ); + // Fachschaft WIAI dependency: + grunt.loadNpmTasks( 'grunt-shell' ); + // Default task grunt.registerTask( 'default', [ 'css', 'js' ] ); @@ -190,4 +212,17 @@ module.exports = function(grunt) { // Run tests grunt.registerTask( 'test', [ 'jshint', 'qunit' ] ); + // Fachschaft WIAI Adaption + // ======================== + + grunt.event.on('watch', function (action, filepath) { + if (/.*\.tex$/.test(filepath)) { + grunt.config.set('texFilepath', grunt.config.escape(filepath)); + } + }); + + grunt.registerTask( 'tex2svg', 'Convert TeX to SVG', function(a) { + grunt.task.run('shell:tex2svg'); + }); + }; diff --git a/package.json b/package.json index cb8a711..e954a03 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ }, "devDependencies": { "express": "^4.16.2", - "grunt": "^1.0.1", + "grunt": "^1.0.4", "grunt-autoprefixer": "^3.0.4", "grunt-cli": "^1.2.0", "grunt-contrib-connect": "^1.0.2", @@ -33,11 +33,12 @@ "grunt-contrib-qunit": "^2.0.0", "grunt-contrib-uglify": "^3.3.0", "grunt-contrib-watch": "^1.0.0", - "grunt-sass": "^2.0.0", "grunt-retire": "^1.0.7", + "grunt-sass": "^2.0.0", "grunt-zip": "~0.17.1", "mustache": "^2.3.0", - "socket.io": "^1.7.3" + "socket.io": "^1.7.3", + "grunt-shell": "^3.0.1" }, "license": "MIT" } diff --git a/tex2svg-single.sh b/tex2svg-single.sh new file mode 100755 index 0000000..91e531c --- /dev/null +++ b/tex2svg-single.sh @@ -0,0 +1,11 @@ +#!/bin/bash +file=$1 +pushd $(dirname $file) +base=$(basename ${file%.tex}) +pdflatex --shell-escape --halt-on-error $base +pdflatex --shell-escape --halt-on-error $base +pdfcrop $base.pdf +pdf2svg $base.pdf $base-orig.svg +pdf2svg $base-crop.pdf $base-crop.svg +rm -f $base.aux $base.log $base.out $base.pdf $base-crop.pdf +popd