Created
August 17, 2012 12:14
-
-
Save gglanzani/3378381 to your computer and use it in GitHub Desktop.
Applescript for MacVim to compile a .tex file with latexmk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on findAndReplace(tofind, toreplace, TheString) | |
set ditd to text item delimiters | |
set res to missing value | |
set text item delimiters to tofind | |
repeat with tis in text items of TheString | |
if res is missing value then | |
set res to tis | |
else | |
set res to res & toreplace & tis | |
end if | |
end repeat | |
set text item delimiters to ditd | |
return res | |
end findAndReplace | |
tell application "System Events" | |
tell process "MacVim" | |
set theFile to value of attribute "AXDocument" of window 1 | |
end tell | |
end tell | |
set fileName to findAndReplace("file://localhost", "", theFile) as string | |
set andFish to "; and " | |
set andBash to " && " | |
-- set the following for Fish or Bas | |
set aAnd to andFish | |
try | |
do shell script "echo " & fileName & " | grep tex" | |
on error | |
display dialog "This is not a tex file" | |
end try | |
set latexMK to "latexmk -pdf -bibtex -file-line-error" | |
-- the exportPATH is only needed when not running in the terminal | |
-- set exportPATH to "export PATH='/usr/local/texlive/2012/bin/universal-darwin/:/usr/bin/:/bin:/usr/sbin:/usr/sbin' " & aAnd | |
set getPath to "echo " & fileName & " | sed 's/[^/]*\\.tex//'" | |
set myPath to do shell script getPath | |
set isLatexMain to "ls " & myPath & " | grep latexmain" | |
try | |
set latexMain to do shell script isLatexMain | |
on error | |
-- set toCompile to exportPATH & "cd " & myPath & aAnd & latexMK & " " & fileName | |
set toCompile to "cd " & myPath & aAnd & latexMK & " " & fileName | |
do shell script toCompile | |
end try | |
set getLatexMain to "ls " & myPath & " | grep latexmain | sed 's/\\.latexmain//'" | |
set latexMainName to do shell script getLatexMain | |
-- set toCompile to exportPATH & "cd " & myPath & aAnd & latexMK & " " & latexMainName | |
set toCompile to "cd " & myPath & aAnd & latexMK & " " & latexMainName & aAnd & "exit" | |
-- do shell script toCompile | |
tell application "Terminal" | |
activate | |
do script toCompile | |
end tell | |
tell application "MacVim" | |
activate | |
end tell | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment