Sublime Text + LaTeXTools: How To Automatically Delete Generated Files After Compilation?

3

0

I use Sublime Text Editor 3 with LaTeXTools to write in LaTeX.

I compile files by pressing Control+B. If I name my text file as main.tex, the generated files will be:

 - main.aux
 - main.bbl
 - main.blg
 - main.log
 - main.pdf
 - main.synctex.gz

Is there a way to edit the LaTeXTools package so that, after the compilation process is over, the .aux, .bbl, .blg, .log, and .synctex.gz files are deleted?

Aventinus

Posted 2018-01-19T15:40:27.673

Reputation: 908

I'm not sure how you'd do it with your toolchain but keep in mind that this will lengthen the time it takes to compile as the aux files etc. contain intermediate information. With larger documents this will be noticeable. An easy option might be to create a batch file that allows you on demand "easy" cleanup. – Seth – 2018-01-29T11:00:31.613

Which operating system and LaTeX distribution are you using? – Hugh – 2018-01-29T11:08:40.227

Answers

2

Method 1:

Install the Sublime Text LaTeXTools package.

By default the Command Pallet -> LaTeXTools: Delete temporary tiles is mapped to Ctrl-L, backspace by default:

// super+l,backspace to remove temporary files
{ "keys": ["super+l", "backspace"],
  "context":  [{"key": "selector", "operator": "equal", 
                  "operand": "text.tex.latex"}],
  "command": "delete_temp_files"},

The LaTeXTools package is also documented here.

To adjust what LaTeXTools cleans up without worrying about package updates, choose Preferences -> Package Settings -> LaTeXTools -> Settings -- User and adjust the following block of code:

// ------------------------------------------------------------------
// Temporary file settings
// ------------------------------------------------------------------
// Ends of the names of temporary files to be deleted
"temp_files_exts": [
    ".blg",".bbl",".aux",".log",".brf",".nlo",".out",".dvi",".ps",
    ".lof",".toc",".fls",".fdb_latexmk",".pdfsync",".synctex.gz",
    ".ind",".ilg",".idx"
],
// Folders that are not traversed when deleting temp files
"temp_files_ignored_folders": [
    ".git", ".svn", ".hg"
],

To tie both ^b and ^l together: use the Chain of Command Package as described by https://stackoverflow.com/a/27994582, and modify the build keyboard shortcut to include delete_temp_files.

Method 2:

Install latexmk. You will want this anyway, as it runs LaTeX the required number of times, and runs biber/BibTeX as needed until it builds the pdf correctly.

Then within Sublime Text Under Tools->Build System choose New Build System and enter the following:

{
    "shell_cmd": "latexmk -pdf \"$file\" && latexmk -c",
    "selector": "text.tex.latex"
}

If latexmk isn't in your default path, you may need to specify the full path. The above will work on OSX and Linux. The && is a bash script directive that tell the shell to run the second command if the first command was successful. The -c runs the cleanup. Which files are cleaned up can be adjusted through the configuration file for latexmk.

glallen

Posted 2018-01-19T15:40:27.673

Reputation: 1 886

1

I don't know if modifying the LaTeXTools package is the best approach, especially if it's a package that is prone to regular updates. You might find yourself having to re-implement your modifications, or even re-designing them from time to time. However, this doesn't leave you completely without a solution. You may be able to rely on your operating system's scripting abilities to create a procedure that calls LaTeXTools and then cleans up afterward.

Being a Linux user myself, this could be done in a bash script like the following:

#!/bin/bash
    PROJECTNAME=$1
    {COMMAND_LINE_EQUIVALENT_OF_YOUR_CONTROL_B_COMMAND}
    rm $1.aux $1.bbl $1.blg $1.log $1.synctex.gz

Of course, you'd replace the string between the {}s with whatever CLI command structure you'd use to accomplish the same compilation that you do when you hit Ctrl+B within your interface.

If you're using a different operating system, like Windows, then you might want to look into what scripting capabilities Windows offers and try to build off of the same sort of idea as what I presented in the bash script.

gluonman

Posted 2018-01-19T15:40:27.673

Reputation: 56