Since there has not been a response (and since I am still unhappy with the limitations of \definesynonyms) I came up with my own solution which is included in this mail. The code provides a fully automated handling of symbols. I think this might be useful for a lot of people in engineering, physics, etc.. It should be more generalized and packed into a module though.
Kind regards,
Thomas
% Document Layout
\setupcolors[state=start]
\setuppapersize[A4][A4]
% Typography
\setupwhitespace[medium]
\setupindenting[no]
\setupbodyfont[sans, 11pt]
% PDF Output Adjustments
\setupinteraction[state=start, focus=standard, style=, click=yes, color=, contrastcolor=,]
% Units
\defineunit[sunit][separator=small]
\setupunit[space=medium]
\setuphead[section][style={\bfc}, before={\bigskip}, after={}]
% Lua code to set up a database of symbols
\definedescription[SymItem][]
\startluacode
userdata = userdata or {}
userdata.listofsymbols = {} -- hash table with all symbols of the form keyword:{symbol, {unit=... , description=...}}
function userdata.addsym(keyword, symbol, option) -- parses the input and adds an entry to the hash table
keywords = utilities.parsers.settings_to_array(keyword)
symbols = utilities.parsers.settings_to_array(symbol)
options = utilities.parsers.settings_to_hash(option)
userdata.listofsymbols[keywords[1]] = {symbols[1], options}
end
function userdata.getsym(keyword) -- prints the symbol to a given keyword
context.math(userdata.listofsymbols[keyword][1])
end
function userdata.symattr(keyword, attribute) -- prints whatever attribute of the symbol (its unit, description, ...)
context(userdata.listofsymbols[keyword][2][attribute])
end
function userdata.sorttable(t,o) -- sorting algorithm: hash table gets inserted to an indexed array which then can be indexed by the iterator
local a = {}
for n in pairs(t) do
table.insert(a, n)
end
if o then
table.sort(a, function(a,b) return o(t, a, b) end)
else
table.sort(a)
end
local i = 0
local iterator = function ()
i = i + 1
return a[i], t[a[i]]
end
return iterator
end
function userdata.placelistofsymbols() -- prints the List of Symbols
greekgroup = {}
latingroup = {}
for keyword, values in next, userdata.listofsymbols do -- devides the symbol list into greek and latin letters
if values[2]["group"] == "greek" then
greekgroup[keyword] = values
elseif values[2]["group"] == "latin" then
latingroup[keyword] = values
end
end
context.setuptabulate{distance="1ex"}
context.starttabulate{"|lw(0.18\\textwidth)|lw(0.18\\textwidth)|p(0.6\\textwidth)|"}
context.NC()
context.bf() context("Symbol")
context.NC()
context.bf() context("Unit")
context.NC()
context.bf() context("Description")
context.NC()
context.FR()
context.HL()
function printlistitem(keyword, values)
context.NC()
context.startSymItem({reference="sym:"..keyword, title=values[1]})
context.math(values[1])
context.stopSymItem()
context.NC()
context(values[2]["unit"])
context.NC()
context(values[2]["description"])
context.NC()
context.MR()
end
for keyword, values in userdata.sorttable(greekgroup, function(t,a,b) return string.lower(a) < string.lower(b) end) do -- sorting algorithm uses the "<"-comparator to compare the keys a and b
printlistitem(keyword, values)
end
context.TB{"2ex"}
for keyword, values in userdata.sorttable(latingroup, function(t,a,b) return string.lower(a) < string.lower(b) end) do
printlistitem(keyword, values)
end
context.stoptabulate()
end
\stopluacode
% Create the hook to the lua functions
\def\addsym[#1][#2][#3]{\ctxlua{userdata.addsym([==[#1]==], [==[#2]==], [==[#3]==])}}
\def\getsym[#1]{\ctxlua{userdata.getsym([==[#1]==])}}
\def\symattr[#1][#2]{\ctxlua{userdata.symattr([==[#1]==], [==[#2]==])}}
% Print a symbol with \sym[keyword]. Printed as an internal link to the entry in the List of Symbols via \goto{symbol}[sym:keyword]
\def\sym[#1]{\goto{\getsym[#1]}[sym:#1]}
% Create a database containing all symbols with \addsym[keyword][symbol][options]
\def\loadsymbols{
\addsym[beta][\beta][unit={\sunit{meter per second}}, description={Mass transfer coefficient}, group={greek}]
\addsym[alpha][\alpha][unit={\sunit{watt per square meter per kelvin}}, description={Heat transfer coefficient}, group={greek}]
\addsym[c][c][unit={\sunit{kilogram per cubic meter}}, description={Concentration}, group={latin}]
\addsym[m][m][unit={\sunit{kilogram}}, description={Mass}, group={latin}]
\addsym[A][A][unit={\sunit{square meter}}, description={Phase boundary interface}, group={latin}]
\addsym[Q][Q][unit={\sunit{joule}}, description={Heat}, group={latin}]
\addsym[T][T][unit={\sunit{kelvin}}, description={Temperature}, group={latin}]
\addsym[t][t][unit={\sunit{second}}, description={Time}, group={latin}]
}
% Print the List of Symbols with \placelistofsymbols
\def\placelistofsymbols{\loadsymbols\ctxlua{userdata.placelistofsymbols()}}
\starttext
\startfrontmatter
\startsubject[title=Content]
\placecontent
\stopsubject
\startsection[title=List of Tables]
\placelistoftables
\stopsection
\startsection[title=List of Symbols]
\placelistofsymbols
\stopsection
\stopfrontmatter
\startbodymatter
\startsection[title=Symbols]
\startsubsection[title=Using the Symbols]
\placeformula
\startsubformulas
\startformula
\startalign
\NC \frac{d\sym[m]}{d\sym[t]} \NC = \sym[beta] \cdot \sym[A] \cdot \Delta \sym[c] \NR[eq:1]
\NC \frac{d\sym[Q]}{d\sym[t]} \NC = \sym[alpha] \cdot \sym[A] \cdot \Delta \sym[T] \NR[eq:2]
\stopalign
\stopformula
\stopsubformulas
This is a reference to \in{equation}{}[eq:1] where the change of \sym[m] is calculated. \sym[beta] is called \quote{\symattr[beta][description]} and its unit is \symattr[beta][unit].
\stopsubsection
\stopsection
\stopbodymatter
\stoptext
________________________________________
Von: Thomas Welter