# This script sets up the environment to be able to compile the latex source
# files from within the 'src' directory with latexmk.
#
# Context: The project is set up in such a way that running make from the root
# directory compiles all documents. When using vimtex, however, when compiling
# a document it is always assumed that the root directory is that of the
# document currently being edited. Running this script enables the documents in
# 'src' to be edited and compiled with vimtex as well.

SRC_DIRS=$(ls src)

for SRC_DIR in $SRC_DIRS; do
    # Create the latexmkrc file. Note the -cd option which changes the working
    # directory
    echo '$pdflatex="pdflatex -shell-escape -interaction=nonstopmode -synctex=1 %O %S -cd ./../..";' >./src/$SRC_DIR/.latexmkrc
    echo '$out_dir = "build";' >>./src/$SRC_DIR/.latexmkrc
    echo '$pdf_mode = 1;' >>./src/$SRC_DIR/.latexmkrc

    # Changing the working driectory using the -cd option seems to only affect
    # source files.
    #ln -s `pwd`/src ./src
    ln -s $(pwd)/lib ./src/$SRC_DIR/lib
    ln -s $(pwd)/src ./src/$SRC_DIR/src
done
