\ProvidesPackage{mqquantity}
\RequirePackage{mqlua}
\RequirePackage{etoolbox}

\directLuaAux{
    quantities = quantities or {}
}

% [1]: label to point to
% 2: key - must expand to a valid lua string!
% 3: symbol
% 4: units
% 5: comment key to translation
\newcommand{\quantity@new}[5][\relax]{%
    \directLuaAux{
        quantities["#2"] = {} 
        quantities["#2"]["symbol"]  = [[\detokenize{#3}]]
        quantities["#2"]["units"]   = [[\detokenize{#4}]]
        quantities["#2"]["comment"] = [[\detokenize{#5}]]
    }
    \ifstrempty{#1}{}{
        \directLuaAuxExpand{
            quantities["#2"]["linkto"]  = [[#1]] %-- fqname required for getting the translation key
        }
    }
}

% 1: key
\newcommand\quantity@print[1]{
    \begingroup % for label
        Symbol: $\luavar{quantities["#1"]["symbol"]}$
        \hfill Unit: $\directlua{split_and_print_units(quantities["#1"]["units"])}$ %
        % label it only once
        \directlua{ 
            if quantities["#1"]["labeled"] == nil then
                quantities["#1"]["labeled"] = true
                tex.print("\\label{qty:#1}")
            end
        }%
    \endgroup%
}
