1

I am trying to build a complex latex document (at least it's complex for me). The directory structure looks like this:

- bat.tex
- packages.tex
- {other tex files}.tex
- content
-- {chapter folders}
--- chapter.tex
-- abstract.tex

Till now I built the document with the following bash script:

#!/bin/sh
start=`date +%s`

echo ----------------------------
echo Generating Documentation
echo ----------------------------

echo Generating PDF \(pass 1\)
lualatex --shell-escape --interaction=nonstopmode bat.tex > /dev/null

echo Generating Bibliography
biber bat > /dev/null

echo Generating Glossaries
makeglossaries bat > /dev/null

echo Finishing PDF
lualatex --shell-escape --interaction=nonstopmode bat.tex > /dev/null

end=`date +%s`

runtime=$((end-start))

echo $runtime s

Which works great. But I would like to build it with latexmk.

So I wrote this .latexmkrc

$latex = 'latex  %O --shell-escape %S'; 
$pdflatex = 'lualatex  %O --shell-escape %S; 
$pdf_mode = 4; $bib_program = 'biber';

$out_dir = 'build';

The problem now is, that it does not find the .aux files from the content subdirectory. I found this thread which does not have any good solution. Since it is rather old I wanted to ask if there is a fix for my problem or another good solution.

Also will my .latexmkrc file work with biber?

Thank you for your help.

Pascal
  • 779
  • See https://tex.stackexchange.com/a/391998 – Pablo González L Nov 24 '19 at 22:50
  • @PabloGonzálezL my main.tex is not in a subdirectory, but the files I include in it. – Pascal Nov 24 '19 at 23:33
  • you can place the output of the command tree? – Pablo González L Nov 24 '19 at 23:50
  • A couple of side issues: 1. You don't need to set $bib_program in .latemkrc. It will have no effect, since latexmk automatically determines whether to run bibtex or biber. 2. Your line $pdflatex = 'lualatex %O --shell-escape %S; should be $lualatex = 'lualatex %O --shell-escape %S;. – John Collins Nov 26 '19 at 22:38
  • Are are using \include in your document? If not there should be no problem with .aux files in the content subdirectory. You say that "it does not find the .aux files from the content subdirectory". A problem you could encounter is that lualatex or pdflatex may say that it cannot write to the .aux file(s), which is not the same. You can solve the problem by creating ahead of time a content subdirectory in the build directory. (latexmk does this, but only after the first compilation, which is too late to prevent you seeing an error. Later compilations should go fine.) – John Collins Nov 26 '19 at 22:54
  • @JohnCollins If I exchange the line$pdflatex as you test, I get the error The fontspec package requires either XeTeX or LuaTeX. In my main tex file I got the first lines %!TEX TS-program = lualatex – Pascal Dec 03 '19 at 06:53
  • It looks like you are correct with your second comment. It says, that it can't write into the file. Is there something to create the needed folder structure ahead of time? I only found some hackish solutions. – Pascal Dec 03 '19 at 06:56

1 Answers1

0

So with the help of @JohnCollins I was able to get it working:

.latexmk

sub createFolderStructure{
   system("bash ./createFolderStructure.sh");
}

createFolderStructure();

$latex = 'latex  %O --shell-escape %S';
$pdflatex = 'lualatex  %O --shell-escape %S --output-directory=build --aux-directory=build';
$pdf_mode = 4;

$out_dir = 'build';

createFolderStructure.sh

#!/bin/sh

find ./content -type d > folder_list.txt

mkdir -p build
cd build
cat ../folder_list.txt | xargs mkdir -p
rm ../folder_list.txt

With this there is no initial error with creating the folder structure under the build folder.

Pascal
  • 779