joostkremers/pandoc-mode

Conversion to PDF ignores settings

Closed this issue · 9 comments

First of all: Excellent work! I really like the minor mode and its precise menus.

My problem is that converting to pdf seems to be ignoring some settings. I have added a filter, defined a template file and set some other options, but they are all ignored. Pandoc is just called with --ouput=....pdf. So how can I export to PDF with all these settings?

Another suggestion is that, when producing PDF, the function C-c / V should open the pdf file.

First of all: Excellent work! I really like the minor mode and its precise menus.

Thanks! I'm glad you find it useful.

My problem is that converting to pdf seems to be ignoring some settings. I have added a filter, defined a template file and set some other options, but they are all ignored. Pandoc is just called with --ouput=....pdf. So how can I export to PDF with all these settings?

I suspect that you opened your markdown file, made your settings and ran C-c / p? In that case you made the settings for the native output format, but pdf output uses the settings for latex output.

I admit this is quite confusing, but I've never been able to find a better way... Every output format can have its own settings, and since pdf output is obtained by outputting a LaTeX file which is then compiled to pdf, it makes sense to use the latex settings.

So what you should do is change the output format to latex and then set all options that you need. Then you can convert to pdf. If you already saved the settings that you made, then most likely all you need to do is rename the settings file (which is probably .<yourfile>.native.pandoc) to .<yourfile>.latex.pandoc.

If you save the latex settings, the next time you open the file there's no need to switch to the latex output format. If there is a latex settings file, running C-c / p loads settings from that file, regardless of the current output format.

If you usually use the same settings for conversion to pdf, you may consider creating a global settings file for the latex output format. That way you won't have to remember to create latex settings for new files, they will automatically be picked up from the global settings.

I guess what pandoc-mode could do is ask for confirmation if the user wants to convert to pdf and there is no latex settings file. And perhaps I should improve the documentation on this point.

Another suggestion is that, when producing PDF, the function C-c / V should open the pdf file.

Yes, that's something I've wanted myself as well... It's not trivial to implement, though, because people have different pdf viewers, so I won't promise anything, but I'll take another look.

Thanks for the fast reply.
Indeed, saving the settings and then renaming them to filename.org.latex.pandoc produces pdf output. But now I have a different, though related problem: my latex source generates errors, but I have no source file in the directory. So I tried to create latex output. But setting the output format to latex (to produce the file without compiling it) does not work. What is produced is -- Haskell! The native format. Is this a bug or another aspect of the pdf handling? What I want is just to produce plain latex in order to debug the latex source....

Thanks for the help, I appreciate it.

Sorry, that was my fault. Renaming the settings file was a bad idea, I didn't realise that the output format is also recorded in the settings file, so even though you renamed it to file.latex.pandoc, the output format is still native.

So either edit the settings file directly and replace "native" with "latex", or delete it and create it from scratch. In either case, it's probably best to close the source file first, just to make sure there aren't any old settings lingering around.

Works! Even though I still find it confusing: If producing the pdf does not work, I have to explicitly set the output format to latex and run pandoc again in order to produce the .latex. I would have expected the .latex lying around in the directory since it is needed to produce the pdf anyways. But that's okay. That way, the directory is kept clean. Thanks for the support.

Works!

Whew!

Even though I still find it confusing: If producing the pdf does not work, I have to explicitly set the output format to latex and run pandoc again in order to produce the .latex. I would have expected the .latex lying around in the directory since it is needed to produce the pdf anyways. But that's okay. That way, the directory is kept clean.

Yes, pandoc deletes it again after the pdf has been produced. (IIRC pandoc actually uses a temp dir). So yes, if you want the LaTeX file, you need to convert to latex, not to pdf.

pandoc-mode can make this a bit easier, though. If you only ever convert to pdf, you could simply set latex as the default output format, that way you don't have to remember switching the output format if you want to see the LaTeX file.

Alternatively, if you call pandoc-run-pandoc with a prefix argument, you are asked for the output format first. So instead of doing C-c / r to run pandoc, you can do C-c / C-u r, then type latex (tab completion works) followed by RET. That way, pandoc is called with the output format latex, but the output format for the buffer you're in is not changed.

Just realised: there is a --verbose option that you can pass to pandoc when converting to pdf. This will keep the .tex file around. In pandoc-mode it can be activated through the menu with C-c / o w V.

I turned on the --verbose option, but the .tex is not kept. Creating the pdf from the org file directly works, though. As well as converting it to latex. I'm using the latest version of pandoc-mode available at melpa.

The --verbose option was added to pandoc in version 1.14, so if you have an older version, it's not going to work. If your version of pandoc is newer, then check your latex settings (switch to latex as output format and then do C-c / S). If verbose turns up there, could you do a pandoc run and then check the contents of the *Pandoc log* buffer (C-c / L`)? It should show the exact pandoc call that was made.

Closing this ancient issue 😄