joostkremers / pandoc-mode

An Emacs minor mode for interacting with Pandoc.
https://joostkremers.github.io/pandoc-mode/
177 stars 14 forks source link

Still unable to use file with --defaults argument #112

Open carljv opened 2 years ago

carljv commented 2 years ago

Hi!

I have recently installed pandoc-mode and am still encountering the issue in #106. I have set a defaults yaml file via the file options, then run the Convert to PDF command.

The log shows:

Calling pandoc with:

pandoc --read=markdown --write=latex --output=/Users/carljv/Desktop/tex-test//test.pdf

test.md: pandoc finished successfully

showing the defaults file is being ignored.

Here is the value of pandoc--cli-options, which contains default

pandoc--cli-options is a variable defined in ‘pandoc-mode-utils.el’.
Its value is
(mathml mathjax gladtex webtex katex katex-stylesheet latexmathml jsmath mimetex citeproc csl citation-abbreviations natbib biblatex epub-stylesheet epub-cover-image epub-metadata epub-chapter-level epub-subdirectory chapters no-tex-ligatures listings latex-engine self-contained html-q-tags ascii number-offset section-divs email-obfuscation id-prefix title-prefix top-level-division reference-location reference-links markdown-headings number-sections incremental slide-level reference-doc pdf-engine ipynb-output atx-headers reference-odt reference-docx standalone template dpi eol wrap no-wrap columns table-of-contents toc-depth no-highlight highlight-style syntax-definition include-in-header include-before-body include-after-body verbose strip-comments no-check-certificate old-dashes shift-heading-level-by indented-code-classes default-image-extension normalize preserve-tabs tab-stop track-changes strip-empty-paragraphs abbreviations base-header-level parse-raw smart defaults)

Let me know if any other information would be helpful. Thanks!

joostkremers commented 2 years ago

What version exactly do you have installed? If you installed from Melpa Stable, you wouldn't have the fix. I can tag the current version so that it's propagated to Melpa Stable.

carljv commented 2 years ago

I'm installing from https://melpa.org/packages/ and have version 20211208.2229. Is there a better place to install from to get the new fix, or should I wait for you to propagate the fix to stable?

Thanks for looking into it!

joostkremers commented 2 years ago

Nope, that's the latest version, so things should work. Still, the command in the log buffer does not contain a --defaults switch, so something is wrong.

The next thing to look at is to make sure that you added the defaults option to the correct output format. Setting in pandoc-mode depend on the output format (i.e., if you change output formats, you get different settings). If you change some setting and then change the output format, the setting you just changed is reverted to its default value (or whatever value you have configured in a settings file).

carljv commented 2 years ago

I'm only outputting to PDF (choosing latex output when asked—though my defaults file specifies to use xelatex as the pdf-engine). pandoc-mode is saying the output format is "native", and if I save the settings to a file, and look at .my-doc.md.native.pandoc, I see the default file specified correctly: (defaults . "pandoc-latex-defaults.yaml")

I'm still seeing this in the log after I convert to pdf:

==================================================
Wed Feb  9 09:53:42 2022

Calling pandoc with:

pandoc --read=markdown --write=latex --output=/Users/carljv/my-doc//my-doc.pdf

my-doc.md: pandoc finished successfully

The PDF renders, but does not have any of the settings specified in my defaults file, as you'd expect. Hope this is helpful.

joostkremers commented 2 years ago

Yeah, unfortunately that's another complication... If you convert to pdf, pandoc-mode will use the settings for the pdf-engine that you choose, so in your case it uses settings for latex. If pandoc-mode cannot find a settings file for latex, it will only set the input and output formats and the output file, which seems to be what is happening in your case.

So what you need to do is change the output format to latex, set the defaults option, and save the settings file. Then you can convert to pdf using the defaults file.

The next time you open the file, you don't need to switch to latex as output format, because when you create a pdf, pandoc-mode checks if there's a settings file for latex even if the output format is set to e.g., native.

The way pandoc-mode handles settings files is unfortunately not very straightforward. I have often thought about a better way, or at least a better user experience, but I haven't been able to come up with something. I'm open to suggestions...

carljv commented 2 years ago

Ah ok — that did the trick! Thank you! I was a bit confused about how to set the output format, because the actual output format was pdf, not tex (i.e., how I would set the -o option for pandoc).

I don't have any ideas about how to better handle this re. settings file. I think my main confusion was ambiguity about what "output format" meant, which is maybe just a documentation/labeling issue.

But no worries — I appreciate your help, and am finding pandoc-mode super handy. Thanks for all your work!

joostkremers commented 2 years ago

Ah ok — that did the trick! Thank you! I was a bit confused about how to set the output format, because the actual output format was pdf, not tex (i.e., how I would set the -o option for pandoc).

Well, the -o option specifies the output file, not the output format. I think if you specify a pdf file as output file, the output format (-t or -w) is ignored by Pandoc, but it's used by pandoc-mode to determine the settings to be used.

I just noticed that Pandoc's user manual lists pdf as output format as well, so it seems you can specify -o pdf. If so, I should add pdf as output format to pandoc-mode. That might make things a bit clearer for use cases such as yours.

But no worries — I appreciate your help, and am finding pandoc-mode super handy. Thanks for all your work!

I'm glad you find it useful!