+proc tryInstallPackage { name } {
+ global latexpid oldresult result spawn_id argv
+
+ # Set result
+ set result $name
+ send_user "\nTrying to install missing package\n"
+ # Encountering this result for the second time...
+ if {$oldresult == $result} {
+ send_user "$result has been tried twice with no results\n"
+ send_user "Is this not an image? Aborting...\n"
+ exit
+ # Install the package with tlmgri
+ } { spawn tlmgri $result
+ interact
+ # Reset spawn id to kill original pdflatex
+ set spawn_id $latexpid
+ close
+ wait
+ # Respawn pdflatex
+ spawn pdflatex {*}$argv
+ set oldresult $result
+ exp_continue
+ }
+}
+
+# Start latex and save the pid to kill it later