From 84b8b0c3913fd13606552013ec9d0d475326d9f4 Mon Sep 17 00:00:00 2001
From: Malin Freeborn <malinfreeborn@tutamail.com>
Date: Tue, 15 Dec 2020 04:29:30 +0100
Subject: [PATCH] add \externalReferent commant for outside refs

---
 autocompile.sh |  1 +
 bind.sty       | 20 +++++++++++++++++++-
 latexmkrc      |  8 ++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 latexmkrc

diff --git a/autocompile.sh b/autocompile.sh
index f79b03d2..cb580ace 100755
--- a/autocompile.sh
+++ b/autocompile.sh
@@ -8,6 +8,7 @@
 [ ! -e main.tex ] && [ -e config/main.tex ] && \
 	cp config/main.tex . && \
 	ln -s config/autocompile.sh . && \
+	ln -s config/latexmkrc . && \
 	ln -s config/.gitignore .
 
 git gc --auto
diff --git a/bind.sty b/bind.sty
index ee56e0fd..b4ce21da 100644
--- a/bind.sty
+++ b/bind.sty
@@ -30,7 +30,7 @@
 \RequirePackage{colortbl}
 \RequirePackage[poster]{tcolorbox}
 \tcbuselibrary{breakable,raster}
-%\tcbset{enhanced, attach boxed title to top center={yshift*=-3mm},drop shadow east,colback=white,arc=6mm,outer arc=1mm}
+%\tcbset{enhanced, attach boxed title to top center={yshift*=-3mm},drop shadow east,callback=white,arc=6mm,outer arc=1mm}
 
 \tcbset{enhanced, drop shadow east,
 colframe=black,colbacktitle=black!5!white,
@@ -47,11 +47,29 @@ interior code={ \path[tcb fill interior] ([xshift=-2mm]interior.west)
 }
 }
 
+\RequirePackage{xr-hyper}
 \RequirePackage[
 pdfstartpage=2,
 bookmarks=true]%
 {hyperref}
 
+%%%%%%%%%% Allow for external referencing
+
+\newcommand*{\externalReferent}[1]{
+	\newtoggle{#1}
+	\IfFileExists{../#1/main.tex}{
+		\makeatletter
+		\@addtofilelist{../#1/main.tex}
+		\@addtofilelist{../#1/main.aux}%
+		\makeatother
+		\externaldocument{../#1/main}%
+		\settoggle{#1}{true}
+	}%
+	{\typeout{No file #1.}
+	\settoggle{#1}{false}
+	}
+}
+
 
 %%%%%%%%%% Section Headers %%%%%%%%%%
 
diff --git a/latexmkrc b/latexmkrc
new file mode 100644
index 00000000..755cb5d1
--- /dev/null
+++ b/latexmkrc
@@ -0,0 +1,8 @@
+add_cus_dep( 'tex', 'aux', 0, 'makeexternaldocument' );
+
+sub makeexternaldocument {
+    if (!($root_filename eq $_[0]))
+    {
+        system( "latexmk -cd -pdf \"$_[0]\"" );
+    }
+}
-- 
GitLab