I have been there and done that . . . there and back again . . . and visited again and again . . .
The solution is to use a custom plugin (not necessarily relying upon a .sublime-build
, but that is possible too) so that you can refer to the *.tex file that is open. I have some solutions you are probably unaware of, one of which is my own, and one where I modify the popular plugin LaTexTools.
latexmk cleans with a big -C (everything) or a little -c (some things that are pre-defined, and additional things that can be user-defined) -- so there is no need to use a separate custom cleaner script.
https://github.com/lawlist/LaTexTools-Unofficial-Modification
https://github.com/lawlist/ST2-plugin-latexmk-save-build-clean
FYI: I recommend putting latex (or something like that) in your subject line of the question -- I almost missed your question . . . and just happened to see the short summary and realized I knew something about this issue.
SAMPLE -- for MultiTaskBuild plugin located here: https://github.com/bizoo/MultiTaskBuild
{
"cmd": {
"latexmk -pvc . . .": {
"cmd": ["latexmk", "-r", "/Users/HOME/.latexmkrc", "$file"]
},
"latexmk -pv . . .": {
"cmd": ["latexmk",
"-e", "\\$pdflatex = 'pdflatex -enable-write18 %O -interaction=nonstopmode -synctex=1 %S'",
"-recorder-", "-pvc-", "-f", "-pdf", "-pv", "$file"]
},
"latexmk -c": {
"cmd": ["latexmk", "-c", "$file"]
},
"latexmk -C": {
"cmd": ["latexmk", "-C", "$file"]
}
},
"path": "$PATH:/usr/texbin:/usr/local/bin",
"file_regex": "^(...*?):([0-9]+): ([0-9]*)([^\\.]+)",
"selector": "text.tex.latex",
"default_task": "latexmk -pv . . .",
"target": "multi_task_exec"
}