msprev / panzer

pandoc + styles
BSD 3-Clause "New" or "Revised" License
159 stars 15 forks source link

Location of Temp Path #8

Closed sergiocorreia closed 9 years ago

sergiocorreia commented 9 years ago

Is there a way to change the current directory when building the PDF files? I'm on Windows and use Dropbox, so when Pandoc creates the tex2pdf.### folder , Dropbox reads the files, uploads them, then recognizes their deletion, and finally removes them from the server, which slows the process quite a bit.

On Windows the standard way is to use %TMP% when creating temporary files (which can be accesses from python with tempfile.gettempdir()

Also, on a related note: is there a way for a filter to know the initial path of the markdown file? (e.g. if I want to add tables located in ./Tables)

Thanks! Sergio

msprev commented 9 years ago

Thanks! Could you describe what you want a bit more precisely? Is this a custom postflight script building the pdf, or is it you asking pandoc to build the pdf for you by passing .pdf as the extension of the output file? If the former, you can easily modify your postflight script to move to any working directory when building the PDF, and then move back when done. This is what I did in my latexmk.py postflight script.

Also, on a related note: is there a way for a filter to know the initial path of the markdown file? (e.g. if I want to add tables located in ./Tables)

panzer passes a dictionary as a json message to the filter inside a metadata field of your document called panzer_reserved. It's easy to extract this with python. The value json_message[0]['options']['pandoc']['input'] contains a list of all input files. So a filter can know where they are. Is this where you have been looking? At the moment, these entries contain exactly the paths that were passed on the command line to panzer. A python filter can work out their absolute paths by running os.path.abspath on the entries (under the assumption that the working directory has not been changed by a script that panzer has previously run).

sergiocorreia commented 9 years ago

Thanks for the ideas!

I'm porting a custom Pandoc wrapper to Panzer. I have a filter that reads certain fenced blocks and replaces them with latex regression tables. Before I was attaching the path directly to the metadata but panzer_reserved is indeed cleaner.

About building the PDF, latexmk seems like the solution. If I understand right, then instead of outputting the PDF files directly, I'll set latex as output, then call the postflight script which moves the .tex file to %TMP%, builds the PDF, and copies the PDF and the TEX files back to the working directory.

Thanks again, Sergio

msprev commented 9 years ago

Thanks! pandoc's own pdf generation is pretty inflexible. It's better to have a postflight script process the generated .tex files with the kind of Dropbox workflow you describe. You might want to have a look at modifying my latexmk.py script above. It invokes latexmk and is designed to pair with the tmp_out and tmp_back scripts to sweep the temporary tex files out of and into a .tmp directory before/after compilation -- my motivation was that I want to keep latex's temp files around to speed up recompilation but I don't want they cluttering up my working directory.

sergiocorreia commented 9 years ago

Agree with that.. I'm trying to replicate your workflow on Windows, expect maybe a couple of PR if I encounter some OS differences :D