ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* List of Symbols/Abbreviations/Glosses with more then two entries
@ 2019-06-12 15:37 Thomas Welter
  2019-10-11 18:20 ` Thomas Welter
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Welter @ 2019-06-12 15:37 UTC (permalink / raw)
  To: ntg-context

The synonym "sym" defined by \definesynonyms[sym][syms][\symdesc] can take 2 entries by default:

\sym[<RefName>]{<ShortName>}{<LongName>}

For theses and whitepapers in the natural sciences and in engineering it is needed to introduce another entry for the unit:

\sym[<RefName>]{<ShortName>}{<Unit>}{<LongName>} (<-- This does of course not compile, take it as a feature request)

e.g. 

\sym[Salpha]{\alpha\ }{$[W~m^{-2}~K^{-1}]$}{Heat Transfer Coefficient}

where 

\sym[Salpha]{\alpha\ }{$[W~m^{-2}~K^{-1}]$ Heat Transfer Coefficient}

cannot be a good workaround since \symdesc{Salpha} should not include the unit. And of course I want the unit entry to be in a separate column when calling \placelistofsynonyms[sym]

In LaTeX I accomplished this with glossaries and glossary-mcols. Is there some neat trick to get this behaviour "the ConTeXt way" (maybe with some Lua + *.aux)? 

The next step would be to define the table headers of the list of symbols such as "Symbol \NC Unit \NC Description"...

Thanks in advance and kind regards,

Thomas
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: List of Symbols/Abbreviations/Glosses with more then two entries
  2019-06-12 15:37 List of Symbols/Abbreviations/Glosses with more then two entries Thomas Welter
@ 2019-10-11 18:20 ` Thomas Welter
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Welter @ 2019-10-11 18:20 UTC (permalink / raw)
  To: ntg-context

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 <welter.thomas@outlook.de>
Gesendet: Mittwoch, 12. Juni 2019 17:37
An: ntg-context@ntg.nl
Betreff: List of Symbols/Abbreviations/Glosses with more then two entries

The synonym "sym" defined by \definesynonyms[sym][syms][\symdesc] can take 2 entries by default:

\sym[<RefName>]{<ShortName>}{<LongName>}

For theses and whitepapers in the natural sciences and in engineering it is needed to introduce another entry for the unit:

\sym[<RefName>]{<ShortName>}{<Unit>}{<LongName>} (<-- This does of course not compile, take it as a feature request)

e.g.

\sym[Salpha]{\alpha\ }{$[W~m^{-2}~K^{-1}]$}{Heat Transfer Coefficient}

where

\sym[Salpha]{\alpha\ }{$[W~m^{-2}~K^{-1}]$ Heat Transfer Coefficient}

cannot be a good workaround since \symdesc{Salpha} should not include the unit. And of course I want the unit entry to be in a separate column when calling \placelistofsynonyms[sym]

In LaTeX I accomplished this with glossaries and glossary-mcols. Is there some neat trick to get this behaviour "the ConTeXt way" (maybe with some Lua + *.aux)?

The next step would be to define the table headers of the list of symbols such as "Symbol \NC Unit \NC Description"...

Thanks in advance and kind regards,

Thomas
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-11 18:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-12 15:37 List of Symbols/Abbreviations/Glosses with more then two entries Thomas Welter
2019-10-11 18:20 ` Thomas Welter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).