diff --git a/Makefile b/Makefile
index 6a4988d5e07a57c3926672b150baa4d72a1e545e..ea0b74580327cf6d1d1cdc908dfd755e532bd2da 100644
--- a/Makefile
+++ b/Makefile
@@ -9,15 +9,15 @@ pretex: rust_tex notebook_py_libs
 
 # Sage artifacts which can only be generated after the first run of (pdf/lua)latex.
 # `make main.sagetex.sout` is invoked by `latexmk -use-make` when needed
-SAGETEXARTIFACT = main.sagetex.sout
+SAGETEXARTIFACT = aux_files/main.sagetex.sout
 # Location for all the python libraries generated from the jupyter notebooks:
 GENERATED_PYLIBS_DIR=generated_py_libs
 
 sage_artifacts: ${SAGETEXARTIFACT}
 
 SAGETEXSCRIPT = main.sagetex.sage # generated by latex compile
-${SAGETEXARTIFACT}: ${SAGETEXSCRIPT} notebook_py_libs
-	PYTHONPATH=./${GENERATED_PYLIBS_DIR} sage ${SAGETEXSCRIPT}
+${SAGETEXARTIFACT}: aux_files/${SAGETEXSCRIPT} notebook_py_libs
+	cd aux_files && PYTHONPATH=../${GENERATED_PYLIBS_DIR} sage ${SAGETEXSCRIPT}
 
 # PYTHON LIBS FROM NOTEBOOKS
 
diff --git a/latexmkrc b/latexmkrc
index 9ea77ca576e8030f5e48ef916b57d3e150cc704e..0a46fa3127128d4aef433c1bb54063997369d2c9 100644
--- a/latexmkrc
+++ b/latexmkrc
@@ -2,3 +2,6 @@
 $pdf_mode = 1;
 $pdflatex = 'lualatex -shell-escape -synctex=1 -interaction=nonstopmode';
 @generated_exts = (@generated_exts, 'synctex.gz');
+$use_make_for_missing_files = 1;
+$aux_dir = 'aux_files';
+$out_dir = 'latex_output';