\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesClass{multicast3}[2021/09/13 v3.2.5]


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CLASS MULTICAST3
% by Nils Norman Schiborr, University of Bamberg
% CC-BY-SA 4.0 International


% ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %
% CHANGELOG
%	3.0	19-02-03	initial release

\newcommand{\classversion}{3.2.5}


% ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %
% CHECKLIST
%	[x]	adjust indent of TOC levels!
%	[  ]	adjust url styling!
%	[x]	make author surnames bold? what about other name orders?
%	[  ]	redo BibLaTeX settings!
%	[  ]	PDF metadata!
%	[x]	lists!


% ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %
% KNOWN ISSUES
%	[  ]	PDF table of contents does not list appendices


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CLASS OPTIONS

\RequirePackage{etoolbox}									% 	programming tools

% class options
\newtoggle{Tgeneral}
\DeclareOption{general}{%									%	option: general documents
	\toggletrue{Tgeneral}
}

\newtoggle{Tnotes}
\DeclareOption{notes}{%										%	option: annotation notes
	\toggletrue{Tnotes}
	\togglefalse{Tgeneral}	\togglefalse{Treferents}
	\togglefalse{Tcounts}	\togglefalse{Ttranslation}	
}

\newtoggle{Treferents}										%	option: lists of referents
\DeclareOption{referents}{%
	\toggletrue{Treferents}
	\togglefalse{Tgeneral}	\togglefalse{Tnotes}
	\togglefalse{Tcounts}	\togglefalse{Ttranslation}
}

\newtoggle{Tcounts}										%	option: corpus counts
\DeclareOption{counts}{%
	\toggletrue{Tcounts}
	\togglefalse{Tgeneral}	\togglefalse{Tnotes}
	\togglefalse{Treferents}	\togglefalse{Ttranslation}
}

\newtoggle{Ttranslation}										%	option: translated texts
\DeclareOption{translation}{%
	\toggletrue{Ttranslation}
	\togglefalse{Tgeneral}	\togglefalse{Tnotes}
	\togglefalse{Treferents}	\togglefalse{Tcounts}
}

\newtoggle{Tgray}
\DeclareOption{gray}{%										%	option: grayscale
	\toggletrue{Tgray}
}

\newtoggle{Tnologos}
\DeclareOption{nologos}{%									%	option: do not render cover logos
	\toggletrue{Tnologos}
}

\DeclareOption*{%
	\ClassWarning{multicast3}{Unknown option '\CurrentOption'}			%	option: unknown option
}

% default options
\ExecuteOptions{final}
\ExecuteOptions{general}

% pass options to class memoir
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{memoir}}
\ProcessOptions\relax
\LoadClass[11pt, a4paper, twoside, openany]{memoir}


% check for passed options
\newtoggle{Ttwocolumn}
\makeatletter
	\@ifclasswith{memoir}{twocolumn}{%
		\toggletrue{Ttwocolumn}
	}{%
		\togglefalse{Ttwocolumn}
	}
\makeatother


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PACKAGES

% tools
\RequirePackage{xparse}										%	better interface for writing commands	!!! LaTeX3 !!!
\RequirePackage{calc}										%	perform calculations on counters and lengths
\RequirePackage{xstring}										%	manipulate strings

% localization
\RequirePackage[british]{babel}									%	localization

% bibliography
\RequirePackage[obeyspaces]{url}								%	format URLs		>>> call before biblatex! <<<
	\Urlmuskip=0mu plus 1mu

