On Fri, Sep 23, 2011 at 2:59 PM, mdb <[email protected]> wrote:
> There have been a handful of questions in this group about using Latex
> & Leo and I'd like to encourage more user development in this area.
>
> So below I offer my script for creating a pdf from a latex file to
> help new users get started.
You did indeed encourage development. Rev 4536 contains a complete
rewrite of the script :-) It's in scripts.leo. A clone of the script
appears at the top level, along with an @@auto node that I used for
testing.
To test, change @@auto to @auto and save, changing the @path node as needed.
The Post Script contains the new docstring, but here are a few notes:
1. The "trick" of finding @<file> nodes, is actually quite easy with
p.isAnyAtFileNode() and p.anyAtFileNodeName().
2. Perhaps I did not emphasize this enough in the docstring: the code
does *not* "compute" the file's contents. Instead, it simply computes
the full path to the input file and the output directory, and passes
these on the pdflatex. However, the script does do a c.save before
calling pdflatex so all external files are up to date.
3. The new script is much more careful about computing file names. It
takes into account @path directives, and resolves relative paths by
making them relative to the directory containing the .leo file.
4. There are two modes of operation, determined by whether a static
file name is given. If not, the script searches for the nearest
ancestor node of the selected node (c.p.self_and_parents()).
**Important** The idea is that you will alter the dictionary returned
by get_options to meet your needs. This is easy in practice. If we
were to turn this script into an official Leo command, we would need
lots of settings to accomplish the same thing. That wouldn't be bad,
but the present way is good for experimentation.
That's about all. In some ways, the code is quite straightforward: it
just invokes pdflatex. The complications arise from the usual gory
details concerning file names and paths.
I shall be happy to make any changes that you might like.
Edward
P.S. Here is the docstring for the script:
'''A script for creating a pdf from a latex file.
There are two modes of operation, static and dynamic, determined by the contents
of **d**, the **option dictionary**, returned by get_options.
**Important**: change get_options as described below to meet your needs.
If d.get('in_fn') exists, the script operates in static mode. Otherwise, the
script operates in dynamic mode.
Static mode
===========
d.get('in_fn') must be the full path to the input file.
If d.get('out_dir') exists, it must be the full path to the output directory.
The out_dir setting is optional. If omitted, output goes to the directory
containing the input file.
Dynamic mode
============
Rather than use d.get('in_fn'), the script finds the nearest @<file> node in
c.p.self_and_parents(). This node, *whatever it is*, is assumed to contain LaTeX
text.
**Important**: if in_fn is a relative path, it is converted to an absolute path
by taking account of any ancestor @path directive. If the resulting path is
still relative, it is taken to be a path relative to the directory containing
the .leo file. Here is the actual code::
c_dir = g.os_path_dirname(c.fileName())
fn = g.os_path_join(c_dir,c.getNodePath(p),fn)
If d.get('out_dir') exists, it may be either an absolute or relative path. If it
is a relative path, it is taken to be a path relative to the path given by the
@<file> node. That is::
out_dir = g.os_path_join(g.os_path_dirname(fn),out_dir)
Other settings
==============
- exe: The full path to the pdf creation program.
'pdflatex' is part of MikTex.
- open_out: True: open the output file automatically after it is created.
- trace: True: output log messages using g.es_print.
The exe setting is a global variable. The open_out and trace settings
are arguments to the makePDF function.
To do
=====
- Add an argument to the command that would have pdflatex run without
user input.
- determine if the node held a rst file and first turn this into Latex.
- open the log file or read it into a node if there is a compiling error.
- It might be useful to have some settings in the file node that let the script
automatically basic latex packages, items and definitions for a particular
type of document (Title page, TOC, set date, use the beamer package to create
slides, etc.)
- It would be really cool to be able to render TEX to PDF in real time like
viewrendered handles HTML and ReST.
Acknowledgements
================
The original script by M.D.Boldin. Rewritten by EKR.
'''
EKR
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/leo-editor?hl=en.