\documentclass{article}

\usepackage{luacas}
\usepackage{amsmath}
\usepackage{amssymb}

\usepackage[margin=1in]{geometry}
\usepackage[shortlabels]{enumitem}

\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{positioning,calc}
\usepackage[edges]{forest}
\usepackage{minted}
\usemintedstyle{pastie}
\usepackage[hidelinks]{hyperref}
\usepackage{parskip}
\usepackage{multicol}
\usepackage[most]{tcolorbox}
    \tcbuselibrary{xparse,documentation}
\usepackage{microtype}
\usepackage{makeidx}

\usepackage[
backend=biber,
style=numeric,
]{biblatex}
\addbibresource{sources.bib}

\definecolor{rose}{RGB}{128,0,0}
\definecolor{roseyellow}{RGB}{222,205,99}
\definecolor{roseblue}{RGB}{167,188,214}
\definecolor{rosenavy}{RGB}{79,117,139}
\definecolor{roseorange}{RGB}{232,119,34}
\definecolor{rosegreen}{RGB}{61,68,30}
\definecolor{rosewhite}{RGB}{223,209,167}
\definecolor{rosebrown}{RGB}{108,87,27}
\definecolor{rosegray}{RGB}{84,88,90}

\definecolor{codegreen}{HTML}{49BE25}

\newtcolorbox{codebox}[1][sidebyside]{
    enhanced,skin=bicolor,
    #1,
    arc=1pt,
    colframe=brown,
    colback=brown!15,colbacklower=white,
    boxrule=1pt,
    notitle
}

\newtcolorbox{codehead}[1][]{
    enhanced,
    frame hidden,
    colback=rosegray!15,
    boxrule=0mm,
    leftrule=5mm,
    rightrule=5mm,
    boxsep=0mm,
    arc=0mm,
    outer arc=0mm,
    left=3mm,
    right=3mm,
    top=1mm,
    bottom=1mm,
    toptitle=1mm,
    bottomtitle=1mm,
    oversize,
    #1
}

\usepackage{varwidth}

