Thanks for this. I've downloaded MikTeX and will play with your script asap.
> I link the script to both a button and a shortcut key and I include a
> step to open the result (a pdf file). Suggestions are welcome.
Can you put it in scripts.leo? If not, I'll do it for you.
Edward
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
Thanks for these comments.
> out-dir was not pre-created.
I would suggest honoring the following setting::
@bool create_nonexistent_directories = False
You can do so by calling::
g.makeAllNonExistentDirectories
The arguments are (theDir,c=None,force=False,verbose=True)
g.makeAllNonExistentDirectories will return None if the
create_nonexistent_directories settings is False, or if there was any
other problem creating the directories.
> MakePDF was not in the main branch version of scripts.leo
> (revision 4597).
@@button MakePDF is in scripts.leo, the node::
@thin leoScripts.txt-->Important-->@@button MakePDF
> it seems p.isAnyAtFileNode() does not recognize nodes starting with @rst. I guess that makes sense, so I will work on creating a step that translate a @rst node with ReStruct markup to a @file x.tex node
Possible, or just test p.h.startswith('@rst') in addition to the test
p.isAnyAtFileNode()
Feel free to commit any of your changes to the trunk in scripts.leo.
Edward
I'm looking to compile raw latex to pdf from Leo. I wanted to take a look at the mentioned MakePDF script, but I can't find it in the current version of Leo.