\def\descwidth{0.3\textwidth}
\def\eqwidth{0.6\textwidth}

\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\textwidth}
\def\distleftwidth{0.45\textwidth}

% 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         = "f:math:pt:pdf",
                pmf         = "f:math:pt:pmf",
                cdf         = "f:math:pt:cdf",
                mean        = "f:math:pt:mean",
                variance    = "f:math:pt:variance",
                median      = "f: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
    \begin{minipage}{\distrightwidth}
        \begingroup
            \setlength{\tabcolsep}{0.9em}  % horizontal
            \renewcommand{\arraystretch}{2}  % vertical
            \begin{tabular}{|l|>{$\displaystyle}c<{$}|}
            \hline
}{
            \end{tabular}
        \endgroup
    \end{minipage}
}

% 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 = "\luaescapestring{##1}", value = [[\detokenize{##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 = "\luaescapestring{##1}", value = "\\gt{" .. table_name .. ":\luaescapestring{##1}}"})
        }
    }
}{
    % \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
                    tex.print("\\GT{" .. kv.key .. "} & " .. kv.value .. "\\\\")
                end
            }
            \hline
            \end{tabularx}
        \endgroup
    \end{minipage}
}
