Customizing org-mode exports

前端 未结 4 911
醉话见心
醉话见心 2021-02-01 10:07

So, I have been using org-mode for taking my research notes for some time now. I love how I can seamlessly export to both latex (for my papers) and html (for my blog). However,

4条回答
  •  情深已故
    2021-02-01 10:39

    I usually have a file with many custom definitions which I reuse for many documents and I want to use it also in my org documents.

    The following is a modification of Blout's answer, so please read his answer for more info.

    Define macro

    (defun org-dblock-write:insert-latex-macros (params)
      (let ((text)
        (file (plist-get params :file)))
        (with-temp-buffer
          (insert-file file)
          (setq text (split-string (buffer-string) "\n" t)))
        (insert (mapconcat (lambda (str) (concat "#+LATEX_HEADER: " str)) text "\n"))
        (insert "\n#+BEGIN_HTML\n\\(\n")
        (insert (mapconcat 'identity text "\n"))
        (insert "\n\\)\n#+END_HTML")))
    

    Usage

    File macros.tex:

    \newcommand\a{a}
    \def\b{b}
    \DeclareMathOperator\c{c}
    

    In org file:

    #+BEGIN: insert-latex-macros :file "macros.tex"
    #+BEGIN_HTML
    \(
          \newcommand\a{a}
          \def\b{b}
          \DeclareMathOperator\c{c}
    \)
    #+END_HTML
    #+LATEX_HEADER:       \newcommand\a{a}
    #+LATEX_HEADER:       \def\b{b}
    #+LATEX_HEADER:       \DeclareMathOperator\c{c}
    #+LATEX_HEADER: 
    #+END:
    

提交回复
热议问题