Brett on 31 May, 2018 12:38 PM
Connor, sincerely sorry for the delayed reply. I looked at this and realized there was a lot to figure out here and put it off a bit, then somehow the todo item I added disappeared and it slipped through the cracks.
Found it in my review, will add it back to the list to dig into this week.
Brett on 11 Jun, 2018 03:07 PM
Sorry again for the delay. I recently (v2.5.18) made a change to the custom processor JSON handler that may help with the issue passing "pdf" to the custom processor as an argument. Let me know if you see any difference when using the same settings you have now.
First, that per document setting line appears at the top of the document, even when running the default Marked processor.
If you're using the GFM processor, it doesn't recognize metadata and just passes it through. Marked will recognize it if you wrap it in HTML comments and that will hide it from the output.
custom preprocessor: true
Alternatively, under Advanced prefs you can check "Strip MMD Metadata." Preprocessors are run prior to the stripping, so the Custom Processor: line would still be read, but removed from the final output.
In addition, if a custom processor is enabled in settings (in addition to the preprocessor), even if it is not enabled for this document, after rendering the document a second time (put the above JSON line in the document, save, then refresh Marked again to force an additional render), the Custom Processor is enabled, and will not disable unless you either disable it globally in the Preferences or change the line in the document. I believe this is a bug on your end, though I'm not entirely sure.
If custom processor is set to true in the metadata, it will always enable the custom processor, there's no UI override, you need to change the setting in the metadata.
The modification to pass a parameter works fine (other than revealing the bug above), but for whatever reason, the script does not execute pandoc to render a PDF via LaTeX. Running the pandoc command directly works, as does calling the script manually (with the paths hardcoded since the Marked environment variables wouldn't exist). Any ideas why pandoc is happy to build me a PDF when I ask it directly, and happy to build a docx when called via the Preprocessor script, but unwilling to generate a PDF via preprocessor? Note that it does not fail or throw an error (that I can see), it just never generates a file.
I have not had a chance to test your script yet, but I would recommend using a full path to pandoc, e.g. /Users/connor/anaconda3/bin/pandoc instead of the tilde shortcut. I also wonder if there's any environment setup loaded in your shell that Marked might be missing when it shells out. I'm not sure what Anaconda does, but if it loads a specific environment, keep in mind that it won't be available to the non-user shell that Marked executes the script in.
You might also want to suppress any output from the pandoc comand with:
(The HTML tags will make sure you see the full output in the preview window.)
If all that looks good, let me know and I'll dig in and try some local testing. You might also look at using the tee command, though I doubt it would solve the current issues. It would only be useful if you wanted to output the pandoc results to HTML (to Marked) and PDF at the same time.
Okay, I updated to the latest Version 2.5.18 (952). I got some interesting results.
Without enclosing Custom Preprocessor: [true, "pdf"] in an HTML comment, both the MMD and GFM processors include that text at the top of the rendering. When I then wrap it in a comment, the GFM processor does not display it, but the MMD processor still does. Checking the "Strip MMD3 Metadata headers" has no effect for the GFM processor, but for the MMD processor, when the metadata line is wrapped in an HTML comment, it reformats but still displays the text ("Custom Preprocessor" becomes "custompreprocessor"). Not sure what to make of all this.
Re: the UI override, that isn't quite the issue. The issue is I'm enabling the PREprocessor via metadata, which is also force enabling the custom PROCESSOR. What you described is the expected behavior, but I'm getting BOTH the preprocessor and custom processor enabled when the metadata have only enabled the preprocessor.
Re: the script, I reviewed the changes you suggested, to no avail. I removed the tilde shortcut from the pandoc path. I also switched to the plain-jane installation of pandoc on my machine, /usr/local/bin/pandoc, instead of the one brought in by anaconda. Not sure if that will handle any environment variables or other issues introduced by anaconda, but I gave it a shot. I also suppressed output with &> /dev/null (I presumed 2&> was a typo), and added a return 0 at the end of the function. The function is calling pandoc correctly as far as I can tell from the echo. None of the above solved the problem when trying to generate a PDF, though creation of a .docx file continues to work (except when I tried 2&> before realizing it should be &>).
Is it possible that Marked's non-user shell environment does not have access to LaTeX that is called by pandoc, or something like that?
Brett on 12 Jun, 2018 09:03 PM
Ok, this is a lot going wrong. I don't have time in the immediate future
to dig into this as higher priority than a couple of other issues, but
I'm making notes to tackle as soon as I can free up the space to do so.
Is any of this immediate high priority/showstopper in your workflow?