From 0c2ada30f2180b8d0add9ba5e57869eaa3ffcf15 Mon Sep 17 00:00:00 2001
From: Sébastien Dailly <sebastien@dailly.me>
Date: Fri, 21 Mar 2025 10:13:33 +0100
Subject: Automatically starts the columns for all document with a sidebar

---
 common/99_sidebar.tex | 41 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 38 insertions(+), 3 deletions(-)

(limited to 'common/99_sidebar.tex')

diff --git a/common/99_sidebar.tex b/common/99_sidebar.tex
index ab599a0..5bc96cd 100755
--- a/common/99_sidebar.tex
+++ b/common/99_sidebar.tex
@@ -1,5 +1,39 @@
+\usepackage{paracol}
 \newlength{\notesep}
 
+% All the models uses two columns.
+% At any time in the RST document, you can add elements in the sidebar using
+% the sidebar directive.
+%
+%   .. sidebar:: Informations
+%   
+%     * 17 allée des cerisiers
+%     * 75001 Paris |phoneicon|
+%     * 01 23 45 67 89 |mailicon|
+%     * email@example |noicon|
+%   
+%   You can close the sidebar at any time, but this requires to use latex code in the document
+%   
+%   .. raw:: latex
+%   
+%       \flushpage
+%       \end{paracol}
+%       \newgeometry{left=3cm,right=3cm,bottom=1cm,top=1cm}
+
+
+% Switch in paracol mode from the begining of the document
+% This can be disabled by defining \nocolumns before loading
+% this template.
+% 
+% \def\nocolumns{}
+
+\ifdefined\nocolumns
+\else
+    \AtBeginDocument{%
+      \begin{paracol}{2}
+    }
+\fi
+
 \def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
 \let\endchangemargin=\endlist 
 
@@ -21,8 +55,9 @@
   \ifdefinedcolor{textsidecolor}{\color{black}}{}
 }
 
+% If the column is still active, make it go to the bottom of the page.
+\makeatletter
 \AtEndDocument{%
-  % Make the column go to the bottom
-  \flushpage
-  \end{paracol}
+  \ifthenelse{\equal{\@currenvir}{paracol}}{\flushpage\end{paracol}}{}
 }
+\makeatother
-- 
cgit v1.2.3

