ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* texdoc in ConTeXt standalone
@ 2018-04-04 22:43 Henri Menke
  2018-04-04 23:18 ` Hans Hagen
  0 siblings, 1 reply; 5+ messages in thread
From: Henri Menke @ 2018-04-04 22:43 UTC (permalink / raw)
  To: mailing list for ConTeXt users

[-- Attachment #1: Type: text/plain, Size: 619 bytes --]

Dear list,

I'm sure you aware of the very useful "texdoc" command line utility in TeX live
which brings up the PDF documentation for packages.  ConTeXt standalone also
comes with documentation in

    /opt/context/tex/texmf-context/doc/context

However, I find it tedious to always search for the correct subfolder to get to
the document I need.  It would be great if there was something like

    mtxrun --script doc metafun

which would open the MetaFun manual.  Similarly "mtxrun --script doc gnuplot"
would open the manual of the gnuplot module, etc.

See attached for my shitty prototype.

Cheers, Henri


[-- Attachment #2: mtx-doc.lua --]
[-- Type: text/x-lua, Size: 1980 bytes --]

if not modules then modules = { } end modules ['mtx-doc'] = {
    version   = 1.001,
    comment   = "companion to mtxrun.lua",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

-- If needed this one can be optimized for speed as well as use some existing
-- helpers. We can quit faster on max, and probably use lpeg instead of find.

local helpinfo = [[
<?xml version="1.0"?>
<application>
 <metadata>
  <entry name="name">mtx-doc</entry>
  <entry name="detail">Documentation Utility</entry>
  <entry name="version">0.1</entry>
 </metadata>
 <flags>
  <category name="basic">
   <subcategory>
    <flag name="list"><short>list all matches instead of opening the first one</short></flag>
   </subcategory>
  </category>
 </flags>
 <examples>
  <category>
   <title>Examples</title>
   <subcategory>
    <example><command>mtxrun --script doc metafun</command></example>
   </subcategory>
  </category>
 </examples>
</application>
]]

local application = logs.application {
    name     = "mtx-doc",
    banner   = "Documentation Utility 0.1",
    helpinfo = helpinfo,
}

local report = application.report

local list = environment.arguments["list"] or false
local files = environment.files and #environment.files > 0 and environment.files

if files and files[1] then
   local matches = resolvers.findfiles([[*]] .. files[1] .. [[*.pdf]])

   if not list and matches[1] then
      os.execute([[xdg-open "]] .. matches[1] .. [["]])
   else
      for i,file in pairs(matches) do
         print(i,file)
      end
      io.write("Enter number of file to view, anything else to skip: ")
      local n = io.read("*n")
      if n then
         if matches[n] then
            os.execute([[xdg-open "]] .. matches[n] .. [["]])
         else
            error("The document with number " .. n .. " does not exist")
         end
      end
   end
else
    application.help()
end

[-- Attachment #3: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
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] 5+ messages in thread

end of thread, other threads:[~2018-04-05  0:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-04 22:43 texdoc in ConTeXt standalone Henri Menke
2018-04-04 23:18 ` Hans Hagen
2018-04-04 23:28   ` Henri Menke
2018-04-04 23:45     ` Hans Hagen
2018-04-05  0:06     ` Hans Hagen

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).