Update readme and remove non-used dotfiles
[dotfiles.git] / x / .local / bin / pdflatexi
1 #!/usr/bin/expect
2 proc tryInstallPackage { name } {
3 global latexpid oldresult result spawn_id argv
4
5 # Set result
6 set result $name
7 send_user "\nTrying to install missing package\n"
8 # Encountering this result for the second time...
9 if {$oldresult == $result} {
10 send_user "$result has been tried twice with no results\n"
11 send_user "Is this not an image? Aborting...\n"
12 exit
13 # Install the package with tlmgri
14 } { spawn tlmgri $result
15 interact
16 # Reset spawn id to kill original pdflatex
17 set spawn_id $latexpid
18 close
19 wait
20 # Respawn pdflatex
21 spawn pdflatex {*}$argv
22 set oldresult $result
23 exp_continue
24 }
25 }
26
27 # Start latex and save the pid to kill it later
28 spawn pdflatex {*}$argv
29 set latexpid $spawn_id
30
31 # Initialize the saved result to compare later
32 set oldresult ""
33 set result ""
34
35 expect {
36 # Regular sty file is missing
37 -re "^.*File .(.*). not found.*$" {
38 tryInstallPackage $expect_out(1,string)
39 } -re "^.*language definition file (.*) was not foun" {
40 # Bibtex ldf file is missing
41 tryInstallPackage $expect_out(1,string)
42 } -re "^.*Encoding file .(.*). not found." {
43 # Font encoding file is missing
44 tryInstallPackage $expect_out(1,string)
45 } timeout {
46 # Timeout
47 send_user "Compilation timed out???"
48 exit
49 }
50 }