#!/usr/bin/expect spawn pdflatex {*}$argv set latexpid $spawn_id set oldresult "" expect -re "^.*File .(.*). not found.*$|^.*language definition file (.*) was not foun" { set result $expect_out(1,string) send_user "\nTrying to install missing package\n" if {$oldresult == $result} { send_user "$result has been tried twice with no results\n" send_user "Is this not an image? Aborting...\n" exit } { spawn tlmgri $result interact set spawn_id $latexpid close wait spawn pdflatex {*}$argv set oldresult $result exp_continue } }