How to hide extra/auxiliary files generated by pdflatex in Linux

8.2k views Asked by At

I have seen answers to this similar question which suggest using latexmk -c or pdflatex -aux-directory=/some/temp/dir <additional options>. I prefer the latter because you can create a subdirectory without having to remove and generate files repeatidly. Currenlty, this option is "only implemented on the MiKTeX version of (pdf)latex". On the other hand, the former approach does not seem to work properly. I use LaTeX Workshop in Visual Studio Code which by default uses latexmk. To add the -c flag, I created the following receipe:

"latex-workshop.latex.tools": [
        {
            "name": "latexmk -c",
            "command": "latexmk",
            "args": [
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "-pdf",
                "-c",
                "%DOC%"
            ]
        }
      ],

    "latex-workshop.latex.recipes": [
        {
            "name": "latexmk -c",
            "tools": [
              "latexmk -c"
            ]
        }
      ]

If I first create the pdf file from latex source files and then add the -c flag for the next compiles, it removes the additional files properly. However, if you want to compile for the first time (when there is no pdf or auxiliary files available), it does not generate any pdf file and I should consider removing the -c flag. Even if you already have the pdf file and its associated files available, once you remove only the pdf file from the folder, the same problem occurs. Is there an efficient way to hide such auxiliary files (by removing them or preferably puting them in a subfolder) in Linux (or in vscode)?

3

There are 3 answers

1
Juan Leni On BEST ANSWER

I have the following entry in .vscode/settings.json:

"latex-workshop.latex.outDir": "%DIR%/aux",

It works quite well. All temporary files are kept in aux so compilation is fast but does not pollute my .tex files

1
Lucas Aimaretto On

You can set that up in the options for LaTex Workshop whithin VSCode.

enter image description here

After enabling that option, and after a successful compilation, all the auxiliary files are deleted automatically.

0
Amado Rosas On

You need to update your .vscode/settings.json file as follows:

        `{
        "name": "latexmk -c",
        "command": "latexmk",
        "args": [
            "-synctex=1",
            "-interaction=nonstopmode",
            "-file-line-error",
            "-lualatex",
            "-outdir=%OUTDIR%",
            "-auxdir=%OUTDIR%/build",
            "%DOC%"
        ]
    }
  ],`

I've set /build as the directory where the auxiliary files will be generated. You can replace it with the name of the folder you prefer. No need to create the folder beforehand; it will be created automatically during compilation. Additionally, I've kept the -outdir argument because I want the PDF file to be generated in my main project folder. If you prefer to have all generated files (including PDF) stored in a separate directory from your main folder, you can ignore -auxdir and specify it directly in -outdir:

        `{
        "name": "latexmk -c",
        "command": "latexmk",
        "args": [
            "-synctex=1",
            "-interaction=nonstopmode",
            "-file-line-error",
            "-lualatex",
            "-outdir=%OUTDIR%/build",
            "%DOC%"
        ]
    }
  ],`