\newtcolorbox{newcodehead}[2][]{
    enhanced,
    frame hidden,
    colback=rosegray!15,
    boxrule=0mm,
    leftrule=5mm,
    rightrule=5mm,
    boxsep=0mm,
    arc=0mm,
    outer arc=0mm,
    left=3mm,
    right=3mm,
    top=1mm,
    bottom=1mm,
    toptitle=1mm,
    bottomtitle=1mm,
    oversize,
    #1,
    fonttitle=\bfseries\ttfamily\footnotesize,
    coltitle=rosegray,
    attach boxed title to top text right,
    boxed title style={frame hidden,size=small,bottom=-1mm,
    interior style={fill=none,
    top color=white,
    bottom color=white}},
    title={#2}
}

\makeindex

\newcommand{\coderef}[2]{%
\begin{codehead}[sidebyside,segmentation hidden]%
    \mintinline{lua}{#1}%
    \tcblower%
    \begin{flushright}%
    \mintinline{lua}{#2}%
    \end{flushright}%
\end{codehead}%
}

\newcommand{\newcoderef}[3]{%
\begin{newcodehead}[sidebyside,segmentation hidden]{#3}%
    \mintinline{lua}{#1}%
    \tcblower%
    \begin{flushright}%
    \mintinline{lua}{#2}%
    \end{flushright}%
\end{newcodehead}%
}

\begin{document}
\thispagestyle{empty}
\part{Reference}
This part contains reference material for the classes and methods that incorporate the \texttt{luacas} package. Some classes are \emph{concrete} while others are \emph{abstract}. The concrete classes are essentially the objects that a user might reasonably interact with while using \texttt{luacas}. Thankfully, most of this interaction will be filtered through a rudimentary (but functional!) parser. Abstract classes exist for the purposes of inheritance.

The classes in the diagram below are color-coded according to:
\begin{itemize}
    \item (\tikz[baseline=-0.5ex]\node[text=rosenavy,fill=roseblue!40]{\ttfamily\bfseries Class};) {\color{rosenavy}\ttfamily\bfseries Class}: a (concrete) class belonging to the core module;
    \item (\tikz[baseline=-0.5ex]\node[text=rose,fill=rose!30]{\ttfamily\bfseries Class};) {\color{rose}\ttfamily\bfseries Class}: a (concrete) class belonging to the algebra module;
    \item (\tikz[baseline=-0.5ex]\node[text=roseorange,fill=roseorange!30]{\ttfamily\bfseries Class};) {\color{roseorange}\ttfamily\bfseries Class}: a (concrete) class belonging to the calculus module.
\end{itemize}
Inheritance is indicated with an arrow:

\forestset{multiple directions/.style={for tree={#1}, phantom, for relative level=1{no edge, delay={!c.content/.pgfmath=content("!u")}, before computing xy={l=0,s=0}}},
    multiple directions/.default={},
    grow subtree/.style={for tree={grow=#1}},
    grow' subtree/.style={for tree={grow'=#1}}}

\begin{center}
    \begin{forest}
        core/.style = {draw={rosenavy,thick},
            font={\ttfamily\bfseries\color{rosenavy}},
            fill = roseblue!#1},
        algebra/.style = {draw={rose,thick},
            font={\ttfamily\bfseries\color{rose}},
            fill = rose!#1},
        calculus/.style = {draw={roseorange,thick},
            font={\ttfamily\bfseries\color{roseorange}},
            fill = roseorange!#1},
        multiple directions,
        for tree = {font = \ttfamily\bfseries,
            draw,
            rounded corners=1pt,
            edge = {-stealth},
            s sep = 0.2cm}
        [Expression
            [, grow subtree = 90
                [AtomicExpression,
                    core = {0},
                    for tree = {grow=east,
                        child anchor=west,
                        node options={anchor=west}},
                        forked edges,
                        calign=last,
                        l sep = 0.5cm,
                        s sep = 0.2cm
                [SymbolExpression,
                    core={50}]
                [ConstantExpression,
                    core ={0},
                    for tree = {grow = north,
                        node options = {anchor=north}
                    }
                    [Ring,
                        algebra ={0},
                        for tree = {grow = east}
                        [EuclideanDomain,
                            algebra={0}
                            [Field,
                                algebra = {0}
                                [IntegerModN,
                                    algebra={30}]
                                [Rational,
                                    algebra={30}]
                            ]
                            [Integer,
                                algebra={30}]
                        ]
                        [PolynomialRing,
                            algebra={30}]
                    ]
                ]
            ]]
            [, grow subtree = -90
                [CompoundExpression,
                    core = {0},
                    for tree = {grow=east,
                        child anchor=west,
                        node options={anchor=west}},forked edges,
                        calign=last,
                        l sep = 0.5cm,
                        s sep = 0.2cm
                [FunctionExpression,
                    core = {40}
                    [TrigExpression,algebra={30}]
                ]
                [BinaryOperation,
                    core = {40}]
                [Equation,
                    algebra = {30}]
                [Logarithm,
                    algebra={30}]
                [FactorialExpression,
                    algebra={30}]
                [RootExpression,
                    algebra={30}]
                [SqrtExpression,
                    algebra={30}]
                [AbsExpression,
                    algebra={30}]
                [DerivativeExpression,
                    calculus={20}]
                [DiffExpression,
                    calculus={20}]
                [IntegralExpression,
                    calculus={20}]
            ]]
        ]
    \end{forest}
\end{center}
Every object in \texttt{luacas} is an expression, meaning it inherits from the {\ttfamily Expression} type (class). Since the {\ttfamily Expression} type itself has no constructor and cannot be instantiated, it it closer to an interface in Java OOP terms.\footnote{In reality, interfaces are unnecessary in Lua due to its weak typing - Lua doesn't check whether an object has a method at compile time. The {\ttfamily Expression} type is really an abstract class in Java terms.} {\ttfamily Expression}s can store any number of other expressions as sub-expressions, depending on type. This means that {\ttfamily Expression} objects are really trees. Types that inherit from {\ttfamily Expression} that can not store other expressions are called \emph{atomic expressions}, and correspond to the leaf nodes of the tree. Other expression types are \emph{compound expressions}. Thus, every {\ttfamily Expression} type inherits from one of {\ttfamily AtomicExpression} or {\ttfamily CompoundExpression}. The {\ttfamily ConstantExpresssion} interface is a subinterface to {\ttfamily AtomicExpression}. Types that inherit from {\ttfamily ConstantExpression} roughly correspond to numbers (interpreted broadly).

\end{document}