[tex-live] texdoc in luatex (was: texdoc under windows)

Frank Küster frank at kuesterei.ch
Mon Jun 25 14:57:03 CEST 2007


Taco Hoekwater <taco at elvenkind.com> wrote:

>>> Frank Küster wrote:
>>>> b) kpse* in luatex?
[...]
>> Probably I would need the analog of kpsewhich --var-value, too:
>
> Ok, that will be included in the next snapshot (sometime this week)

Thanks, I've started working on "texdoclua".  I've not actually used
kpse.var_value yet, because I ran into a different problem:  if it needs
to unzip, texdoc creates a temporary directory and puts the file there.  

But I couldn't find a way to create a directory in lua.  There's
io.tempfile, but that gives always a file, and os.tempname, but then I'm
missing a function os.createdir.  Can anyone help me?

The current state is attached, the -l and -h options already work.

Regards, Frank
-- 
Frank Küster
Single Molecule Spectroscopy, Protein Folding @ Inst. f. Biochemie, Univ. Zürich
Debian Developer (teTeX/TeXLive)

-------------- next part --------------
#!/usr/bin/luatexlua
--[[ Written in lua by Frank Küster (2007) based on the shell script by
Thomas Esser, David Aspinall, and Simon Wilkinson.
Public domain.]]

progname = 'texdoc';
usage = '      Usage: ' .. progname ..' [-h|--help] name\
	 -h|--help\t\t Show this help\
         -l|--list\t\t List matching files, do not start a viewer.';


if not arg[1] then
   print (usage);
   return
end

if string.match (arg[1],'^-') then
   if string.match (arg[1],'-h') or string.match (arg[1],'--help') then
      print (usage);
   elseif string.match (arg[1],'-l') or string.match (arg[1],'--list') then
      mode = 'list';
      iter_arg_start = 1;
   end
else
   mode = 'view';
   iter_arg_start = 0;
end

--[[ function definitions ]]
function list_iter (t)
      local i = 0
      local n = table.getn(t)
      return function ()
               i = i + 1
               if i <= n then return t[i] end
             end
   end
function list_iter_arg (t,start)
      local i = start
      local n = table.getn(t)
      return function ()
               i = i + 1
               if i <= n then return t[i] end
             end
   end

--[[ initialize kpathsea ]]
kpse.set_program_name("texdoc")

-- [[ initialize some variables ]]
verbose = false;
nodoc_pattern = [=[\.tfm|\.afm|\.enc|\.pfb|\.pfa|\.pfm|\.vf|\.fd|\.ttf|\.htf|\.mf|\.otf|\.[[:digit:]]*pk]=];
extlist = {'.dvi', '.dvi.gz', '.dvi.bz2', '.pdf', '.pdf.gz', '.pdf.bz2', '.ps', '.ps.gz', '.ps.bz2', '.txt', '.txt.gz', '.txt.bz2', '.html'};
texdoc_unzip = { gz = "gzip -d -c", bz2 = "bzip2 -d -c"};

found = false;

for docname in list_iter_arg (arg,iter_arg_start) do
   for ext in list_iter(extlist) do
      filename = kpse.find_file(docname .. ext , "TeX system documentation")
      if  filename then
	 found = "true"

	 if string.match (mode, 'list') then
	    print(filename);
	 else
	    -- mode should be view
	    dirname  = string.match(filename,'.*/');
	    -- is unzipping needed?
	    zipext = string.match(ext,'%..*%.(.*)');
	    if zipext then
	       unzip_command = texdoc_unzip[zipext];
	       viewext = string.match(ext,'%.(.*)%..*$');
	       print ("found " .. viewext);

	       -- uncompress only once per file, in case it is given more
	       -- than once
	       -- TODO: to be done

	       tmpdir = os.tmpname;
	       

	    else
	       print "unzipped";
	    end

	 end
      end
   end      
end




More information about the tex-live mailing list