0

On the command line, I need to do the following:

pandoc --variable=subparagraph try.md -o try.pdf

How do I achieve the same with pandoc-mode?

I studied pandoc-mode, it seems that it's related to specifying options. But I tried, couldn't get it working.

Thanks,

Yu Shen
  • 2,770
  • 3
  • 33
  • 48

2 Answers2

1

I don't know much about pandoc, and even less about pandoc-mode. So here's a generic answer:

Use M-x compile to run a command (asynchronously) and get the output in a *compilation* buffer. If certain regexps are set up correctly, you get hyperlinks to warnings and errors in the compilation buffer.

You can set compile-command as a file local variable (Emacs: set compilation command per-buffer).

I use the package multi-compile to have a number of compilation command templates.

Community
  • 1
  • 1
jpkotta
  • 9,237
  • 3
  • 29
  • 34
1

General way

If you want to make a precise control, the generalised way as pointed out by @jpkotta is perhaps a way forward. That is, type M-x compile and the entire command of pandoc, including the filename of the buffer (try.md). I do not know how to set a compilation command per-buffer for a markdown file.

pandoc-mode way

However, in this specifi example (and in a vast majoriy of cases with pandoc), it would be better (easier) to use the native pandoc-mode way; that is, set up the required options first and run the conversion command every time you want. Here is the procedure, based on GNU Emacs Ver.25.3.1 and pandoc-mode Ver.20180122.108.

In pandoc-mode, you can set the environment via the pandoc-mode option panel, which is invoked by typing C-c / or M-x pandoc-main-hydra/body from the buffer you are editing (try.md in this case). Then, do as follows.

Note the following procedure is based on the command interface. Alternatively, if the tool-bar is available in your Emacs environment, the same thing should be possible via GUI by clicking Pandoc tab in the tool bar (I don't go in detail). Also, for clarity, I am assuming you return to the main menu by pressing b (maybe multiple times) after each step, though you may not have to in reality, depending how and what you do.

  1. Input format: Select it by I (Input format) and m (Markdown).
    • It seems this command exits the option panel; so you need to invoke C-c / again after this.
  2. Output format: Select it by O (Output format) and l (LaTeX). There is no PDF option here. See the author's description to find why it is LaTeX. I believe the native pandoc does so, too, internally (you can check it via pandoc --verbose option).
  3. (Optional) Output filename: Set it by o f o YOUR_OUTPUT.pdf[RET] (Options → Files → Output file). In this specific case, you can skip this, because try.pdf is the default PDF filename converted from try.md.
    • nb., if you want to cancel it, that is, to set it back to the default, type o f C-u o (from the main menu).
  4. Command-line option: To set --variable=subparagraph, type o w v subparagraph[RET] t[RET] (Options → General writer options → Variables)

    • I think "t" works in this case, though it is saved as a string rather than the true value. It would raise an error in executing the following step, if you specify nothing here.
    • nb., to cancel it (all of the variables), type o w C-u C-u v (from the main menu).
    • The manual (*info*) warns:

      they only apply to the current file and the current output format.

  5. Run: To generate a PDF, type p (or, if it is from the buffer, the sequence is C-c / p. Alternatviely, via tool bar, navigate "Pandoc" > "Creat PDF")
    • nb., again, PDF creation is exceptional; for any other runs of pandoc, it is c (Run Pandoc)

Finally, the command-search path must be correctly set so that pandoc-mode can find the commands pandoc and pdflatex (or similar). My .emacs contains the following lines:

(setq exec-path (append exec-path '("/usr/local/bin")))
(setenv "PATH" (concat (getenv "PATH") ":/Library/TeX/texbin"))

That's it. Hope it works for you.

Masa Sakano
  • 1,921
  • 20
  • 32