4

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
  • 1,352
  • 4
  • 17
  • 31
  • 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 Jan 29 '18 at 11:00
  • Which operating system and LaTeX distribution are you using? – Hugh Jan 29 '18 at 11:08

3 Answers3

4

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
  • 2,164
  • 12
  • 23
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
  • 56
  • 7
0

Head to Preferences > Package Settings > LaTeXTools > Settings – User in Sublime, and find the section titled Output Directory settings. Here, you need to specify your "aux_directory" and "output_directory" settings. Your options are:

  • "": the default; does not use any auxiliary/output directory
  • path: the path to the auxiliary/output directory; if this is not an absolute path it is interpreted as a path relative to the main tex file
  • "<<temp>>": the auxiliary/output directory will be a temporary directory generated in as secure a manner as possible; note that this temporary directory is only valid until ST is restarted and will be deleted on the next start-up
  • "<<project>>": this creates an auxiliary/output directory in the same folder as the main tex file; the name is the MD5 hash of the absolute path of the main file; unlike <<temp>> this directory will persist
  • "<<cache>>": this creates an auxiliary/output directory in the ST cache directory on ST3 or a suitable directory on ST2; unlike <<temp>> this directory will persist; unlike <<project>>, it will not be in the same directory as the main tex file

This allows you to specify where all the extra files generated when compiling your latex PDF are stored. For more information on these settings, check out the latextools documentation.