
\newcommand\separateEntries{
    \vspace{0.5\baselineskip}
    \textcolor{fg3}{\hrule}
    \vspace{0.5\baselineskip}
}



% Custon environment with table of contents, requires etoolbox?
% Define a custom list
\newcommand{\listofmyenv}{%
    \section*{List of My Environments}%
    \addcontentsline{toc}{section}{List of My Environments}%
    \par\noindent\hrule\par\vspace{0.5\baselineskip}\@starttoc{myenv}%
}
\newcommand{\addmyenv}[1]{\addcontentsline{myenv}{subsection}{\protect\numberline{\themyenv}#1}}
% Define the custom environment
\newcounter{myenv}
\newenvironment{myenv}[1]{%
  \refstepcounter{myenv}%
  \addmyenv{#1}%
  \noindent\textbf{My Environment \themyenv: #1}\par%
}{\par\vspace{0.5\baselineskip}}




%
% DISTRIBUTION
%
\def\distrightwidth{0.45}
\def\distleftwidth{0.45}

% Table for distributions
% create entries for parameters using \disteq
\newenvironment{distribution}{
    % 1: param name (translation key)
    % 2: math
    \newcommand{\disteq}[2]{
        % add links to some names
        \directlua{
            local cases = {
                pdf         = "math:pt:pdf",
                pmf         = "math:pt:pmf",
                cdf         = "math:pt:cdf",
                mean        = "math:pt:mean",
                variance    = "math:pt:variance",
                median      = "math:pt:median",
            }
            if cases["\luaescapestring{##1}"] \string~= nil then
                tex.sprint("\\hyperref["..cases["\luaescapestring{##1}"].."]{\\GT{##1}}")
            else
                tex.sprint("\\GT{##1}")
            end
        }
        & ##2 \\ \hline
    }
    \hfill
    \begingroup
        \setlength{\tabcolsep}{0.9em}  % horizontal
        \renewcommand{\arraystretch}{2}  % vertical
        \begin{tabular}{|l|>{$\displaystyle}c<{$}|}
        \hline
}{
        \end{tabular}
    \endgroup
}

% A 2 column table in a minipage
% create entries for parameters using \entry
% 1: minipage width
% 2: key of the table
\newenvironment{minipagetable}[2][0.5\textwidth]{
    % save real fq name
    \edef\tmpFqname{\fqname}
    \edef\tmpMinipagetableWidth{#1}
    \edef\tmpMinipagetableName{#2}
    \directlua{
        table_name = "\luaescapestring{#2}"
        entries = {}
    }

    % Normal entry
    % 1: field name (translation key)
    % 2: entry text
    \newcommand{\entry}[2]{
        \directlua{
            table.insert(entries, {key = \luastring{##1}, value = \luastringN{##2}})
        }
    }
    % Translation entry
    % 1: field name (translation key)
    % 2: translation define statements (field content)
    \newcommand{\tentry}[2]{
        % temporarily set fqname so that the translation commands dont need an explicit key
        \edef\fqname{\tmpFqname:#2:##1}
        ##2
        \edef\fqname{\tmpFqname}
        \directlua{
            table.insert(entries, {key = \luastring{##1}, value = "\\gt{" .. table_name .. ":\luaescapestring{##1}}"})
        }
    }
    % Entry with raw field, for example a reference
    % 1: field text
    % 2: entry text
    \newcommand{\rentry}[2]{
        \directlua{
            table.insert(entries, {key = \luastring{##1}, value = \luastringN{##2}, raw = true})
        }
    }
}{
    % \hfill
    % reset the fqname
    \edef\fqname{\tmpFqname}
    \begin{minipage}{\tmpMinipagetableWidth}
        \begingroup
            \setlength{\tabcolsep}{0.9em}  % horizontal
            \renewcommand{\arraystretch}{2}  % vertical
            \begin{tabularx}{\textwidth}{|l|X|}
            \hline
            \directlua{
                for _, kv in ipairs(entries) do
                    if kv.raw == true then 
                        tex.print(kv.key .. " & " .. kv.value .. "\\\\")
                    else
                        tex.print("\\GT{" .. kv.key .. "} & " .. kv.value .. "\\\\")
                    end
                end
            }
            \hline
            \end{tabularx}
        \endgroup
    \end{minipage}
}
