Skip to content

Instantly share code, notes, and snippets.

@Mikulas
Created November 12, 2012 20:21
Show Gist options
  • Save Mikulas/4061641 to your computer and use it in GitHub Desktop.
Save Mikulas/4061641 to your computer and use it in GitHub Desktop.
Mac OS X LaTeX build script for Sublime Text 2
{
"cmd": ["php", "/Volumes/Data/Scripts/latex_build.php", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
//"target": "exec_in_window", // https://github.com/vhyza/exec-in-window
"selector": "text.tex.latex"
}
<?php
$file = $argv[1];
$res = file_get_contents($file);
list($line) = explode("\n", $res);
$match = [];
preg_match('~^%build\s+(?P<file>.*?)$~ims', $line, $match);
$info = pathinfo($file);
$target = $info['dirname'] . '/' . $match['file'];
passthru('/usr/texbin/pdflatex ' . escapeshellarg($target));
$pdf = $info['dirname'] . '/' . $info['filename'] . '.pdf';
exec('open ' . escapeshellarg($pdf));
@Mikulas
Copy link
Author

Mikulas commented Nov 12, 2012

Usage:

Set the main/root file in each included tex file such as

%build ProjectRoot.tex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment