kill(all);

Maxima : block Formula  , 'version 1.0' ,part: '2'
peter.vlasschaert@gmail.com, 30/10/2019

v: [[H,2],[S,1], [O,4]];

formula(v):=block([],
kaa:makelist(v[i][1],i,1,length(v)),
kbb:makelist(v[i][2],i,1,length(v)),
kbb1:makelist(if  v[i][2] =1 
    then  v[i][2] : "" else  v[i][2] : v[i][2],i,1,length(v)),
kcc1:maplist(concat,kaa,kbb1),
mpp:concat(kcc1[1],kcc1[2]),
for i:3 thru length(v) do(
mpp: concat(mpp,kcc1[i])),
    return(mpp)
);           

formula(v);

m1:[[Na,2],[S,2],[O,3]];
formula(m1);

m2:[[K,1],[Mn,1],[O,4]];
formula(m2);