For the following, it is assumed that two folders are needed to host all the generated files: one for the output PDF file (suppose the folder name is PDF) and the other for all the auxiliary files generated by pdflatex (I neamed the folder AuxDirectory). Two approaches are considered: TeXstudio and Latexmk.
First, TeXstudio needs to understand where to put the output files. SO, two options will be changed:
--aux-directory for auxiliary files and
--output-directory for PDF output file.
Options > Configure TeXstudio > Commands. In pdfLaTeX field, add
--aux-directory=AuxDirectory --output-directory=PDF before %.tex.
In case of using BibTeX:
In BibTeX field, change it from
bibtex.exe % to
bibtex.exe AuxDirectory/% -include-directory=AuxDirectory. This is very important step to make the bibliography tool able to find aux files.
In case of using Biber:
In Biber field, change it from
biber.exe % to
To make TeXstudio able to locate PDF output file for external pdf readers, in the left tab menu, go to
Build > Additional Search Paths: and write the folder name you wish to store log file into (I chose AuxDirectory) and the folder name that TeXstudio asks the external PDF viewer to go there to open the file.
Now, you are able to make a clean and well organized directory for the LaTeX project.
Latexmk is a powerful automation tool and also smart. More information is given in its documentation. The same previous options (
--output-directory) are used since the same engine/compiler is given.
For example, if you want to compile a file named
main.tex using latexmk you have to run this command (providing that the command current directory is the same as the one hosting
latexmk -quiet -bibtex -aux-directory=AuxDirectory --output-directory=PDF -pdf -pdflatex="pdflatex -synctex=1 -interaction=nonstopmode" main.tex
Latexmk is very smart and able to determine the required number of pdfLaTeX and BibTeX runs to properly generate the PDF output file.
Additionally, if you found it very annoying to open the command window each time you want to compile your document, you can create a bash file that opens the command window and runs the previous command by just double-clicking it.
In order to do so, create a file with extension
.bat in the same working directory of
main.tex and edited it to have
cmd /k latexmk -quiet -bibtex -aux-directory=AuxDirectory --output-directory=PDF -pdf -pdflatex="pdflatex -synctex=1 -interaction=nonstopmode" main.tex.
Any other suggestions/improvements are highly appreciated.