11

I have started to configure VSC as my default latex text editor, using the "Latex Workshop" extension.

My question is: How can I make the auxiliary files generated when compiling the project be saved in a separate folder? files (.aux, .bbl, .blg, .fls ...)

I read that this can be done by adding --aux-directory=FOLDER to the compile-time statement but I don't know how I can do that in VSC.

Any idea how to do it?

Thank you very much.

  • 1
    I would not do it unless you know very well how all the tools (bibtex, biber, makeindex, etc) have to be configured to find their input files in the auxiliary folder. It is much less trouble to let the files in the folder where the tex programs are expecting them by default. – Ulrike Fischer Jan 25 '20 at 16:46
  • Yes, but I read that by specifying the directory for the auxiliary files with that command, the compiler knows where they are when it needs them – Josemanuu01 Jan 26 '20 at 11:32
  • Pdflatex would know but not the other tools or scripts. – Ulrike Fischer Jan 26 '20 at 11:35
  • Is there a specific problem that motivates this need for another folder ? – BambOo Mar 30 '20 at 10:20

4 Answers4

6

If you are using pdflatex, you can add the flag --aux-directory=.aux to the tool arguments in the setting.json file, such as:

{
    "name": "pdflatex",
    "command": "pdflatex",
    "args": [
        "-synctex=1",
        "-interaction=nonstopmode",
        "-file-line-error",
        "--aux-directory=.aux",
        "%DOC%"
    ],
    "env": {}
},

The synctex file will still be in the source directory. You need it there next to the pdf.

Then it is convenient to just add the .aux folder to .gitignore if you are using it.

Ejowan
  • 3
  • 2
    Where do you access settings.json? – Paul Wintz Nov 01 '22 at 23:31
  • 1
    @PaulWintz Bit late to it, but for anyone looking for this in the future, it's Cmd/Ctrl + Shift + P (Command Palette) > Preferences: Open Workspace Settings (JSON) – shreyasm-dev Jan 10 '23 at 23:22
  • @PaulWintz create a .vscode folder in your project directory. then create a settings.json there. Visual Studio Code will automatically load every time you invoke/open it from within that folder. – Foad Jan 24 '24 at 10:15
  • this is not the correct answer. pdflatex has the option -output-directory=<path> – Foad Jan 24 '24 at 10:17
5

A very simple solution is to save everything in a temporary folder. This is easy to set up: Search for "latex outdir" in settings, and set it to %TMPDIR% as in the image below.

This will also write the pdf into a temporary folder, which I personally like. If you want to check the pdf, just use Ctrl+Alt+V. You may then optionally save the pdf from the viewer.

enter image description here

  • what's Ctrl+Alt+V on mac? where can I see this defined? – BlkPengu Oct 24 '21 at 21:33
  • In MacOS it should be Command+Alt+V. You can find it by opening the Command+Shift+P prompt and typing "preview pdf". The command for previewing the pdf should be listed in the options with it's respective shortcut. – Carlos Pinzón Oct 26 '21 at 16:39
  • I have to say the short-cut might be conflict with other software (like mine, it was occupied by Evernote), the unambiguous ways is type "LaTex Workshop View LaTex PDF file" after open the Ctrl + Alt + P or Command + Shift + P, or just resolve the conflict, :) – Yan An Feb 17 '22 at 10:02
3

Step One: On vscode, open the Preferences (UI)

enter image description here

Step Two: search for latex OutDir

enter image description here

Step Three: in the field Latex-workshop Latex: Out Dir, update the input to %DIR%/<insert-path> where <insert-path> is the path where you want the output to be placed.

enter image description here

Note: This solution is relevant for vsCode and the extension 'Latex Workshop'.

2

I have specifically created a python module for saving the auxiliary files that are generated by LaTeX and BibTeX engines into a desired folder. On my GitHub site are more informations: https://github.com/amrane99/LaTeXCompiler. The compilation of the file will then be executed using a single command in the Terminal. Once the module has been installed (using pip) you can simply compile the .tex file using lualatex and no BibTeX engine eg. as follows -- the generated files will be stored in the .aux_files folder --:

LaTeXCompiler -file <full_path_to_file>.tex 
              -tex_engine lualatex -no_bib_engine -aux_folder .aux_files