Hi All I hope it's OK to ask this here. I've implemented a Windows version of the Directory Iterator as described in "Programming in Lua" http://www.lua.org/pil/29.1.html and can call it with code like this \directlua{ require "luadir" for fname in luadir.dir("directory") do tex.print(fname) end } (luadir is an add-in DLL) where "directory" is a path and fname is the returned filename. fname can contain special characters so naturally, I am having catcode problems since I'm not using ConTeXt which provides a lot of tools to deal with catcodes etc when running directlua. I'm using a version of plain to run this. So, would anyone have time to suggest the best way to set this up so that I can run this to resolve the catcode issues --- in the directory names and the returned file names? I know that tex.print can take a catcode table number but I'm not sure how to best set it up. An example using \catcodetable 16-bit number and how to use + save the catcode table would be very welcome. Thanks in advance Graham
Hi Graham, try tex.print(-2,fname). -2 is a "safe" catcode table. If you want to make sure that in 'luadir.dir("directory")' you don't have problems with catcodes, you should move this part to a separate lua file and include that with dofile("myfile.lua"). Then there are no cat code problems while interpreting this file. Hope this helps, Patrick
Hi Patrick "try tex.print(-2,fname). -2 is a "safe" catcode table." Yes, perfect thank you :-) ---> I just slapped myself very hard... sigh, reading the manual properly would have told me that... I had been trying tex.print(fname,-2) ==> I must get some new glasses ... DOH++ Thanks again Patrick Warm wishes Graham
On 18-4-2010 10:13, Graham Douglas wrote:
Hi Patrick
"try tex.print(-2,fname). -2 is a "safe" catcode table."
Yes, perfect thank you :-)
---> I just slapped myself very hard... sigh, reading the manual properly would have told me that... I had been trying tex.print(fname,-2) ==> I must get some new glasses ... DOH++
tex.write is also quite ok for this (and faster too although no one will notice that i guess) ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
An example using \catcodetable 16-bit number and how to use + save the catcode table would be very welcome.
Before I switched completely to "nodelist based typesetting" I used a special catcode table. As I am no TeX expert at all (I always fight with catcodes), there are probably mistakes or room for improvement in the following code: \begingroup \catcode`\^= 12 \catcode`\$= 12 \catcode`\_= 12 \catcode`\{=12 \catcode`\}=12 \catcode`\%=12 \catcode`\&=12 \catcode`\~=12 \catcode`\#=12 \catcode`\¬=0 \catcode`\\=12 ¬savecatcodetable1 ¬endgroup This made all characters harmless except for ¬, the new escape character. So, this is an example, but don't take this as "the way to go". Patrick
participants (3)
-
Graham Douglas
-
Hans Hagen
-
Patrick Gundlach