On Fri, Jan 18, 2019 at 4:44 PM User 19087 <se.user19...@gmail.com> wrote: > There must be some other method (at least via luatex) to > obtain the 'x' and 'xx' sizes as workable dimensions.
I've come up with the following macro and I'd like some feedback. Will it work consistently? Any suggestions for improvement? % A '\start...\stopluacode' block inside a macro is just as bad (or worse?) to % escape as '\ctxlua' code. So create a function here for use elsewhere. % % There were multiple font sizes in the "specification" and "parameters" % tables, hopefully I picked the right one. % % It turns out that for ConTeXt there is a difference between the 10pt and % 10.0pt sizes: the former is predefined in the body font environment that % ships with ConTeXt while the latter causes ConTeXt to generate a new body % font environment. Unfortunately '\the' displays values with trailing 0s, and % so the result must be converted to a string and truncated in lua. \startluacode userdata = userdata or {} userdata.fontsize = function () local fs fs = font.getfont(font.current()).specification.size fs = tostring(fs/2^16):gsub("%.?0+$","") .. "pt" return fs end \stopluacode % In some situations the 'tx' and 'txx' sizes are ignored by ConTeXt. This % macro determines the font size that would have been used by such a command % and switches the entire body font to that size for the duration of the second % argument. The chosen size depends on the 'x' and 'xx' values of the specific % body font environment nearest in size to the current body font, though the % font itself (via definebodyfont) may override those values. \define[2]\tosize{% % Use a scratch box to prevent any typesetting. Otherwise changes to the % font size would be compounded: 'tfxx' remaining in effect after % 'switchtobodyfont'. I've also tried stop...starthiding, but that prevents % all processing of contents. \setbox\scratchbox\hbox{% #1% % Use a global lua variable rather than globally setting a scratch % register. \startluacode userdata = userdata or {} userdata.lastfontsize = userdata.fontsize() \stopluacode% }% {\switchtobodyfont[\ctxlua{context(userdata.lastfontsize)}]#2}% } Test{\tfx Test} \tosize{\tfx Unwanted}{Test{\tfx Test}} ___________________________________________________________________________________ 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 ___________________________________________________________________________________