Add grunt watch task for tex files

This commit is contained in:
Knoch 2019-05-08 11:15:32 +02:00
parent 551e681c03
commit 878a3f006d
3 changed files with 51 additions and 4 deletions

View File

@ -144,13 +144,32 @@ module.exports = function(grunt) {
}, },
options: { options: {
livereload: true 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: { retire: {
js: [ 'js/reveal.js', 'lib/js/*.js', 'plugin/**/*.js' ], js: [ 'js/reveal.js', 'lib/js/*.js', 'plugin/**/*.js' ],
node: [ '.' ] 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-sass' );
grunt.loadNpmTasks( 'grunt-zip' ); grunt.loadNpmTasks( 'grunt-zip' );
// Fachschaft WIAI dependency:
grunt.loadNpmTasks( 'grunt-shell' );
// Default task // Default task
grunt.registerTask( 'default', [ 'css', 'js' ] ); grunt.registerTask( 'default', [ 'css', 'js' ] );
@ -190,4 +212,17 @@ module.exports = function(grunt) {
// Run tests // Run tests
grunt.registerTask( 'test', [ 'jshint', 'qunit' ] ); 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');
});
}; };

View File

@ -24,7 +24,7 @@
}, },
"devDependencies": { "devDependencies": {
"express": "^4.16.2", "express": "^4.16.2",
"grunt": "^1.0.1", "grunt": "^1.0.4",
"grunt-autoprefixer": "^3.0.4", "grunt-autoprefixer": "^3.0.4",
"grunt-cli": "^1.2.0", "grunt-cli": "^1.2.0",
"grunt-contrib-connect": "^1.0.2", "grunt-contrib-connect": "^1.0.2",
@ -33,11 +33,12 @@
"grunt-contrib-qunit": "^2.0.0", "grunt-contrib-qunit": "^2.0.0",
"grunt-contrib-uglify": "^3.3.0", "grunt-contrib-uglify": "^3.3.0",
"grunt-contrib-watch": "^1.0.0", "grunt-contrib-watch": "^1.0.0",
"grunt-sass": "^2.0.0",
"grunt-retire": "^1.0.7", "grunt-retire": "^1.0.7",
"grunt-sass": "^2.0.0",
"grunt-zip": "~0.17.1", "grunt-zip": "~0.17.1",
"mustache": "^2.3.0", "mustache": "^2.3.0",
"socket.io": "^1.7.3" "socket.io": "^1.7.3",
"grunt-shell": "^3.0.1"
}, },
"license": "MIT" "license": "MIT"
} }

11
tex2svg-single.sh Executable file
View File

@ -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