update pdflatexi
authorMart Lubbers <mart@martlubbers.net>
Wed, 21 Jun 2017 17:11:54 +0000 (19:11 +0200)
committerMart Lubbers <mart@martlubbers.net>
Wed, 21 Jun 2017 17:11:54 +0000 (19:11 +0200)
shell/.local/bin/update
x/.local/bin/pdflatexi

index a451d41..3563918 100755 (executable)
@@ -9,7 +9,7 @@ cmd() {
                [ `head -c 1 $DV` -ge 9 ] && echo -n '--' || -n '&& apt-get '
                echo -n 'autoremove --purge && apt-get clean && apt-get autoclean'
        else
-               echo -n 'pacman -Syu && pacman -R `pacman -Qdtq`'
+               echo -n 'pacman -Syu && pacman -Qdtq | ifne xargs pacman -R'
        fi
 }
 
index 015002c..a23b435 100755 (executable)
@@ -1,22 +1,50 @@
 #!/usr/bin/expect
+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
 spawn pdflatex {*}$argv
 set latexpid $spawn_id
+
+# Initialize the saved result to compare later
 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
-               }
+set result ""
+
+expect {
+       # Regular sty file is missing
+       -re "^.*File .(.*). not found.*$" {
+               tryInstallPackage $expect_out(1,string)
+       } -re "^.*language definition file (.*) was not foun" {
+       # Bibtex ldf file is missing
+               tryInstallPackage $expect_out(1,string)
+       } -re "^.*Encoding file .(.*). not found." {
+       # Font encoding file is missing
+               tryInstallPackage $expect_out(1,string)
+       } timeout {
+       # Timeout
+               send_user "Compilation timed out???"
+               exit
        }
+}