\RequirePackage[	backend=biber,%
			sorting=nyt,			sortcase=false,		maxbibnames=99,		abbreviate=true,%
			backref=false,		backrefstyle=none,		date=edtf,			urldate=edtf,%
			seconds=true,		datezeros=true,		isbn=false,			eprint=false,%
			useprefix=true,		dashed=false,		mergedate=true,		sortcites=false,%
			maxcitenames=2,		ibidtracker=false,		opcittracker=false,		loccittracker=false,	%	
			idemtracker=false,%
			citestyle=linguistics-generic,%
			bibstyle=linguistics-generic]{biblatex}					%	citations and bibliography management
	\DeclareFieldFormat{postnote}{#1}


% typesetting
\RequirePackage{fontspec}									%	advanced font features	>>> requires XeLaTeX <<<
	\defaultfontfeatures{Ligatures={Common, TeX}}					%		use TeX ligatures
	\setmainfont{Linux Libertine}[Scale=1.100]	% 1.037				%		set roman font
	\setsansfont{Source Sans Pro}								%		set sans-serif font
	\setmonofont[Mapping=]{Inconsolata}[Scale=1.056]				%		set monospaced font
	\renewcommand{\familydefault}{\sfdefault}						%		make sans-serif the default

\RequirePackage{amsmath}									%	advanced mathematical typesetting	>>> call before unicode-math! <<<
\RequirePackage{unicode-math}									%	complete unicode character set for mathematics
	\setmathfont{TeX Gyre Pagella Math}							%		set maths font

\RequirePackage[	protrusion=true,
			final]{microtype}								%	advanced microtypography
													%		(expansion and tracking not available with XeLaTeX)

\RequirePackage{pifont}										%	postscript and dingbat fonts

% format
\RequirePackage{hyphenat}									%	better hyphenation control
\RequirePackage{xspace}										%	lookahead for spaces

\RequirePackage[	datetimesep=-,
			hourminsep=-]{datetime2}						%	date formatting
\RequirePackage[	group-digits=integer,
			group-minimum-digits=4,
			group-separator={\thinspace},
			detect-all]{siunitx}								%	advanced number and unit typesetting

%\RequirePackage{listings}										%	code listings

%\RequirePackage[nobottomtitles]{titlesec}							%	prevent widowed section headings
\RequirePackage[font=small]{quoting}								%	better control over quotations

\RequirePackage{multicol}										%	dynamic multi-column setups
\RequirePackage{paracol}										%	multi-column setups for parallel texts
\RequirePackage{pdflscape}									%	rotate PDF viewport

\RequirePackage{accsupp}									%	accessibility support for PDF readers

% lists
\RequirePackage{enumitem}									%	better lists
\RequirePackage{tabto}										%	custom tab widths

% graphics
\RequirePackage{graphicx}									%	graphics inclusion
\RequirePackage{xcolor}										%	advanced colour manipulation

\RequirePackage{pgf}										%	graphics creation
\RequirePackage{tikz}										%	syntax layer for PGF
	\tikzset{x=1mm, y=1mm}									%		set default dimension units

\RequirePackage{pst-barcode}									%	barcode creation

% linguistics
\RequirePackage{forest}										%	linguistic parse trees
	\useforestlibrary{edges}									%		edfe labels and styles
\RequirePackage{expex}										%	linguistic examples
	\let\expexgla\gla										%		resolve namespace conflict with unicode-math

% references
\RequirePackage[	pageanchor,
			hyperindex,
			breaklinks,
			hidelinks]{hyperref}							%	hypertext	>>> call late! <<<
\RequirePackage[	capitalize,
			nameinlink,
			noabbrev]{cleveref}							%	clever references	>>> call after hyperref! <<<

% miscellanea
\RequirePackage{metalogo}									%	TeX-family logos
\RequirePackage{lipsum}										%	dummy text


% ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %

% class modules
\RequirePackage{mc3_logos}							% [LOCAL]	%	logos for multicast3
\RequirePackage{mc3_covers}							% [LOCAL]	%	covers for multicast3
\RequirePackage{mc3_functions}						% [LOCAL]	%	document-specific functions for multicast3


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% COMMANDS

% generic counters
\newcounter{Cindex}
\newcounter{Cjndex}
\newcounter{Ckndex}
\newcounter{Ctmp}

% ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %

% font style shorthands
\NewDocumentCommand{\tit}{m}{\textit{#1}}						%	shorthand for italics
\NewDocumentCommand{\tbf}{m}{\textbf{#1}}						%	shorthand for bold
\NewDocumentCommand{\tsc}{m}{\textrm{\textsc{#1}}}					%	shorthand for small caps
\NewDocumentCommand{\tup}{m}{\textup{#1}}						%	shorthand for upshape
\NewDocumentCommand{\tnm}{m}{\textnormal{#1}}					%	shorthand for clearing font styles

% font family shorthands
\NewDocumentCommand{\tsf}{m}{\textsf{#1}}						%	shorthand for sans-serif
\NewDocumentCommand{\trm}{m}{\textrm{#1}}						%	shorthand for roman
\NewDocumentCommand{\ttt}{m}{\texttt{#1}}						%	shorthand for monospaced

% colour shorthands
\NewDocumentCommand{\tcolf}{m}{\textcolor{colourF}{#1}}				%	shorthand for coloured text, full
\NewDocumentCommand{\tcolm}{m}{\textcolor{colourM}{#1}}				%	shorthand for coloured text, mid
\NewDocumentCommand{\tcoll}{m}{\textcolor{colourL}{#1}}				%	shorthand for coloured text, light

% quotation shorthands
\NewDocumentCommand{\sqt}{m}{`#1'}							%	shorthand for single quotation marks
\NewDocumentCommand{\dqt}{m}{``#1''}							%	shorthand for double quotation marks

% bracketing shorthands
\NewDocumentCommand{\tchv}{m}{$\langle$#1$\rangle$}					%	shorthand for chevrons
\NewDocumentCommand{\tcbr}{m}{\{#1\}}							%	shorthand for curly brackets
\NewDocumentCommand{\tang}{m}{\textless#1\textgreater}				%	shorthand for angular brackets

% character shorthands
\NewDocumentCommand{\tnd}{}{\textendash}						%	shorthand for en dash
\NewDocumentCommand{\tmd}{}{\textemdash}						%	shorthand for em dash
\NewDocumentCommand{\ths}{}{\thinspace}							%	shorthand for thin space
\NewDocumentCommand{\tgrt}{}{\textgreater}						%	shorthand for greater than sign
\NewDocumentCommand{\tlss}{}{\textless}							%	shorthand for less than sign
\NewDocumentCommand{\tgeq}{}{≥}								%	shorthand for greater than or equal sign
\NewDocumentCommand{\tleq}{}{≤}								%	shorthand for less than or equal sign
\NewDocumentCommand{\ttld}{}{$\sim$}							%	shorthand for wide tilde


% ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %

% semantic markup
\NewDocumentCommand{\tword}{m}{\textit{\textrm{#1}}}				%	for object language words
\NewDocumentCommand{\tgloss}{m}{\textsc{\textrm{#1}}}				%	for inline morphological glosses
\NewDocumentCommand{\tgls}{m}{\tgloss{#1}}						%	alias for inline morphological glosses
\NewDocumentCommand{\tann}{m}{\mbox{\texttt{\color{MCgrayF}\tchv{#1}}}}	%	for annotation values
\NewDocumentCommand{\tcode}{m}{\texttt{\color{MCgrayF}#1}}			%	for inline code without highlighting
\NewDocumentCommand{\txmln}{m}{\mbox{\texttt{\color{MCgrayF}\tang{#1}}}}	%	for XML nodes
\NewDocumentCommand{\txmla}{m}{\mbox{\texttt{\textcolor{MCgrayF}{#1}}}}	%	for XML attributes
\NewDocumentCommand{\thead}{m}{\tit{\tcolm{#1}}}					%	for table headers
\NewDocumentCommand{\temph}{m}{\textcolor{colourM}{#1}}				%	for emphasis in linguistic examples

% checkmarks
\NewDocumentCommand{\checkyes}{}{\textcolor{MCgrayF}{~\ding{51}}}
\NewDocumentCommand{\checksome}{}{\textcolor{MCgrayF}{(\ding{51})}}
\NewDocumentCommand{\checkno}{}{\textcolor{MCgrayF}{~\ding{56}}}
\NewDocumentCommand{\checkdia}{}{\textcolor{MCgrayF}{\ding{117}}}

% editorial styles
\NewDocumentCommand{\tedit}{m}{\textbf{\textcolor{red}{((#1))}}}			%	mark segment as missing


% ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %

% citation commands
\newcommand{\pcite}{\parencite}								%	alias for parenthesized citations
\newcommand{\tcite}{\textcite}									%	alias for in-text citations
\newcommand{\bcite}{\cite}									%	alias for bare citations
\newcommand{\acite}{\citeauthor}								%	alias for author-only citations
\newcommand{\ycite}{\cite*}									%	alias for year-only citations

% hyperlinks to websites
\NewDocumentCommand{\turl}{mm}{\texttt{\color{MCgrayF}\href{#1}{#2}}}		%	URLs


% ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %

% half-quad
\NewDocumentCommand{\hquad}{}{\hspace*{0.5em}}

% empty accessibility substitute
\NewDocumentCommand{\eaccs}{m}{%
	\BeginAccSupp{ActualText={}}#1\EndAccSupp{}%
}

% ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %

% expandable lists with LaTeX3
\ExplSyntaxOn
	\NewDocumentCommand{\storelist}{mm} {%						%	wrapper: create list
		\meta_store_data:nn {#1} {#2}
	}

	\NewDocumentCommand{\addtolist}{mm} {%						%	wrapper: add to list
		\meta_append_data:nn {#1} {#2}
	}

	\DeclareExpandableDocumentCommand{\getlist}{O{1}m} {% 			%	wrapper: retrieve from list
		\meta_get_data:nn {#1} {#2}
	}

	\cs_new_protected:Npn \meta_store_data:nn #1 #2 {%				%	function: store data in list
		\seq_if_exist:cTF {l_meta_data_#1_seq}					%		check whether list sequence exists:
			{\seq_new:c {l_meta_data_#1_seq} }					%			if not, create sequence
			{\seq_clear:c {l_meta_data_#1_seq} }					%			if yes, clear sequence
		\__meta_append_data:nn {#1} {#2}						%		append data
	}

	\cs_new_protected:Npn \meta_append_data:nn #1 #2 {%				%	function: append data to list
		\seq_if_exist:cF {l_meta_data_#1_seq}					%		check whether list sequence exists,
			{\seq_new:c {l_meta_data_#1_seq} }					%			if not, create sequence
		\__meta_append_data:nn {#1} {#2}						%		append data
	}
	\cs_new_protected:Npn \__meta_append_data:nn #1 #2 {%			%	subroutine for appending
		\tl_map_inline:nn {#2} {%							%		append items one at a time
			\seq_put_right:cn {l_meta_data_#1_seq} {##1}
		}
	}

	\cs_new:Npn \meta_get_data:nn #1 #2 {%						%	function: retrieve data from list
		\seq_item:cn {l_meta_data_#2_seq} {#1}					%		retrieve requested list item
	}
\ExplSyntaxOff


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %

% string comparison with LaTeX3
\ExplSyntaxOn
	\cs_new_eq:NN \strcomp \str_if_eq_x:nnTF						%	function: compare strings, ifelse output	
\ExplSyntaxOff											%		\strcomp{x}{y}{true}{false}


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %

% test for empty argument to xparse commands with LaTeX3
\ExplSyntaxOn
	\DeclareExpandableDocumentCommand{\IfNoValueOrEmptyTF}{mmm}{%	%	function: check if argument is
		\IfNoValueTF{#1}{#2}{%								%		(a) not given or
			\tl_if_empty:nTF {#1} {#2} {#3}					%		(b) given but empty
		}
	}
\ExplSyntaxOff


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %

% convert seconds to h:mm:ss
\newcounter{Cconvhours}
\newcounter{Cconvminutes}
\newcounter{Cconvseconds}

\NewDocumentCommand{\secstotime}{m}{%
	\setcounter{Cconvhours}{#1/3600}
	\setcounter{Cconvminutes}{#1/60 - \theCconvhours * 60}
	\setcounter{Cconvseconds}{#1 - \theCconvminutes * 60 - \theCconvhours * 3600}

	\num[minimum-integer-digits=1]{\theCconvhours}:%
	\num[minimum-integer-digits=2]{\theCconvminutes}:%
	\num[minimum-integer-digits=2]{\theCconvseconds}
}

% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %

% custom code listing environment
\newenvironment{codelisting}{	\par%
					\ttfamily%
					\color{MCgrayF}%
					\setlength{\parindent}{0mm}%
					\medskip}{%
					\medskip\par}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% COLOURS

% define colours
\definecolor{MCblueF}{RGB}{0,91,164}							%	blue
\definecolor{MCblueM}{RGB}{42,120,179}
\definecolor{MCblueL}{RGB}{191,214,232}

\definecolor{MCceruleanF}{RGB}{0,122,166}							%	cerulean
\definecolor{MCceruleanM}{RGB}{42,144,181}
\definecolor{MCceruleanL}{RGB}{191,222,233}

\definecolor{MCtealF}{RGB}{33,120,103}							%	teal
\definecolor{MCtealM}{RGB}{70,142,128}
\definecolor{MCtealL}{RGB}{199,221,217}

\definecolor{MCgreenF}{RGB}{79,126,4}							%	green
\definecolor{MCgreenM}{RGB}{107,147,45}
\definecolor{MCgreenL}{RGB}{211,223,192}

\definecolor{MCappleF}{RGB}{131,146,0}							%	apple
\definecolor{MCappleM}{RGB}{151,164,42}
\definecolor{MCappleL}{RGB}{224,228,191}

\definecolor{MCgrayF}{RGB}{85,85,81}							%	grays
\definecolor{MCgrayM}{RGB}{113,113,110}
\definecolor{MCgrayL}{RGB}{212,212,211}

\definecolor{MCeclipse}{RGB}{43,43,43}							%	other
\definecolor{MCanthracite}{RGB}{60,60,60}
\definecolor{MCovercast}{RGB}{138,138,135}
\definecolor{MCpaper}{RGB}{242,242,242}

% assign colours by option
\iftoggle{Tgeneral}{%
	\colorlet{colourF}{MCblueF}								%	general documents
	\colorlet{colourM}{MCblueM}
	\colorlet{colourL}{MCblueL}
}

\iftoggle{Tnotes}{%
	\colorlet{colourF}{MCceruleanF}								%	annotation notes
	\colorlet{colourM}{MCceruleanM}
	\colorlet{colourL}{MCceruleanL}
}

\iftoggle{Treferents}{%
	\colorlet{colourF}{MCtealF}								%	list of referents
	\colorlet{colourM}{MCtealM}
	\colorlet{colourL}{MCtealL}
}

\iftoggle{Tcounts}{%
	\colorlet{colourF}{MCgreenF}								%	corpus counts
	\colorlet{colourM}{MCgreenM}
	\colorlet{colourL}{MCgreenL}
}

\iftoggle{Ttranslation}{%
	\colorlet{colourF}{MCappleF}								%	translated texts
	\colorlet{colourM}{MCappleM}
	\colorlet{colourL}{MCappleL}
}

\iftoggle{Tgray}{%
	\colorlet{colourF}{MCgrayF}								%	gray
	\colorlet{colourM}{MCgrayM}
	\colorlet{colourL}{MCgrayL}
}

% assign colours by function
\colorlet{textcolour}{MCanthracite}								%	text colour

\colorlet{headcolour}{colourM}									%	colour of head
\colorlet{fnmarkcolour}{colourM}									%	colour of footnote marks
\colorlet{captionlabelcolour}{colourM}								%	colour of caption titles
\colorlet{exnumcolour}{colourM}									%	colour of example numbers
\colorlet{itemizeAcolour}{MCgrayF}								%	colour of itemized list bullets, first level
\colorlet{itemizeBcolour}{MCgrayM}								%	colour of itemized list bullets, second level
\colorlet{itemizeCcolour}{MCovercast}								%	colour of itemized list bullets, third level
\colorlet{enumeratecolour}{MCgrayF}								%	colour of enumerated list labels
\colorlet{alphabetizecolour}{MCgrayF}								%	colour of alphabetized list labels
\colorlet{descriptioncolour}{MCgrayF}								%	colour of description list labels

\colorlet{colophoncolour}{MCgrayM}								%	colour of colophon text
\colorlet{colophonheadingcolour}{MCgrayM}							%	colour of colophon headings

\colorlet{tocnumbercolour}{colourM}								%	colour of TOC section and page numbers
\colorlet{tocchaptercolour}{colourM}								%	colour of TOC chapter titles
\colorlet{tocsectioncolour}{colourM}								%	colour of TOC section titles
\colorlet{tocssectioncolour}{colourM}								%	colour of TOC subsection titles
\colorlet{tocsssectioncolour}{colourM}								%	colour of TOC subsubsection titles
\colorlet{tocleadercolour}{MCovercast}								%	colour of TOC leaders

\colorlet{sectioncolour}{colourM}									%	colour of section titles
\colorlet{ssectioncolour}{colourF}								%	colour of subsection titles
\colorlet{sssectioncolour}{colourF}								%	colour of subsubsection titles


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% REFERENCES

% references with cleveref
\newcommand{\refx}{\cref}									%	alias for cleveref references

% define conjunctions
\NewDocumentCommand{\crefrangeconjunction}{}{\textendash}				%	conjunction for numerical ranges
\NewDocumentCommand{\creflastconjunction}{}{, and }					%	final conjunction in lists with n > 2 elements
\NewDocumentCommand{\creflastgroupconjunction}{}{, and }				%	final conjunction in mixed lists with n > 2 elements


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %

% define aliases for expex example numbers so that cleveref can access them
\newcounter{exnumi}										%	alias for expex counter 'excnt'
\setcounter{exnumi}{0}
\newcounter{exnumiilabel}									%	alias for expec counter 'pexcnt'
\setcounter{exnumiilabel}{0}
\newcounter{exnumii}										%	hook for references
\setcounter{exnumii}{0}

% expex reference labels
\crefname{exnumi}{}{}										%	reference name for linguistic examples, level 1
\creflabelformat{exnumi}{#2(#1)#3}								%	label format for linguistic examples, level 1
\crefrangelabelformat{exnumi}{#3(#1#4\textendash#5#2)#6}				%	label format for ranges of linguistic examples, level 1

\renewcommand{\theexnumii}{\arabic{exnumi}\symbol{\theexnumiilabel}} 		%	redefine hook to include numerical and alphabetical labels
\crefname{exnumii}{}{}										%	reference name for linguistic examples, level 2
\creflabelformat{exnumii}{#2(#1)#3}								%	label format for linguistic examples, level 2
\crefrangelabelformat{exnumii}{#3(#1#4\textendash#5#2)#6} 				%	label format for ranges of linguistic examples, level 2

% custom labelling commands for expex examples
\NewDocumentCommand{\exlabel}{m}{\setcounter{exnumi}{\excnt-1}\refstepcounter{exnumi}\label{#1}}
\NewDocumentCommand{\pexlabel}{m}{\setcounter{exnumi}{\excnt}\setcounter{exnumiilabel}{\pexcnt-1}\refstepcounter{exnumii}\label{#1}}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PAGE LAYOUT

\setlrmarginsandblock{24.00mm}{33.00mm}{*}	% 21 28				%	\spinemargin		\textwidth - \spinemargin		ratio
\setulmarginsandblock{34.00mm}{38.00mm}{*}						%	\uppermargin	\textheight - \uppermargin	ratio
\setheadfoot{11.00mm}{8.0mm}									%	\headheight		\footskip
\setheaderspaces{15.00mm}{*}{*}								%	\headdrop		\headsep				ratio
\setcolsepandrule{4.3mm}{0pt}									%	\columnsep		\columnseprule

\checkandfixthelayout


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% METADATA

% corpus
\newtoggle{Tcorpus}										%	has the subtitle been set?

\NewDocumentCommand{\corpus}{mm}{%
	% check for missing argument: subtitle
	\IfNoValueOrEmptyTF{#1}{%
		\storelist{corpus}{{CORPUS}}%							%	if no subtitle supplied, set default value
	}{%
		\storelist{corpus}{{#1}}%							%	store subtitle
	}%

	% check for missing argument: corpus identifier
	\IfNoValueOrEmptyTF{#2}{%
		\addtolist{corpus}{{CORPUS IDENTIFIER}}%					%	if no identifier supplied, set default value
	}{%
		\addtolist{corpus}{{#2}}%							%	store subtitle
	}%

	\toggletrue{Tcorpus}%
}


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %

% title
\newtoggle{Ttitle}											%	has the title been set?

\RenewDocumentCommand{\title}{m}{%							%	set title
	% check for missing argument
	\IfNoValueOrEmptyTF{#1}{%								%	if no title supplied, set default value
		\iftoggle{Tgeneral}{\storelist{title}{{TITLE}}}{}%
		\iftoggle{Tnotes}{\storelist{title}{{annotation notes}}}{}%
		\iftoggle{Treferents}{\storelist{title}{{list of referents}}}{}%
		\iftoggle{Tcounts}{\storelist{title}{{corpus counts}}}{}%
		\iftoggle{Ttranslation}{\storelist{title}{{translated texts}}}{}%
	}{%
		\storelist{title}{{#1}}%								%	store first line
	}%

	\toggletrue{Ttitle}%
}


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %

% authors
\newcounter{Cauthors}										%	counter for authors

\NewDocumentCommand{\addauthor}{mmo}{%
	% check for missing argument: surname
	\IfNoValueOrEmptyTF{#1}{%
		\addtolist{authors}{{SURNAME}}%						%	if no surname supplied, set default value
	}{%
		\addtolist{authors}{{#1}}%							%	set surname
	}%

	% check for missing argument: given name
	\IfNoValueOrEmptyTF{#2}{%
		\addtolist{authors}{{GIVENNAME}}%						%	if no given name supplied, set default value
	}{%
		\addtolist{authors}{{#2}}%							%	set given name
	}%

	% check for missing optional argument: middle name(s)
	\IfNoValueOrEmptyTF{#3}{%
		\addtolist{authors}{{}}%								%	if no middle name supplied, set default value
	}{%
		\addtolist{authors}{{#3}}%							%	set middle name
	}%

	% check for missing optional argument: affiliation
%	\IfNoValueOrEmptyTF{#4}{%
%		\addtolist{authors}{{AFFILIATION}}%						%	if no affiliation supplied, set default value
%	}{%
%		\addtolist{authors}{{#4}}%							%	set middle name
%	}%

	\stepcounter{Cauthors}%
}


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %

% corpus version
\newtoggle{Tvkey}											%	has the version key been set?

\NewDocumentCommand{\vkey}{mm}{%
	% check for missing argument: version key
	\IfNoValueOrEmptyTF{#1}{%
		\storelist{vkey}{{0000}}%							%	if no vkey supplied, set default value
	}{%
		\storelist{vkey}{{#1}}%								%	store vkey
	}%

	% check for missing argument: version release date
	\IfNoValueOrEmptyTF{#2}{%
		\addtolist{vkey}{{MONTH YEAR}}%						%	if no date supplied, set default value
	}{%
		\addtolist{vkey}{{#2}}%								%	store date
	}%

	\toggletrue{Tvkey}%
}


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %

% publication date
\newtoggle{Tdate}											%	has the publication date been set?

\RenewDocumentCommand{\date}{mmm}{%
	% check for missing argument: year
	\IfNoValueOrEmptyTF{#1}{%
		\storelist{date}{{0000}}%							%	if no year supplied, set default value
	}{%
		\storelist{date}{{#1}}%								%	store year
	}%

	% check for missing argument: month
	\IfNoValueOrEmptyTF{#2}{%
		\addtolist{date}{{12}}%								%	if no month supplied, set default value
	}{%
		\addtolist{date}{{#2}}%								%	store year
	}%

	% check for missing argument: day
	\IfNoValueOrEmptyTF{#3}{%
		\addtolist{date}{{31}}%								%	if no day supplied, set default value
	}{%
		\addtolist{date}{{#3}}%								%	store day
	}%

	\toggletrue{Tdate}%
}


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %

% document version
\newtoggle{Tversion}										%	has the version been set?

\NewDocumentCommand{\version}{m}{%
	% check for missing argument
	\IfNoValueOrEmptyTF{#1}{%
		\storelist{version}{{VERSION}}%						%	if no version supplied, set default value
	}{%
		\storelist{version}{{#1}}%							%	store version
	}%

	\toggletrue{Tversion}%
}


% ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %

% check metadata for completeness
\NewDocumentCommand{\checkmetadata}{}{%
	\iftoggle{Tcorpus}{}{%									%	has the corpus been set?
		\corpus{}{}%
	}%

	\iftoggle{Ttitle}{}{%									%	has the title been set?
		\title{}%
	}%

	\ifnumcomp{\theCauthors} < 1 {%							%	is there at least one author?
		\addauthor{}{}[]{}%
	}{}%

	\iftoggle{Tvkey}{}{%									%	has the version key been set?
		\vkey{}{}%
	}%

	\iftoggle{Tdate}{}{%									%	has the date been set?
		\date{}{}{}%
	}%

	\iftoggle{Tversion}{}{%									%	has the version been set?
		\version{}%
	}%
}


% ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %
% PDF METADATA

\NewDocumentCommand{\pdfmetadata}{}{%
	\hypersetup{%
		pdfsubject={Multi-CAST: Multilingual Corpus of Annotated Spoken Texts},% 
		pdfkeywords={linguistics, corpus-based, typology, discourse, Bamberg}%
	}%
	%
	\iftoggle{Tgeneral}{%
		\hypersetup{pdftitle={Multi-CAST \getlist[1]{title} (v\getlist[1]{version})}}%
	}{%
		\hypersetup{pdftitle={Multi-CAST \getlist[1]{corpus} \getlist[1]{title} (v\getlist[1]{version})}}%
	}%
	%
	% set PDF authors
	\hypersetup{pdfauthor={\getlist[2]{authors} \getlist[1]{authors} et al.}}
	\ifnumcomp{\theCauthors} = 1 {\hypersetup{pdfauthor={\getlist[2]{authors} \getlist[1]{authors}}}}{%
	\ifnumcomp{\theCauthors} = 2 {\hypersetup{pdfauthor={\getlist[2]{authors} \getlist[1]{authors}, %
										\getlist[5]{authors} \getlist[4]{authors}}}}{%
	\ifnumcomp{\theCauthors} = 3 {\hypersetup{pdfauthor={\getlist[2]{authors} \getlist[1]{authors}, %
										\getlist[5]{authors} \getlist[4]{authors}, %
										\getlist[8]{authors} \getlist[7]{authors}}}}{%
	\ifnumcomp{\theCauthors} = 4 {\hypersetup{pdfauthor={\getlist[2]{authors} \getlist[1]{authors}, %
										\getlist[5]{authors} \getlist[4]{authors}, %
										\getlist[8]{authors} \getlist[7]{authors}, %
										\getlist[11]{authors} \getlist[10]{authors}}}}{%
	}}}}%
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PAGE STYLES

% general settings
\nouppercaseheads

% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %
% primary page style
\copypagestyle{mc3-main}{plain}

\makeoddhead{mc3-main}
	{\sffamily\upshape\color{headcolour}\eaccs{\iftoggle{Tgeneral}{%
								\textbf{Multi-CAST}~~\itshape\getlist[1]{title}%
							   }{%
								\textbf{Multi-CAST}~~\itshape\getlist[1]{corpus}~~\itshape\getlist[1]{title}%
							   }}}
	{}
	{\sffamily\upshape\large\color{headcolour}\eaccs{\thepage}}

\makeevenhead{mc3-main}
	{\sffamily\upshape\large\color{headcolour}\eaccs{\thepage}}
	{}
	{\sffamily\upshape\color{headcolour}\itshape\eaccs{\headauthors}}

\makeoddfoot{mc3-main}{}{}{}
\makeevenfoot{mc3-main}{}{}{}

% adjust widths
\makerunningwidth{mc3-main}{1.05\textwidth}
\makeheadposition{mc3-main}{flushright}{flushleft}{}{}


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %
% frontmatter page style
\copypagestyle{mc3-front}{mc3-main}

\makeoddhead{mc3-front}
	{}
	{}
	{\sffamily\upshape\large\color{headcolour}\eaccs{\thepage}}

\makeevenhead{mc3-front}
	{\sffamily\upshape\large\color{headcolour}\eaccs{\thepage}}
	{}
	{}

\makeoddfoot{mc3-front}{}{}{}
\makeevenfoot{mc3-front}{}{}{}


% ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %

% linearize authors for page head
\NewDocumentCommand{\headauthors}{}{%
	\ifnumcomp{\theCauthors} = 1 {%					%	n = 1 author
		\getlist[2]{authors}\xspace\getlist[3]{authors} \getlist[1]{authors}%
	}{%
		\ifnumcomp{\theCauthors} = 2 {%				%	n = 2 authors
			\getlist[2]{authors} \getlist[1]{authors},~~\getlist[5]{authors} \getlist[4]{authors}%
		}{%
			\setcounter{Cindex}{0}%					%	n > 2 authors
			\whileboolexpr{test {\ifnumcomp{\theCindex} < {\theCauthors}}}{%
				\getlist[\theCindex*3+2]{authors} \getlist[\theCindex*3+1]{authors}%
				\ifnumcomp{\theCindex} = {\theCauthors - 1}{}{%
					\ifnumcomp{\theCindex} = {\theCauthors - 2}{%
						,~~%					%	penultimate
					}{%
						,~~%					%	pre-penultimate
					}%
				}%
				\stepcounter{Cindex}%
			}%
		}%
	}%
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SECTION HEADINGS

% numbering
\renewcommand*{\thesection}{\arabic{section}}						%	do not number chapters
\setsecnumdepth{subsubsection}								%	number sections up to and including subsubsections

% format
\setsecheadstyle{\LARGE\sffamily\bfseries\color{sectioncolour}}				%	section heading text
\setsubsecheadstyle{\Large\itshape\sffamily\color{ssectioncolour}}			%	subsection heading text
\setsubsubsecheadstyle{\large\itshape\sffamily\itshape\color{sssectioncolour}}		%	subsubsection heading text
\setparaheadstyle{\sffamily\itshape\color{MCgrayF}}					%	paragraph heading style
\setsubparaheadstyle{\sffamily\itshape\color{MCgrayF}}					%	subparagraph heading style

% horizontal positioning
\setsubparaindent{0em}										%	subparagraph indent

% vertical positioning
\setbeforeparaskip{0.6\baselineskip}								%	vertical skip before paragraphs
\setbeforesubparaskip{0.6\baselineskip}							%	vertical skip before subparagraphs


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FOOTNOTES

% positioning
\setlength{\skip\footins}{21pt}									%	vertical space between text block and footnote
\setlength{\footnotesep}{8pt}									%	vertical space between individual footnotes
\feetbelowfloat											%	footnotes are placed below bottom floats

% footnote rule
\let\oldfootnoterule\footnoterule									%	disable footnote rule
\renewcommand*{\footnoterule}{}

% footnote marks
\makeatletter
	\renewcommand{\@makefnmark}{%							%	mark in text
		\hbox{\textsuperscript{\textcolor{fnmarkcolour}{\@thefnmark}}}%
	}%
\makeatother

\footmarkstyle{%											%	mark in footnote
	\quad\hfill\scriptsize\color{fnmarkcolour}\sffamily#1\hspace{1em}%
}
\setlength{\footmarkwidth}{1.8em}

% footnote text
\renewcommand*{\foottextfont}{\footnotesize}						%	footnote text
\setlength{\footmarksep}{0em}									%	no hanging indent in footnote text
\setlength{\footparindent}{0.6\parindent}							%	indent second and following paragraphs in footnote


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LISTS

% list definitions
\newlist{alphabetize}{enumerate}{2}								%	define alphabetically labelled list
\newlist{graidlist}{description}{1}								%	define list of GRAID symbols
\newlist{glosslist}{description}{1}								%	define list of morphological glosses

% vertical spacing
\tightlists												%	tightly spaced list items
\setlist{topsep=0.3\onelineskip, itemsep=0.15mm}						%	space between list and preceding paragraph, all levels
\setlist[2]{topsep=0mm}										%	vertical spacing, level 2
\setlist[3]{topsep=0mm}										%	vertical spacing, level 3

% horizontal spacing
\SetLabelAlign{left-itemize}{~#1\hfill}								%	horizontal alignment of label


% ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %

% itemized lists
\setlist[itemize]{%											%	itemized lists, all levels
	leftmargin=!,
	labelindent=1\parindent,
	labelwidth=1em,
	labelsep*=0.75em,
	align=left-itemize
}

\setlist[itemize,1]{%										%	itemized lists, first level
	label=\scriptsize\color{itemizeAcolour}\ding{117}
}

\setlist[itemize,2]{%										%	itemized lists, second level
	labelindent=0.25\parindent,
	label=\tiny\color{itemizeBcolour}\ding{117}
}

\setlist[itemize,3]{%										%	itemized lists, third level
	labelindent=0.25\parindent,
	label=\tiny\color{itemizeCcolour}\ding{117}
}


% ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %

% enumerated lists
\setlist[enumerate]{%										%	enumerated lists, all levels
	leftmargin=!,
	labelindent=1\parindent,
	labelwidth=1em,
	labelsep*=0.75em,
	align=left
}

\setlist[enumerate,1]{%										%	enumerated lists, first level
	font=\sffamily\color{enumeratecolour}
}

\setlist[enumerate,2]{%										%	enumerated lists, second level
	labelindent=0.25\parindent,
	font=\sffamily\color{enumeratecolour},
	label=\alph*.
}

\setlist[enumerate,3]{%										%	enumerated lists, third level
	labelindent=0.25\parindent,
	font=\sffamily\color{enumeratecolour},
	label=\roman*.
}


% ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %

% alphabetized lists
\setlist[alphabetize]{%										%	alphabetized lists, all levels
	leftmargin=!,
	labelindent=1\parindent,
	labelwidth=1em,
	labelsep*=0.75em,
	align=left
}

\setlist[alphabetize,1]{%										%	alphabetized lists, first level
	font=\sffamily\color{alphabetizecolour},
	label=\alph*.
}

\setlist[alphabetize,2]{%										%	alphabetized lists, second level
	labelindent=0.25\parindent,
	font=\sffamily\color{alphabetizecolour},
	label=\roman*.
}


% ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %

% descriptions
\setlist[description]{%										%	descriptions
	leftmargin=!,
	labelindent=1em,
	labelsep=0.75em,
	itemindent=-0.75\parindent,
	itemsep=0.75mm,
	font=\normalfont\sffamily\itshape\color{descriptioncolour}
}


% ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %

% GRAID symbol lists
\setlist[graidlist]{%											%	GRAID symbol lists
	leftmargin=!,
	rightmargin=3em,
	labelindent=1em,
	labelsep=1em,
	labelwidth=6em,
	itemindent=0em,
	itemsep=0.75mm,
	font=\normalfont\small\color{descriptioncolour},
	before=\small\raggedright
}


% ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %

% lists of abbreviated morphological glosses
\setlist[glosslist]{%											%	gloss lists
	leftmargin=!,
	rightmargin=3em,
	labelindent=1em,
	labelsep=1em,
	labelwidth=4em,
	itemindent=0em,
	itemsep=0.75mm,
	font=\normalfont\small\rmfamily\scshape\color{descriptioncolour},
	before=\small\raggedright
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FLOATS

% floating
\setcounter{topnumber}{2}					%	(default = 2)		%	maximum number of top floats on a page
\setcounter{bottomnumber}{1}					%	(default = 1)		%	maximum number of bottom floats on a page
\setcounter{totalnumber}{3}					%	(default = 3)		%	maximum number of floats on a text page

\renewcommand{\topfraction}{0.7}				%	(default=0.7)	%	maximum fraction of page reserved for top floats
\renewcommand{\bottomfraction}{0.1}				%	(default=0.3)	%	maximum fraction of page reserved for bottom floats
\renewcommand{\textfraction}{0.3}				%	(default=0.2)	%	miminum fraction of page that must have text
\renewcommand{\floatpagefraction}{0.7}			%	(default=0.5)	%	minimum fraction of floats on a float page

% captions
\counterwithout{table}{chapter}									%	do not count tables by chapter
\counterwithout{figure}{chapter}								%	do not count figures by chapter

\captionnamefont{\small\sffamily\bfseries\color{captionlabelcolour}}			%	caption label font
\captiontitlefont{\small}										%	caption text font
\captiondelim{\quad}										%	delimiter between number and text

\captionstyle[\centering]{}									%	justification of captions
\hangcaption												%	caption text has hanging indent
\captionwidth{0.85\textwidth}									%	width of caption
\changecaptionwidth										%	apply changes to caption width

\setlength{\belowcaptionskip}{0pt}								%	skip below caption


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LINGUISTIC EXAMPLES

% define widths
\newlength{\Lexnumwidth}									%	maximum width of example number
\settowidth{\Lexnumwidth}{\sffamily\upshape(999)}
\addtolength{\Lexnumwidth}{0.25\parindent}

\newlength{\Lexlabelwidth}									%	width of example label
\settowidth{\Lexlabelwidth}{\sffamily\upshape w.}

% expex settings
\lingset{%
	aboveexskip=0.7\onelineskip,
	belowexskip=1\onelineskip,
	interpartskip=0.3\onelineskip,
	belowpreambleskip=0.15\onelineskip,
	numoffset=\Lexnumwidth,
	labeloffset=1em,
	labelwidth=\Lexlabelwidth,
	labelalign=right,
	textoffset=0.7\parindent,
	preambleoffset=1em,
	exnoformat={\sffamily\upshape\color{exnumcolour}(X)},
	labelformat={\sffamily\upshape\color{exnumcolour}A.},
	everyex={\small\itshape},
	everyglpreamble={\upshape\itshape\rmfamily},
	everygla={\upshape\itshape\rmfamily},
	everyglb={\upshape},
	everyglc={\upshape\ttfamily},
	everyglft={\upshape},
	belowglpreambleskip=-0.5ex,
	aboveglbskip=0ex,
	aboveglftskip=-0.5ex,
	extraglskip=1.25ex,
	glhangstyle=normal,
	glhangindent=0ex,
	everytrailingcitation={\upshape\footnotesize},
	mincitesep=5em,
}

\makeatletter
	\renewcommand{\exnoprint}{\llap{\ep@exnoformat{\ep@rawexnoprint}}}	%	right-align example numbers
\makeatother

% miscellanea
\newcommand{\glp}{\glpreamble}								%	alias for gloss preamble
\newcommand{\glt}{\glft}										%	alias for gloss translation

\NewDocumentCommand{\exsource}{m}{\trailingcitation{(#1)}}
\NewDocumentCommand{\excorpus}{m}{\trailingcitation{\ttfamily[#1]}}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CODE LISTINGS



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DOCUMENT DIVISIONS

% initializer for front matter
\NewDocumentCommand{\mcfrontmatter}{}{%
	\frontmatter
	\pagestyle{mc3-front}
	\pagenumbering{roman}
}

% initializer for main matter
\NewDocumentCommand{\mcmainmatter}{}{%
	\mainmatter
	\pagestyle{mc3-main}
	\pagenumbering{arabic}

	\counterwithout{table}{chapter}								%	do not count tables by chapter
	\counterwithout{figure}{chapter}							%	do not count figures by chapter


	% paracol settings for translated texts
	\iftoggle{Ttranslation}{%
		\columnratio{0.05,0.475}%							%	column widths (0.05 -- 0.475 -- 0.475)
		\setlength{\parindent}{0em}%							%	set paragraph indent to zero
		\setlength{\parskip}{0.1em}%							%	set paragraph skip
		\sloppy%										%	most languages do not have hyphenation rules,
													%		so set to \sloppy
		\small%										%	save paper and reduce underfull boxes
	}{}

	% paracol settings for lists of referents
	\iftoggle{Treferents}{%
		\columnratio{0.075,0.20,0.30,0.065,0.11}%					%	column widths (0.06 -- 0.21 -- 0.36 -- 0.06 -- 0.1 -- 0.21)
	}
}

% initializer for back matter
\NewDocumentCommand{\mcbackmatter}{}{%
	\backmatter
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TABLE OF CONTENTS

% settings
\onecoltocetc											%	TOC spans all columns
\maxtocdepth{subsubsection}									%	TOC lists sections up to and including subsections

% heading
\RenewDocumentCommand{\printtoctitle}{m}{\section*{#1}}				%	TOC heading is section level
\RenewDocumentCommand{\aftertoctitle}{}{}


% horizontal spacing
\setlength{\cftchapterindent}{1.5\parindent}

% vertical spacing
\setlength{\cftbeforechapterskip}{6mm}
\setlength{\cftbeforesectionskip}{2mm}
\setlength{\cftbeforesubsectionskip}{0.6mm}
\setlength{\cftbeforesubsubsectionskip}{0.6mm}

% section numbers
\RenewDocumentCommand{\cftchaptername}{}{\large\sffamily\bfseries\color{tocchaptercolour}}
\RenewDocumentCommand{\cftsectionname}{}{\large\sffamily\bfseries\color{tocsectioncolour}}
\RenewDocumentCommand{\cftsubsectionname}{}{\large\sffamily\color{tocssectioncolour}}
\RenewDocumentCommand{\cftsubsubsectionname}{}{\large\sffamily\color{tocsssectioncolour}}

% section titles
\RenewDocumentCommand{\cftchapterfont}{}{\large\sffamily\bfseries\color{tocchaptercolour}}
\RenewDocumentCommand{\cftsectionfont}{}{\large\sffamily\bfseries\color{tocsectioncolour}}
\RenewDocumentCommand{\cftsubsectionfont}{}{\large\sffamily\color{textcolour}}
\RenewDocumentCommand{\cftsubsubsectionfont}{}{\large\sffamily\color{textcolour}}

% page numbers
\RenewDocumentCommand{\cftchapterpagefont}{}{\large\sffamily\color{tocchaptercolour}}
\RenewDocumentCommand{\cftsectionpagefont}{}{\large\sffamily\color{tocsectioncolour}}
\RenewDocumentCommand{\cftsubsectionpagefont}{}{\large\sffamily\color{textcolour}}
\RenewDocumentCommand{\cftsubsubsectionpagefont}{}{\large\sffamily\color{textcolour}}

% leaders
\RenewDocumentCommand{\cftdotsep}{}{9999}						%	spacing of dot leader
\RenewDocumentCommand{\cftdot}{}{\color{tocleadercolour}.}				%	colour of dot leader
\RenewDocumentCommand{\cftsectionleader}{}{\quad\color{tocleadercolour}\MCrulefill} %	set leader for section-level entries


% ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ %

% vertically centered \hrulefill for section leaders
\NewDocumentCommand{\MCrulefill}{}{%
	\leavevmode\leaders\hrule height 0.6ex depth \dimexpr0.3pt-0.6ex\hfill\kern6pt%
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CONTENTS LISTS

% settings
\pretocmd{\listoftables}{%
	\cleardoublepage%										%	LOT starts recto
	\renewcommand{\listtablename}{List of tables}%					%	rename LOT
}{}{}{}

\pretocmd{\listoffigures}{%
	\cleardoublepage%										%	LOF starts recto
	\renewcommand{\listfigurename}{List of figures}%					%	rename LOF
}{}{}{}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LIST OF REFERENCES

% settings
\renewcommand*{\bibfont}{\small}								%	set font size of bibliography entries

% list of references
\NewDocumentCommand{\references}{}{%
%	\clearpage

	% check if twocolumn option is in effect
%	\iftoggle{Ttwocolumn}{}{\twocolumn}

	\phantomsection
	\addcontentsline{toc}{chapter}{References}
	\section*{References}
	\label{sec:references}

	{
		\emergencystretch=2em
		\printbibliography[heading=none]
	}

	% revert to document column mode
%	\iftoggle{Ttwocolumn}{\clearpage}{\onecolumn}
}

% list of references: collection overview
\NewDocumentCommand{\mcbibliography}{}{%
	\clearpage
	\phantomsection
	\addcontentsline{toc}{chapter}{Bibliography}
	\section*{Bibliography}
	\label{sec:bibliography}

	{
		\emergencystretch=2em
		\phantomsection
		\addcontentsline{toc}{subsection}{The Multi-CAST collection}
		\subsection*{The Multi-CAST collection}
		\label{ssec:references-mc}
		\printbibliography[category=multicast,heading=none]
		\printbibliography[category=corpora,heading=none]
		\printbibliography[category=documentation,heading=none]

		\phantomsection
		\addcontentsline{toc}{subsection}{References}
		\subsection*{References}
		\label{ssec:references}
		\printbibliography[notcategory=multicast,notcategory=corpora,notcategory=documentation,heading=none]
	}
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% APPENDICES

% TOC style changes
\cftinsertcode{appendixstyle}{%
	\maxtocdepth{subsection}								%	TOC lists appendices and subappendices
	
	% horizontal spacing
	\setlength{\cftsectionindent}{4em}
	\addtolength{\cftsectionnumwidth}{\widthof{0.}}
	\setlength{\cftsubsectionindent}{7em}

	% vertical spacing
	\setlength{\cftbeforesectionskip}{0.6mm}
	\setlength{\cftbeforesubsectionskip}{0.6mm}

	% section numbers
	\RenewDocumentCommand{\cftsectionname}{}{\large\sffamily\color{tocssectioncolour}}
	\RenewDocumentCommand{\cftsubsectionname}{}{\large\sffamily\color{tocsssectioncolour}}
	
	% section titles
	\RenewDocumentCommand{\cftsectionfont}{}{\large\sffamily\color{textcolour}}
	\RenewDocumentCommand{\cftsubsectionfont}{}{\large\sffamily\color{textcolour}}
	
	% page numbers
	\RenewDocumentCommand{\cftsectionpagefont}{}{\large\sffamily\color{textcolour}}
	\RenewDocumentCommand{\cftsubsectionpagefont}{}{\large\sffamily\color{textcolour}}
	
	% leaders
	\RenewDocumentCommand{\cftsectionleader}{}{\cftdotfill{9999}} 		%	set leader for section-level entries
}

% appendix initializer
\RenewDocumentCommand{\appendices}{O{Appendices}}{%				%	start appendices
	% adjust counters
	\setsecnumdepth{subsubsection}							%	re-initialize counters 
	\setcounter{section}{0}									%		(which memoir's \backmatter had turned off)
	\setcounter{figure}{0}
	\setcounter{table}{0}

	\renewcommand{\thesection}{\Alph{section}}						%	number sections alphabetically
	\renewcommand{\theHsection}{\Alph{section}}
	\counterwithin{figure}{section}								%	count figures within sections (= appendices)
	\counterwithin{table}{section}								%	count tables within sections (= appendices)

	% adjust references [cleveref]
	\crefname{section}{Appendix}{Appendices}						%	reference name for sections (= appendices)
	\crefname{subsection}{Appendix}{Appendices}					%	reference name for subsections (= subappendices)
	\crefname{subsubsection}{Appendix}{Appendices}					%	reference name for subsubsections (= subsubappendices)

	% print appendices header
	\clearpage
	\phantomsection\cftaddtitleline{toc}{chapter}{#1}{\thepage}			%	add line to TOC
	\section*{#1}										%	print Appendices header
	\label{apx:appendices}

	% apply TOC style changes
	\cftinserthook{toc}{appendixstyle}

	% restyle section headings
	\setsecheadstyle{\Large\sffamily\bfseries\color{sectioncolour}}			%	section heading text
	\setsubsecheadstyle{\large\itshape\sffamily\color{ssectioncolour}}		%	subsection heading text
	\setsubsubsecheadstyle{\itshape\sffamily\itshape\color{sssectioncolour}}	%	subsubsection heading text
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% INITIALIZATION

% settings
\pagestyle{mc3-main}										%	set default page style
\color{textcolour}											%	set default text colour

% execute at \begin{document}
\AtBeginDocument{%
	\let\gla\expexgla										%	resolve namespace conflict with unicode-math
	\addtocontents{toc}{\protect\thispagestyle{mc3-front}}				%	assign correct page style to TOC
	\checkmetadata{}										%	check metadata for completeness
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\endinput