【问题标题】:Automating org -> Rnw -> tex -> pdf自动化 org -> Rnw -> tex -> pdf
【发布时间】:2014-08-14 19:00:49
【问题描述】:

我正在尝试通过 knitr 自动处理 org-mode 文件,最后是 pdf。为此,我使用来自 https://github.com/chasberry/orgmode-accessories 的 ox-ravel.el。基本上我想要 org-mode 导出中的另一个条目,它允许我 C-c C-e l q 运行 org-ravel-latex-noweb-pdf-dispatch:

(org-export-define-derived-backend 'latex-noweb 'latex
  :translate-alist '((src-block . org-ravel-src-block)
                    (inline-src-block . org-ravel-inline-src-block))
  :menu-entry
  '(?l 1
      ((?q "As KnitR PDF" org-ravel-latex-noweb-pdf-dispatch))))

这似乎删除了 ox-ravel 中类似派生后端的当前条目:

(org-export-define-derived-backend 'latex-noweb 'latex
  :translate-alist '((src-block . org-ravel-src-block)
                    (inline-src-block . org-ravel-inline-src-block))
  :menu-entry
  '(?l 1
      ((?r "As Rnw File" org-ravel-latex-noweb-dispatch))))

感谢任何使这两个条目出现的提示。现在是更棘手的部分。我希望 org-ravel-latex-noweb-pdf-dispatch 首先导出到 Rnw 文件,方法如下:

 (defun org-ravel-latex-noweb-dispatch 
  (&optional async subtreep visible-only body-only ext-plist)
"Execute menu selection. See org-export.el for meaning of ASYNC,
      SUBTREEP, VISIBLE-ONLY and BODY-ONLY."
(interactive)
(if async
    (message "No async allowed.")
  (let
      ((outfile  (org-export-output-file-name ".Rnw" subtreep)))
       (org-export-to-file 'latex-noweb 
                           outfile async subtreep visible-only 
                           body-only ext-plist))))

.Rnw 文件导出后,我需要运行 ess-swv-weave 来导出 .tex 文件。然后我想运行 org-latex-compile 以获得最终的 pdf。以下是可能相关的 org-latex-export-to-pdf 的一部分:

(defun org-latex-export-to-pdf
  (&optional async subtreep visible-only body-only ext-plist)
  "Export current buffer to LaTeX then process through to PDF."
  (interactive)
  (let ((outfile (org-export-output-file-name ".tex" subtreep)))
    (org-export-to-file 'latex outfile
      async subtreep visible-only body-only ext-plist
      (lambda (file) (org-latex-compile file)))))

任何帮助结合上述想法以使 C-c C-e l q 生成所需的 pdf 将不胜感激!

【问题讨论】:

    标签: emacs elisp org-mode knitr ess


    【解决方案1】:

    org-export-define-derived-backend 的第一个参数是新后端的名称。由于您有两个同名 'latex-noweb 的定义,所以原来的定义会被覆盖。

    因此,将您的后端重命名为latex-knitr,并创建一个函数org-ravel-latex-noweb-pdf-dispatch,复制org-ravel-latex-noweb-dispatch 的定义并进行修改。关键是org-export-to-file,它可以带一个额外的参数POST-PROCESS,你可以用它来编织.Rnw文件并编译生成的tex文件:

    (defun org-ravel-latex-noweb-pdf-dispatch 
        (&optional async subtreep visible-only body-only ext-plist)
      "Process org file through knitr. See org-export.el for meaning of 
    SUBTREEP, VISIBLE-ONLY and BODY-ONLY."
      (interactive)
      (if async
          (message "No async allowed.")
        (let ((outfile  (org-export-output-file-name ".Rnw" subtreep)))
          (org-export-to-file
              'latex-noweb 
              outfile async subtreep visible-only 
              body-only ext-plist
              (lambda (file)
                << run `ess-swv-weave' on file >>
                (let ((texfile (concat
                                (file-name-sans-extension file)
                                ".tex")))
                  (org-latex-compile texfile)))))))
    

    【讨论】:

    • 诀窍是 org-export-to-file 可以接受一个额外的参数。我在 org-export 文档中看到了这种用法,但目前似乎没有记录。也许我错过了。
    猜你喜欢
    • 1970-01-01
    • 2017-02-15
    • 1970-01-01
    • 1970-01-01
    • 2013-01-29
    • 1970-01-01
    • 2021-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多