[NTG-context] Using \applytosplitstringwordspaced and allies

Wolfgang Schuster wolfgang.schuster.lists at gmail.com
Sat Aug 8 12:00:30 CEST 2020


Jairo A. del Rio schrieb am 08.08.2020 um 10:14:
> Hi, list! :D
> I've found \applytosplitstringwordspaced and many other commands reading 
> on the mailing list and TeX StackExchange. An issue with those is: the 
> following does not work:
> 
> \applytosplitstringwordspaced\somemacro{\input knuth}
> 
> It only works with explicit TeX "words". How to circumvent this 
> inconvenience? Thanks in advance.

You can't feed knuth.tex to the command because it contains multiple 
paragraphs but even when your file contains only a single paragraph it 
isn't perfect because the linebreak after the last line contains as 
extra word (seen in the first paragraph below).

To use \input as argument for \applytosplitstringwordspaced you need a 
few \expandafter's to ensure the file is read before the argument is 
passed to Lua. A easier method is to move everything to Lua where you 
read the file and put it in a string, afterward you can use the CLD 
mechanism to call \applytosplitstringwordspaced from Lua.

\unexpanded\def\somemacro#1{[#1]}

\starttext

\expandafter\applytosplitstringwordspaced\expandafter\somemacro\expandafter{\input 
weisman }

\blank

\startluacode

-- local ward = io.loaddata(resolvers.findfile("ward.tex"))
local ward = string.fullstrip(io.loaddata(resolvers.findfile("ward.tex")))

context.applytosplitstringwordspaced ( "\\somemacro", ward )

\stopluacode

\stoptext

Wolfgang


More information about the ntg-context mailing list