gpt4 book ai didi

emacs - 将组织特殊文本 block 导出到 Latex

转载 作者:行者123 更新时间:2023-12-02 04:20:51 28 4
gpt4 key购买 nike

我的问题是导出这个组织 block

#+BEGIN_NOTE
some text here
#+END_NOTE

到这个 latex 代码

\begin{bclogo}[logo=\bcattention, noborder=true, barre=none]{some text here}
\end{bclogo}

有没有办法自定义如何在 Latex 中导出此文本 block ?

最佳答案

您可以保留 NOTE 环境,并通过 latex 特定的过滤器将其替换为 bclogo(我修改了 John 的代码):

(defun my/latex-process-NOTE-blocks (text backend info)
"Filter special blocks from latex export."
(when (eq backend 'latex)
(let ((text (replace-regexp-in-string "\\\\begin{NOTE}" "\\\\begin{bclogo}[logo=\\\\bcattention, noborder=true, barre=none]{" text)))
(replace-regexp-in-string "\\\\end{NOTE}" "}\\\\end{bclogo}" text))))

(eval-after-load 'ox '(add-to-list
'org-export-filter-special-block-functions
'my/latex-process-NOTE-blocks))

如果您想对所有 Latex 派生的后端执行此操作,可以将 (eq backend 'latex) 替换为 (org-export-衍生-backend-p backend 'latex) .

如果您想确保 block 以 \begin{NOTE} 开头:

(defun string/starts-with (string prefix)
"Return t if STRING starts with prefix."
(and (string-match (rx-to-string `(: bos ,prefix) t) string) t))

(defun my/latex-process-NOTE-blocks (text backend info)
"Filter special blocks from latex export."
(when (eq backend 'latex)
(if (string/starts-with text "\\begin{NOTE}")
(let ((text (replace-regexp-in-string "\\\\begin{NOTE}" "\\\\begin{bclogo}[logo=\\\\bcattention, noborder=true, barre=none]{" text)))
(replace-regexp-in-string "\\\\end{NOTE}" "}\\\\end{bclogo}" text)))))

(eval-after-load 'ox '(add-to-list
'org-export-filter-special-block-functions
'my/latex-process-NOTE-blocks))

关于emacs - 将组织特殊文本 block 导出到 Latex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30562840/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com