Skip to content
Snippets Groups Projects
layout.sty 24.1 KiB
Newer Older
  • Learn to ignore specific revisions
  • \ProvidesPackage{config/layout}
    
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \RequirePackage[table]{xcolor}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \RequirePackage[acronym]{glossaries}
    \setacronymstyle{short-long-desc}
    \RequirePackage{glossary-mcols}
    \RequirePackage{glossaries-extra}
    \RequirePackage{gfsartemisia-euler} % fancy fonts
    \RequirePackage[T1]{fontenc} % 
    \RequirePackage{stmaryrd} % For boxy Maths symbols
    \RequirePackage{wasysym} % for circly Maths symbols
    \RequirePackage{dingbat} % for curly section symbols
    \RequirePackage{appendix}
    \RequirePackage{geometry} % changes page borders
    
      \geometry{margin=50pt}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \RequirePackage[
      scale=1,
      angle=0,
      opacity=1,
      contents={}
    ]{background}% for fancy borders
    \RequirePackage{svg}
    \RequirePackage{alltt}
    
      \svgsetup{width=\textwidth}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \RequirePackage{tabularx}
    \RequirePackage{wrapfig}
    \RequirePackage{float}
    \RequirePackage{epigraph} % part quotes
    \RequirePackage{microtype} % more precise word-placement
    \RequirePackage{makeidx}
    \RequirePackage[english]{babel}
    \RequirePackage{multicol}
    
      \raggedcolumns
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \RequirePackage{graphicx}
    \RequirePackage{etoolbox}
    \RequirePackage{titlesec,titletoc}
    \RequirePackage{needspace}
    \RequirePackage{tikz}
    
      \usetikzlibrary{calc,mindmap,trees}% calc for fancy borders
      \usetikzlibrary{intersections}% for very fancy borders with intersecting lines
      \usetikzlibrary{shapes.misc}% for very fancy \section
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \RequirePackage{pifont}
    \RequirePackage{colortbl}
    \RequirePackage[poster]{tcolorbox}
    \tcbuselibrary{breakable,raster}
    \tcbuselibrary{skins} % used for wiggly-border boxes
    
    %%%%% Add fancy page chapter sides %%%%%
    \pagestyle{plain}% needed for fancy borders
    \newcounter{chapshift}
    \addtocounter{chapshift}{-1}
    
    \newcounter{pageDarkness}
    \setcounter{pageDarkness}{20}
    
    \newcommand\pageSideColor{%
    
      black!\arabic{pageDarkness}%
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newtoggle{sideTab}
    \settoggle{sideTab}{true}
    
    \newcommand\ChapFrame{%
    
      \AddEverypageHook{%
        \iftoggle{sideTab}%
        {
        \ifodd\value{page}
          \backgroundsetup{contents={%
            \begin{tikzpicture}[overlay,remember picture]
              \node[
                fill=\pageSideColor,
                inner sep=5pt,
                rectangle,
                text width=1.2cm,
                text height=4.33cm,
                align=center,
                anchor=north east
              ]
               at ($ (current page.north east) + (-0cm,-2*\thechapshift cm) $)
               {\rotatebox{90}{\hspace*{.3cm}\parbox[c][1.5cm][t]{3.4cm}{%
               \raggedright\textcolor{white}{\scshape\rightmark}}}};
            \end{tikzpicture}%
          }%
        }
        \else
          \backgroundsetup{contents={%
            \begin{tikzpicture}[overlay,remember picture]
            \node[
              fill=\pageSideColor,
              inner sep=5pt,
              rectangle,
              text width=1.2cm,
              text height=4.33cm,
              align=center,
              anchor=north west
            ]
            at ($ (current page.north west) + (-0cm,-2*\thechapshift cm) $)
            {\rotatebox{90}{\hspace*{.3cm}\parbox[c][1.5cm][t]{3.4cm}{%
              \raggedright\textcolor{white}{\scshape\leftmark}}}};
            \end{tikzpicture}%
          }%
        }
        \fi
        }
        {}%
      \BgMaterial
      }%
      \stepcounter{chapshift}%
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    % redefinition of \chaptermark to contain only the title
    \renewcommand\chaptermark[1]{\markboth{\thechapter.~#1}{}}
    
    
    \RequirePackage{xr-hyper}
    \RequirePackage[
    pdfstartpage=1,
    hidelinks=true,
    bookmarks=true]%
    {hyperref}
    
    %%%%%%%%%% Allow for external referencing
    
    \newcommand*{\externalReferent}[1]{
    
      \newtoggle{#1}
      \IfFileExists{../#1/main.aux}{
        \makeatletter
        \@addtofilelist{../#1/main.tex}
        \@addtofilelist{../#1/main.aux}%
        \makeatother
        \externaldocument{../#1/main}%
        \settoggle{#1}{true}
      }%
      {\typeout{No file #1.}
      \settoggle{#1}{false}
      }
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    
    %%%%%%%%%% Section Headers %%%%%%%%%%
    
    %%% Allow quotes under part headers
    \makeatletter
    \let\old@endpart\@endpart
    \renewcommand\@endpart[1][]{%
    \begin{quote}#1\end{quote}%
    \old@endpart}
    \makeatother
    
    %%%%%%%%%% Give higher penalty to ~
    % The ~ character usually functions as a space with a high penalty for line breaks.
    % This stops the line breaks altogether, so we can write 'Athletics 3', without a line-break between the Skill and the number.
    
    \DeclareRobustCommand{\nobreakspace}{%
       \leavevmode\nobreak\ }
    \catcode `\~=13
    \def~{\nobreakspace{}}
    
    %%%%% Make table of contents two column
    
    \makeatletter
    \renewcommand\tableofcontents{%
    \begin{multicols}{2}
    
        \@starttoc{toc}%
    \end{multicols}
    }
    % and make repeating function
    \newcommand{\Repeat}[1]{%
    
      \expandafter\@Repeat\expandafter{\the\numexpr #1\relax}%
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \def\@Repeat#1{%
        \ifnum#1>0
            \expandafter\@@Repeat\expandafter{\the\numexpr #1-1\expandafter\relax\expandafter}%
        \else
            \expandafter\@gobble
        \fi
    }
    \def\@@Repeat#1#2{%
        \@Repeat{#1}{#2}#2%
    }
    \makeatother
    
    
    \newcommand{\chapnumfont}{
    
      \fontsize{50}{0}
      \selectfont
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    % change bullet points
    
    \renewcommand{\labelitemi}{\ding{250}}
    \renewcommand{\labelitemii}{\ding{254}}
    
    %%%%%%%%%% Encounter Numbers
    
    \newcounter{encnum}
    \setcounter{encnum}{1}
    \newcommand{\encsymbol}{\ding{168}}
    \newcommand{\encnum}{\ifnumcomp{\value{encnum}}{=}{1}{$A$}{\arabic{encnum}}\encsymbol\addtocounter{encnum}{1}}
    \newcommand{\sqarea}{town}
    
    \newcommand{\headingtype}{CHAPTER}
    
    \newcommand{\pic}[1]{
    
      \needspace{4cm}
      \noindent%
      \IfFileExists{images/#1.svg}{%
        \noindent\includesvg[width=\linewidth]{images/#1}
      }{%
        \includegraphics[width=\linewidth]{images/#1.jpg}
      }
    
    Malin Freeborn's avatar
    Malin Freeborn committed
      \label{#1}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcommand{\sidepic}[3][5]{
    
      \needspace{4cm}
      \begin{wrapfigure}{R}{.#1\linewidth}
      \noindent%
      \IfFileExists{images/#2.svg}{%
        \includesvg[width=\linewidth]{images/#2}
      }{
        \includegraphics[width=\linewidth]{images/#2.jpg}
      }
      #3
      \end{wrapfigure}
    
      \label{#1}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcommand{\toppic}[2]{
    
      \begin{figure*}[t!]
        \IfFileExists{images/#1.svg}{
          \includesvg[width=\textwidth]{images/#1}
        }{
          \includegraphics[width=\textwidth]{images/#1.jpg}
        }
        #2
    
      \label{#1}
    
      \end{figure*}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcommand{\toppicBorder}[2]{
    
      \begin{figure*}[t!]
        \begin{tcolorbox}[before upper={\parindent0pt},colframe=black,colback=gray]
        \IfFileExists{images/#1.svg}{
          \includesvg[width=\textwidth]{images/#1}
        }{
          \includegraphics[width=\textwidth]{images/#1.jpg}
        }
        #2
        \end{tcolorbox}
    
      \label{#1}
    
      \end{figure*}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcommand{\bottompic}[2]{
    
      \begin{figure*}[b!]
        \IfFileExists{images/#1.svg}{
          \includesvg[width=\textwidth]{images/#1}
        }{
          \includegraphics[width=\textwidth]{images/#1.jpg}
        }
        #2
    
      \label{#1}
    
      \end{figure*}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcommand{\bottompicBorder}[2]{
    
      \begin{figure*}[b!]
        \begin{tcolorbox}[before upper={\parindent0pt},colframe=black,colback=gray]
        \IfFileExists{images/#1.svg}{
          \includesvg[width=\textwidth]{images/#1}
        }{
          \includegraphics[width=\textwidth]{images/#1.jpg}
        }
        #2
    
        \label{#1}
    
        \end{tcolorbox}
      \end{figure*}
    
    % sidebling
    % This command automatically adds little decorations to boxes.
    
    \newcounter{blingNo}
    \setcounter{blingNo}{0}
    
    \newcommand\sidebling{
        \ifnum\value{dr}>2
        \addtocounter{dr}{-2}
          \includesvg[width=\thedr ex]{config/images/l1}
          \hspace{-30pt}
        \fi
    
        \ifnum\value{mp}>1
          \addtocounter{mp}{7}
          \includesvg[angle=-20,width=\themp pt]{config/config/images/b1}
          \hspace{-20pt}
        \fi
    
        \ifnum\value{attb}>8
          \addtocounter{attb}{-7}
          \includesvg[angle=55,width=\theattb ex]{config/images/s1}
          \hspace{-30pt}
        \fi
    }
    
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    % Define the 'ornamentedbox' environment
    
    % Wiggly Borders
    \makeatletter
    \tikzset{
      use path for main/.code={%
        \tikz@addmode{%
          \expandafter\pgfsyssoftpath@setcurrentpath\csname tikz@intersect@path@name@#1\endcsname
        }%
      },
      use path for actions/.code={%
        \expandafter\def\expandafter\tikz@preactions\expandafter{\tikz@preactions\expandafter\let\expandafter\tikz@actions@path\csname tikz@intersect@path@name@#1\endcsname}%
      },
      use path/.style={%
        use path for main=#1,
        use path for actions=#1,
      }
    }
    \makeatother
    
    \colorlet{ornamentedFrameInner}{white}
    \colorlet{ornamentedFrameOuter}{gray}
    
    \tikzset{ornamented frame inner/.style={color=ornamentedFrameInner,
                                            line width=2pt},
             ornamented frame outer/.style={color=ornamentedFrameOuter,
                                            line width=3pt}}
    
    \tcbsubskin{ornamented}{empty}{
      skin first=ornamented,  skin last=ornamented,
      title engine=standard,
      colbacktitle=white,
      frame code={
        % Account for the line widths in order not to draw beyond the bounding
        % box---except for a few very small details for which this is intentional.
        \coordinate (north west) at ([shift={(1.5pt,-1.5pt)}]frame.north west);
        \coordinate (north east) at ([shift={(-1.5pt,-1.5pt)}]frame.north east);
        \coordinate (south east) at ([shift={(-1.5pt,1.5pt)}]frame.south east);
        \coordinate (south west) at ([shift={(1.5pt,1.5pt)}]frame.south west);
        %
        \foreach \xoffset/\point in {34pt/north west, -34pt/north east,
                                      34pt/south west, -34pt/south east} {
          \fill[color=ornamentedFrameOuter]
            ([xshift=\xoffset]\point) circle[radius=2.5pt];
        }
        %
        \path[name path=ornament 1]
                                     ([yshift=-4pt]north west)
          [rounded corners=0.5pt] -- ++(23pt,0)
          [rounded corners=2pt]   -- ++(3pt,-4pt)
                                  -- ([shift={(-26pt,-8pt)}]north east)
          [rounded corners=0.5pt] -- ++(3pt,4pt)
          [rounded corners=4pt]   -- ([yshift=-4pt]north east)
                                  -- ([yshift=4pt]south east)
          [rounded corners=0.5pt] -- ++(-23pt,0)
          [rounded corners=2pt]   -- ++(-3pt,4pt)
                                  -- ([shift={(26pt,8pt)}]south west)
          [rounded corners=0.5pt] -- ++(-3pt,-4pt)
          [rounded corners=4pt]   -- ([yshift=4pt]south west)
                                  -- cycle;
        %
        \path[rounded corners=0.5pt, name path=ornament 2]
                                     ([yshift=-20pt]north west)
                                  -- ++(-4pt,3pt)
                                  -- ++(0,4pt)
                   to[out=0, in=-90] ([shift={(8pt,0pt)}]north west)
                                  -- ([shift={(34pt,0pt)}]north west)
                                  -- ([shift={(-8pt,0pt)}]north east)
                 to[out=-90, in=180] ([shift={(4pt,-13pt)}]north east)
                                  -- ++(0,-4pt)
                                  -- ++(-4pt,-3pt)
                                  -- ([yshift=20pt]south east)
                                  -- ++(4pt,-3pt)
                                  -- ++(0,-4pt)
                  to[out=180, in=90] ([shift={(-8pt,0pt)}]south east)
                                  -- ([shift={(8pt,0pt)}]south west)
                    to[out=90, in=0] ([shift={(-4pt,13pt)}]south west)
                                  -- ++(0,4pt)
                                  -- ++(4pt,3pt)
                                  -- cycle;
        %
        \draw[ornamented frame outer, use path=ornament 1];
        \draw[ornamented frame outer, use path=ornament 2];
        \draw[ornamented frame inner, use path=ornament 1];
        \draw[ornamented frame inner, use path=ornament 2];
        %
    
        \node at ([xshift=-20pt,yshift=\thedr-5pt] north east)
          {\iftoggle{bling}{\sidebling}{}};
    
    Malin Freeborn's avatar
    Malin Freeborn committed
      }
    }
    
    % These parameters---especially those related to geometry---are better located
    % here in a style than in the subskin definition (see the Subskins section of
    % the tcolorbox manual).
    \tcbset{ornamented/.style={skin=ornamented, toptitle=14.5pt, top=15pt, bottom=9.5pt,
                               coltitle=black}
    }
    
    % Convenient style to use with a tcolorbox preceded by text (or anything),
    % when one wants to prevent any page break before the tcolorbox.
    \tcbset{skip and no break/.style={
      before={\par\nopagebreak\vspace{2ex}\noindent}}
    }
    
    % Style suitable for an “on line” (in the middle of a paragraph)
    % 'ornamentedbox'.
    \tcbset{my on line/.style={
      capture=hbox, tcbox raise base, top=14pt, bottom=14pt,
      before={\kern 5pt}, after={\kern 5pt}}
    }
    
    %%%%% TColorBox Basic Setup %%%%%
    
    \tcbset{enhanced,
    ornamented,
    
    left=3pt,
    right=3pt,
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    code={\rowcolors{2}{}{gray!10}},
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    before upper={\parindent15pt},
    fonttitle=\bfseries,coltitle=black,attach boxed title to top center=
    {yshift=-0.25mm-\tcboxedtitleheight/2,yshifttext=-2mm-\tcboxedtitleheight/2},
    boxed title style={boxrule=-0.5mm,
    frame code={ \path[tcb fill frame] ([xshift=-4mm]frame.west)
    -- (frame.north west) -- (frame.north east) -- ([xshift=4mm]frame.east)
    -- (frame.south east) -- (frame.south west) -- cycle; },
    interior code={ \path[tcb fill interior] ([xshift=-2mm]interior.west)
    -- (interior.north west) -- (interior.north east)
    -- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west)
    -- cycle;}
    }
    }
    
    
    
    \newtcolorbox{boxtext}[1][]{
      ornamented,
      top=2em,
      bottom=2em,
      colback=white,
      fonttitle=\scshape, #1
      }
    
    \newcommand{\sidebox}[2][23]{
    
      \iftoggle{verbose}{
    
    Malin Freeborn's avatar
    Malin Freeborn committed
        \needspace{4em}
    
        \begin{wrapfigure}{R}{.#1\textwidth} 
        #2
        \end{wrapfigure}%
      }{
        #2
        
      }%
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    % Chapter Heading Color
    \colorlet{chapnumcol}{black!100}
    
    %%%%% Section Formatting %%%%%
    
    \newcommand{\frontpage}[3]{
    
      \iftoggle{verbose}{
      \begin{titlepage}
        \centering
        \vspace{2cm}
        {\scshape\Huge\bfseries #1\par}
        \vspace{2cm}
        \includegraphics[width=0.6\textwidth]{#3}\par\vspace{1cm}
        {\Large #2\par}
        \vspace{1.5cm}
        {\large Last edited \today\par}
      
      \end{titlepage}
      \cleardoublepage
      }{}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \titleformat{\chapter}[display]
    {\bfseries}
    {%
    
      \ChapFrame
      \ifnum\value{pageDarkness}<80
        \addtocounter{pageDarkness}{7}
      \else
        \colorlet{chapnumcol}{black!40}
      \fi
      \hspace*{-1.5em}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \begin{tikzpicture}
      \node[minimum width=\linewidth+3em, text=white, fill=\pageSideColor, inner sep=1, outer sep=0, anchor=south] (rectinit) {\Huge \headingtype};
     \node[minimum width=.75\textwidth, text=white, inner sep=3, outer sep=0, anchor=south west, text width=.75\textwidth, align=right] at (rectinit.south west) (chapname) {};
      \node[minimum width=.25\textwidth, inner sep=-5, outer sep=0, anchor=south west, text width=.25\textwidth, align=left] at (chapname.south east) {\chapnumfont\textcolor{chapnumcol}{\Roman{chapter}}};
    \end{tikzpicture}}
    {0pt}
    {\Huge}
    
    
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcommand\titlebar{%
    \tikz[baseline,trim left=1em,trim right=3cm] {
        \fill [\pageSideColor] (2.5cm,-1ex) rectangle (\linewidth+1.5em,2.5ex);
        \node [
    
            fill=white,
    
      text= \pageSideColor,
    
    Malin Freeborn's avatar
    Malin Freeborn committed
            anchor= base east,
            rounded rectangle,
    
            minimum height=3.5ex] at (2.9cm,0) {
    
    Malin Freeborn's avatar
    Malin Freeborn committed
            \textbf{\arabic{section}}
        };
    }%
    }
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \titleformat{\section}{\large\needspace{12em}}{\titlebar}{0.1cm}{\textcolor{white}}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \renewcommand*{\thesection}{\arabic{section}}
    
    
    \titleformat{\subsection}
    
    {\needspace{7em}\normalfont\large\bfseries}{\thesubsection}{1em}{}[\titlerule\vspace{1ex}]
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    %
    \titleformat{\subsubsection}
    {\needspace{4em}\normalfont\normalsize\bfseries}{\thesubsubsection}{1em}{}
    
    %%%%% Character Sheet Tracker
    
    
        \newcounter{track}
        \setcounter{track}{18}
        \newcommand{\tracker}{\center\noindent\arabic{track}\addtocounter{track}{-1}\vspace{.54cm}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    
    %%%%% NPC Names
    
    \newcommand{\name}{}
    \newcommand{\personality}{}
    \newcommand{\mannerism}{}
    \newcommand{\archetype}{}
    \newcommand{\npcsymbol}{}
    \newcommand{\npc}[2]{\settoggle{personality}{false}\renewcommand{\name}{#1 #2}\renewcommand{\npcsymbol}{#1}}
    \newcommand{\NPC}[5]{\renewcommand{\name}{#1 #2}
    \renewcommand{\npcsymbol}{#1}
    \settoggle{personality}{true}
    \renewcommand{\personality}{#3}
    \renewcommand{\mannerism}{#4}
    \renewcommand{\archetype}{#5}
    }
    \newcommand{\T}{\opposition\settoggle{team}{true}} % groups
    \newcommand{\M}{\mars} % male
    \newcommand{\F}{\venus} % female
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcommand{\E}{\mercury} % sentient
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcommand{\A}{\taurus} % creature
    \newcommand{\N}{\leftmoon} % nura
    \newcommand{\D}{\fullmoon} % undead
    
    %%%%%%%%%%%%%%%%%%%% TOGGLES %%%%%%%%%%%%%%%%%%%%
    
    \newtoggle{verbose}
    \settoggle{verbose}{true}
    \newtoggle{personality}
    \settoggle{personality}{false}
    
    % This toggle tells you if this is just one creature or a team.
    \newtoggle{team}
    \settoggle{team}{false}
    
    \iftoggle{verbose}{
    
      \setcounter{tocdepth}{1}
      \setcounter{secnumdepth}{1}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcounter{r4}
    \setcounter{r4}{\day}
    \addtocounter{r4}{1}
    
      \whileboolexpr{
        test {\ifnumcomp{\value{r4}}{>}{4}}
      }
      {\addtocounter{r4}{-3}}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    
    \newcounter{r2}
    \setcounter{r2}{\value{r4}}
    \newcounter{r2b}
    
      \setcounter{r2b}{\value{r2}}
      \addtocounter{r2b}{-1}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcounter{r2c}
    \setcounter{r2c}{2}
    \newcounter{r3}
    \setcounter{r3}{\month}
    
      \divide\value{r3} by 4
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcounter{r3b}
    
      \setcounter{r3b}{\value{r4}}
      \addtocounter{r3b}{-1}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcounter{r3c}
    
      \setcounter{r3c}{0}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcounter{r4b}
    
      \setcounter{r4b}{\day}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcounter{r12}
    \setcounter{r12}{\month}
    \newcounter{enc}
    \newcounter{list}
    \newcounter{spelllevel}
    \setcounter{spelllevel}{0}
    
    \newcounter{age}
    \setcounter{age}{1}
    \newcounter{gold}
    \setcounter{gold}{\day}
    \setcounter{enc}{0}
    
    
    %%%%%%%%%%%%%%%%%%%% LAYOUT %%%%%%%%%%%%%%%%%%%%
    \makeindex
    \raggedbottom
    
    \newcommand{\currentsphere}{magic}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    
    \newcommand{\sphere}[1]{%
    
      \setcounter{spelllevel}{0}%
      \renewcommand{\currentsphere}{#1}%
      \index{#1}%
      \section{\currentsphere}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }%
    
    \newcommand{\spelllevel}{%
    
      \needspace{10em}
      \addtocounter{spelllevel}{1}%
      \subsection{\currentsphere~ Level \arabic{spelllevel}}%
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcommand{\enhancement}[3]{%
    
      \paragraph[(#1) #2: #3]{(#1) Enhancement -- #2:}%
      \index{Enhancement!#2}%
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcommand{\magicitem}[7]{%
    
      \vspace{2em}\needspace{4em}\noindent\textbf{#1}%
      \index{Magical Item!#1}
    
      \noindent
      \textit{Spells: #2, }%
      \textit{Path: #3, }%
      \textit{Duration: #4, }%
      \textit{Type: #5, }%
      \textit{Potency: +#6, }%
      \textit{MP: #7}%
      % Type can be 'Pocket Spell', 'Talisman', or 'Artefact'.
      \needspace{2em}%
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcommand{\manalake}[8]{
    
      \subsection{#1 (Level #8)}
    
      \textit{Spells: #2, }\textit{Path: #3, }\textit{Duration: #4, }\textit{Type: #5, }\textit{Potence: #6, }\textit{#7 MP}% Type can be 'pocket spell', 'magical item', or 'artefact'.
      \index{Mana Lakes!#1}
      \vspace{.3em}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcommand{\spell}[4]{
    
      \subsubsection[#1: #4]{#1}
    
      {\it Type: #2, Skill: #3}
    
      \noindent%
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    
    % Toggles for knacks
    
    %%%%%%%%%%%%%%%%%%%% Environments %%%%%%%%%%%%%%%%%%%%
    
    \newenvironment{speechtext}{
    
      \begin{boxtext}\it
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \begin{quotation}\noindent}%
    {\end{quotation}
    \end{boxtext}%
    }
    
    \newenvironment{rolltable}%
    {\vspace{.3cm}\begin{tabular}{|lp{.8\textwidth}}
    
    
    Roll & Result \\
    \hline
    
    }%
    {\end{tabular}}
    
    
    
    \newenvironment{exampletext}{
      \iftoggle{verbose}{
        \needspace{2em}\vspace{.3cm}
    
        \rule{.9\linewidth}{0.2pt}
    
        \it
      }{}
    }{
      \iftoggle{verbose}{
        \normalfont\vspace{2em}
      }{}
    }
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newtcolorbox{xpchart}[1]{tabularx={l|X},adjusted title=XP Rewards for #1,
    
      bottom=10pt,
      left=3pt,
      right=3pt,
      code={\rowcolors{3}{}{gray!10}}
      }
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    % this shows encounters, and the two counters below show the encounter number
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newtcolorbox[use counter=enc, use counter=list]{encounters}[1]{
    
      ornamented,
      adjusted title=Encounters in #1,
      tabularx={XXp{.6\textwidth}},
      bottom=10pt,
      left=3pt,
      right=3pt,
      code={\rowcolors{2}{}{gray!10}\setcounter{enc}{19}\setcounter{list}{18}}}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcommand{\li}{\addtocounter{enc}{-1}\arabic{enc}&}
    \newcommand{\lii}{\addtocounter{list}{-1}\arabic{list}&}
    
    
    \newtcolorbox{boxtable}[1][cX]{
    
      tabularx={#1},
      top=10pt,
      bottom=10pt,
      left=3pt,
      right=3pt,
      code={\rowcolors{2}{}{gray!10}\needspace{2em}}
      }
    
    
    \newtcolorbox{nametable}[2][cX]{
    
      tabularx={#1},
      top=10pt,
      adjusted title=#2,
      bottom=10pt,
      left=3pt,
      right=3pt,
      code={\rowcolors{2}{}{gray!10}\needspace{1em}}
      }
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newtcolorbox{rollchart}{
    
      tabularx={cX},
      top=10pt,
      bottom=10pt,
      left=3pt,
      right=3pt,
      code={\rowcolors{2}{}{gray!10}\needspace{2em}}
      }
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    
    \newtcolorbox{xpbox}[1]{
    
      tabularx={lX},
      bottom=10pt,
      left=3pt,
      right=3pt,
      top=10pt,
      code={\rowcolors{2}{}{gray!10}},
      equal height group=#1
      }
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    
    %%%%%%%%%%%%%%%%%%% COMMANDS %%%%%%%%%%%%%%%%%%%%
    
    \newcommand{\story}[2]{%
    
      \subsubsection{#2}
      Cost: #1\par\noindent
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcommand{\best}[2][\C]{
    
      \npc{#1}{#2}
      \subsubsection{#2}
      \index{Antagonists!#2}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcommand{\startingCondition}[1]{
      \ifnum\value{list}<95
        \item
        #1
      \fi
    }
    
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcounter{random}
    \setcounter{random}{1}
    \newcounter{increment}
    \setcounter{increment}{1}
    
    \newcommand{\random}{
    
      \addtocounter{random}{\value{page}}
      \multiply\value{random} by \value{chapter}\addtocounter{random}{\value{increment}}
      \whileboolexpr{
        test {\ifnumcomp{\value{random}}{>}{100}}
      }
      {\addtocounter{random}{-100}}
      \whileboolexpr{
        test {\ifnumcomp{\value{random}}{>}{10}}
      }
      {\addtocounter{random}{-10}}
      \addtocounter{increment}{1}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcommand{\randomtwo}{%
    
      \ifnumcomp{\value{r2}}{>}{1}{\setcounter{r2}{1}}{\addtocounter{r2}{1}}%
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \setcounter{enc}{\value{r2}}%
    }
    
    \newcommand{\randomtwoB}{
    
      \ifodd\value{r3b}\setcounter{r2b}{1}\else\setcounter{r2b}{2}\fi%
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcommand{\randomtwoC}{
    
      \ifnum\value{r2c}>1%
      \setcounter{r2c}{1}\else%
      \addtocounter{r2c}{1}%
      \fi%
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcommand{\randomthree}{%
    
      \ifnumcomp{\value{r3}}{>}{2}{\setcounter{r3}{1}}{\addtocounter{r3}{1}}%
      \setcounter{age}{\value{r3}}%
      \ifnum\value{r3}<1\setcounter{r3}{2}\fi%
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcommand{\randomthreeB}{%
    
      \ifnum\value{r3b}>2%
        \setcounter{r3b}{1}%
      \else%
        \addtocounter{r3b}{1}%
      \fi%
      \ifnum\value{r3b}<1%
        \setcounter{r3b}{3}
      \fi%
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcommand{\randomthreeC}{
    
    Malin Freeborn's avatar
    Malin Freeborn committed
      \ifnum\value{r3c}>2%
    
      \setcounter{r3c}{1}\else%
      \addtocounter{r3c}{1}%
      \fi%
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcommand{\randomfour}{%
    
      \ifnumcomp{\value{r4}}{>}{3}{\setcounter{r4}{1}}{\addtocounter{r4}{1}}%
      \ifnumcomp{\value{r4}}{<}{1}{\setcounter{r4}{1}}{}
      \setcounter{track}{\value{r4}}%
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcommand{\randomfourB}{%
    
      \ifnum\value{r4b}>3\setcounter{r4b}{1}%
      \else%
      \addtocounter{r4b}{1}%
      \fi%
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcommand{\randomdozen}{%
    
      \ifnum\value{r12}>12\setcounter{r12}{2}\fi%
      \ifnum\value{r12}<4\setcounter{r12}{2}\fi%
      \ifnum\value{age}>0\addtocounter{r12}{\value{age}}\else\ifnum\value{r4}>0\addtocounter{r12}{\value{r4}}\else\addtocounter{r12}{3}\fi\fi%
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcommand{\mapentry}[1]{
    
      \needspace{2em}
      \addtocounter{list}{1}
      \subsubsection[#1]{
        \arabic{list}: #1}
      }
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    
    %%%%% Side Quests
    
    % the first side quest gets a ticked box in the toc.
    % the rest get an empty box, so the GM can tick it once it's ready.
    
    \newtoggle{firstsq}
    \settoggle{firstsq}{true}
    
    \newcommand{\sqtoc}{\printcontents[\sqarea]{l}{2}{\section*{Summaries}\setcounter{tocdepth}{3}}}
    
    % Change the tocdepth from 2 to 3 in order to output a miniature table of contents on all side quests
    \newcommand{\sqminitoc}{
    
    
      \begin{figure*}[t]
      
      \begin{tcolorbox}[ornamented,adjusted title={Summary: \sqName}]
      \vspace{-1em}
      \printcontents[sq]{l}{2}{\setcounter{tocdepth}{3}}
      
      \end{tcolorbox}
      
      \end{figure*}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcommand{\sqName}{}
    
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcommand{\sidequest}[1]{%
    
      \renewcommand{\sqName}{#1}
      \resumecontents[\sqarea]
      \subsection{\sqName}
      \stopcontents[\sqarea]
      \settoggle{firstsq}{true}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcommand{\sqpart}[3]{\resumecontents[#1]\subsubsection[\iftoggle{firstsq}{\CheckedBox}{\Square} #2 -- #3]{(#1) #2}\stopcontents[#1]\settoggle{firstsq}{false}}
    
    %%%%% Character Sheet Commands
    
    \newcommand{\trait}[1]{
    \vspace{.2cm} #1 \line(1,0){30}
    
    
      \begin{tabular}{p{0em}p{0em}p{0em}p{0em}p{0em}p{0em}p{0em}p{0em}p{0em}}
    
        \ding{108} & \ding{109} & \ding{109} & \ding{109} & \ding{109} & \ding{109} & \ding{109} & \ding{109} & \ding{109}  \\
        \ding{111} & \ding{111} & \ding{111} & \ding{111} & \ding{111} & \ding{111} & \ding{111} & \ding{111} & \ding{111}  \\
      \end{tabular}
    
    \newcommand{\shortline}{\line(1,0){22}}  
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcommand{\weeline}{\line(1,0){30} \hspace{.6cm}}
    \newcommand{\vlongline}{\line(1,0){100}\hspace{0.8cm}}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcommand{\writeline}{\hrulefill}
    \newcommand{\fiveBoxesRow}{\ding{111} & \ding{111} & \ding{111} & \ding{111} & \ding{111}}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcommand{\fiveboxes}{\ding{111}\ding{111}\ding{111}\ding{111}\ding{111}}
    \newcommand{\threeboxes}{\ding{111}\ding{111}\ding{111}}
    \newcommand{\threecircles}{\ding{109}\ding{109}\ding{109}}
    
    \newcommand{\tenboxes}{  \ding{111} & \ding{111} & \ding{111} & \ding{111} & \ding{111} & \ding{111} & \ding{111} & \ding{111} & \ding{111} & \ding{111}  \\}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcommand{\tencircles}{\ding{109} & \ding{109} & \ding{109} & \ding{109} & \ding{109} & \ding{109} & \ding{109} & \ding{109} & \ding{109} & \ding{109}  \\}
    \newcommand{\attributecircles}{\ding{175}\ding{174}\ding{173}\ding{172}{\Large\ding{109}}\ding{172}\ding{173}\ding{174}\ding{175}}
    \newcommand{\Split}{
    
      \line(1,0){120}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    \newcommand{\skill}[1]{#1 \hrulefill & \ding{109} & \ding{109} & \ding{109} \\
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    }
    
    \newcommand{\longline}{\line(1,0){320}\par\vspace{.2cm}}