In a previous post I shared a way to export VUE diagrams to PDF in bulk on the command-line. In this post I’ll share a way to automate this even further by delegating the dynamic recreation of PDF files to LaTeX-Mk (latexmk), an excellent make
-like build tool for generating documents from arbitrarily complex LaTeX projects.
latexmk can be extended using Perl in a file called latexmkrc
in the project’s base directory (or one of the locations mentioned in the latexmk man page). This is accomplished by adding a custom file dependency that states that for every “*.vue* file that is newer than the corresponding “*.pdf” file (or for which noch corresponding “*.pdf” file exists) the PDF should be re-created.
Here is the code to put into latexmkrc
:
add_cus_dep( 'vue', 'pdf', 0, 'makevue' );
sub makevue {
system( "timeout 20 java -cp \$(locate VUE.jar|head -1) edu.tufts.vue.component.Export \"$_[0].vue\" \"$_[0].pdf\" pdf" );
system( "pdfcrop \"$_[0].pdf\" \"$_[0].pdf\"" );
}
Because the edu.tufts.vue.component.Export
seems to hang indefinitely for large diagrams, the process is killed after 20 seconds if it hasn’t finished before by the highly recommended timeout tool. The call to pdfcrop removes all surrounding whitespace around the actual diagram which makes the PDF files easier to include and position in LaTeX.
Now, whenever I have changed a diagram, I just have to save it and rebuild the LaTeX document, e.g. to a PDF:
$ latexmk -pdf thesis.tex
This should produce output similar to the following (for an updated VUE map diagrams/myDiagram.vue
):
Latexmk: This is Latexmk, John Collins, 11 Nov. 2012, version: 4.35.
**** Report bugs etc to John Collins . ****
Latexmk: applying rule 'cusdep vue pdf diagrams/myDiagram'...
Rule 'cusdep vue pdf diagrams/myDiagram': File changes, etc:
Changed files, or newly in use since previous run(s):
'diagrams/myDiagram.vue'
------------
Run number 1 of rule 'cusdep vue pdf diagrams/myDiagram'
------------
For rule 'cusdep vue pdf diagrams/myDiagram', running '&do_cusdep( makevue )' ...
VUE 2013-04-04 14:59:37,106 INFO [main] Mapping: Loading mapping descriptors from jar:file:/usr/share/java/vue/VUE.jar!/tufts/vue/resources/lw_mapping_1_1.xml
VUE 2013-04-04 14:59:37,107 INFO [main] ActionUtil: unmarshalling: file:/tmp/testproj/diagrams/myDiagram.vue; charset=UTF-8
VUE 2013-04-04 14:59:37,823 INFO [main] ActionUtil: unmarshalled: LWMap[v5 myDiagram.vue n=97]
VUE 2013-04-04 14:59:38,517 INFO [main] Images: created thread pool: tufts.vue.Images$PriorityThreadPool@1a46725d[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]; maxSize=3
PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
==> 1 page written on `diagrams/myDiagram.pdf'.
Latexmk: applying rule 'pdflatex'...
Rule 'pdflatex': File changes, etc:
Changed files, or newly in use since previous run(s):
'diagrams/myDiagram.pdf'
Yay, another optimization as the result of procrastination!