In order to keep clean the folder where my .tex file is, I have successfully adopted the strategy suggested in other posts (see e.g. here or here), setting -output-directory=build and -aux-directory=build and adding ./build in the additional search paths for the log file and the pdf file in the build advanced options.
This works, though all the files (including the pdf) are now in the build subfolder, whereas I would like to have the pdf in the same folder where the .tex file is.
To this aim, I created a simple batch file called copy.bat and put it in the same folder where the .tex file is. Its content is:
for /R "%cd%\build" %%f in (*.pdf) do copy "%%~f" ".\"
What it does is to copy all the pdf files from the build subfolder to the current folder. If run from terminal it works as expected.
Now, I would like to run the .bat file from within the tex file I am working on. I have changed the PdfLatex command option so that now it is:
pdflatex.exe -synctex=1 -interaction=nonstopmode --shell-escape -output-directory=build -aux-directory=build %.tex
I have then included \immediate\write18{"./copy.bat"} in my tex file, but I get an error when I try to compile (the pdf is corrupt).
I really can't understand why. As a side question, would you use a different strategy to copy the pdf in the tex directory?
-output-directorywhen you don't want to redirect the pdf? – Ulrike Fischer Oct 17 '15 at 23:19-output-directory=buildyou'll lose it otherwise. if no you can trypdflatex.exe -interaction=nonstopmode --shell-escape -aux-directory=build %.texand every thing is fine. – touhami Oct 18 '15 at 11:22