\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{cis_technote.cls}[2022/04/05 CIS Technical Note]
% Based on caesar_book by Andy Thomas
% https://github.com/andythomas/TeX-sidenotes
\newif\if@ScreenGeometry\@ScreenGeometryfalse
\DeclareOption{screen}{\@ScreenGeometrytrue}
%
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{scrartcl}}
%
\ProcessOptions\relax
%
\RequirePackage{amsmath}
\RequirePackage[version=3]{mhchem}
%
\LoadClass[10pt]{scrartcl}
\RequirePackage{sidenotes}
\captionsetup{font=footnotesize, skip=4pt}
% These arrows let you clarify if a figure caption in the margin refers
% to a figure in the same margin or to one in the main text.
\DeclareCaptionJustification{uparrow}{$\uparrow$~\RaggedRight}
\DeclareCaptionJustification{leftarrow}{$\leftarrow$~\RaggedRight}
\DeclareCaptionStyle{marginfigure}{justification=raggedright, font=footnotesize}
\DeclareCaptionStyle{sidecaption}{justification=leftarrow, font=footnotesize}
\RequirePackage[maxfloats=45]{morefloats}
\RequirePackage{marginfix}
\RequirePackage{microtype}
%
% Load package with option "screen" to switch to margin-less screen-reading format
\RequirePackage{geometry}
\if@ScreenGeometry
\geometry{paperwidth=440pt, paperheight=600pt, left=20pt, top=20pt, textwidth=280pt, marginparsep=20pt, marginparwidth=100pt, textheight=540pt, footskip=30pt}
\else
\geometry{letterpaper, inner=4.5cm, textwidth=280pt, marginparsep=20pt, marginparwidth=120pt, textheight=540pt, footskip=60pt}
\fi
%
\RequirePackage[footwidth=textwithmarginpar]{scrlayer-scrpage}
\pagestyle{scrheadings}
\clearpairofpagestyles
\automark{section}
%\lofoot{\headmark}
\rofoot{\pagemark}
%
%
\newlength{\overhang}
\setlength{\overhang}{\marginparwidth}
\addtolength{\overhang}{\marginparsep}
%
\newenvironment{fullwidth}
  {\ifthenelse{\boolean{@twoside}}%
     {\begin{adjustwidth*}{}{-\overhang}}%
     {\begin{adjustwidth}{}{-\overhang}}%
  }%
  {\ifthenelse{\boolean{@twoside}}%
    {\end{adjustwidth*}}%
    {\end{adjustwidth}}%
  }%
%
\renewenvironment{titlepage}%
{%
\begin{fullwidth}\centering%
\begin{minipage}{280pt}%
\maketitle%
}%
{%
\end{minipage}%
\vspace{1cm}%
\tableofcontents%
\end{fullwidth}%
\clearpage%
}%
%
\RequirePackage{fontspec}%
\RequirePackage[math-style=ISO, bold-style=ISO]{unicode-math}% 
\mhchemoptions{textfontcommand=\addfontfeature{Numbers=Lining}}
\usepackage{fourier-otf}
%
\RequirePackage{ragged2e} % \RaggedRight works better than \raggedright
\newcommand{\marginparstyle}{\footnotesize\RaggedRight} % initialize style with start value
\long\def\@ympar#1{% redefine margin par to avoid too many macros in the document
  \@savemarbox\@marbox{\marginparstyle#1}% marginparstyle is a prefix to the marginpar text now
  \global\setbox\@currbox\copy\@marbox % the rest of the definition is taken from original LaTeX
  \@xympar}
\renewcommand*{\marginfont}{\marginparstyle}
% setup itemize and enumerate  
\RequirePackage{enumitem}
\setlist[itemize]{leftmargin=*}
%
\ExplSyntaxOn
\NewDocumentCommand \sidecite { o o m }
{ 
  \IfNoValueOrEmptyTF{#1}
  {
    \IfNoValueOrEmptyTF{#2}
    {
      \sidenote{\fullcite{#3}}
    }
    {
      \sidenote{\fullcite[#2]{#3}}
    }
  }
  {
    \IfNoValueOrEmptyTF{#2}
    {
      \sidenote{\fullcite[#1]{#3}}
    }
    {
      \sidenote{\fullcite[#1][#2]{#3}}
    }
  }
}
\ExplSyntaxOff
