On Thu, Dec 8, 2016 at 5:05 AM, Martin Monperrus <martin.monper...@gmail.com > wrote:
> > I would like to programmatically capture a subset of a latex document. > > If I add the right Leo's metadata to the document as Latex comments, I > should be able to do this with Leo, something like: > > > doc = new LeoDoc("foo.tex") > > node = doc.getNode("bar") > > print node.text > > Is it possible? Do you have a snippet showing how to use the API > accordingly? > Interesting question. First off, let's deal with your example code. *doc = new LeoDoc("foo.tex")* This could mean a number of different things. You might be wanting to create a new Leo outline, a new @file node, or just a new node. You can do each by hand, from with an existing Leo outline, or programmatically, using Leo's API. new outline: search for "def new" to see how Leo's creates outlines. new @file node (or new node): p = c.p # or p = c.lastTopLevel() p = p.insertAfter() p.h = "@file foo.txt" # or p.h = "@file %s" % (the_file_name) *node = doc.getNode("bar")* Assuming the script is in the outline containing a node whose headline is "bar": p = g.findNodeAnywhere(c, 'bar') Otherwise, scripts can search in outlines in other tabs: for c in g.app.commanders(): p = g.findNodeAnywhere(c, 'bar') if p: # You've found the proper commander, and the proper node. *print node.text* print(node.b) # prints the body of node. Python 3 compatible ;-) print(node.h) # prints the headline of node. *Other considerations*> If I add the right Leo's metadata to the document as Latex comments, I should be able to do this with Leo, something like: Once you have created an outline, attaching "metadata" to any node is easy using uA's, discussed here <http://leoeditor.com/customizing.html#adding-extensible-attributes-to-nodes-and-leo-files> . Leo does support tex syntax coloring: @language tex. Leo doesn't yet have a latex importer, nor direct support for @file x.tex. However, it might be possible to read and write TeX files from Leo using @comment or @delims <http://leoeditor.com/directives.html#part-4-dangerous-directives>. These directives are dangerous, but might be useful. HTH. I'm not sure I've actually answered your questions. Please feel free to ask more. Edward -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+unsubscr...@googlegroups.com. To post to this group, send email to leo-editor@googlegroups.com. Visit this group at https://groups.google.com/group/leo-editor. For more options, visit https://groups.google.com/d/optout.