自定义组织模式导出 [英] Customizing org-mode exports

查看:134
本文介绍了自定义组织模式导出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我一直在使用组织模式来研究笔记一段时间。我喜欢我可以无缝地导出乳胶(对于我的论文)和html(对我的博客)。但是,每当使用#+ LATEX_HEADER定义具有\\\
ewcommand的宏时,这些宏都不会显示在HTML导出中。

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, whenever I define macros with \newcommand with #+LATEX_HEADER, these do not show up in the HTML export at all.

我目前通过将所有这些命令作为
(\\\
ewcommand \\\
ewcommand等)
处理在顶部,然后从tex文件手动删除(和)。

I currently handle this by putting the all these commands as (\newcommand \newcommand etc. etc.) at the top and then manually removing the "(" and ")" from the tex file.

我希望我能做的是为这些命令保留抽屉,并自定义html和latex导出组织模式以适当地处理这个抽屉。

What I wish I could do was to keep a drawer for these commands and customize html and latex export of org mode to handle this drawer appropriately.

例如,我将在组织文件中添加以下内容:

For example, I would add the following in the org file:

:LATEX_MACROS:
\newcommand{\norm}[1]{\lVert{#1}\rVert}
\newcommand{\abs}[1]{\lvert{#1}\rvert}
\newcommand{\half}{\frac{1}{2}}
:END:

导出后,这个乳胶文件逐个显示在标题部分
中, html文件作为

And after export, this shows up in the latex file verbatim in header section and in the html file as

\(
\newcommand{\norm}[1]{\lVert{#1}\rVert}
\newcommand{\abs}[1]{\lvert{#1}\rvert}
\newcommand{\half}{\frac{1}{2}}
\)


推荐答案

我想出了如何做到这一点。请注意,这可能不是最优雅的解决方案,因为它不会将乳胶部分放置在胶乳文件的开头(即在\begin {document}之外)),但它对我来说非常有用。

I figured out how to do it myself. Note that this is perhaps not the most elegant solution since it does not place the latex part in the beginning of the latex file (i.e. outside \begin{document}), but it works well enough for me.

(setq org-export-blocks
  (cons '(latexmacro org-export-blocks-latexmacro) org-export-blocks))

(defun org-export-blocks-latexmacro (body &rest headers)
  (message "exporting latex macros")
  (cond
   ((eq org-export-current-backend 'html) (concat "\\(" body "\\)"))
   ((eq org-export-current-backend 'latex) body)
   (t nil))
)

这篇关于自定义组织模式导出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