将组织特殊文本块导出到 Latex
Export org special text block to Latex
我的问题是导出这个组织块
#+BEGIN_NOTE
some text here
#+END_NOTE
到此 Latex 代码
\begin{bclogo}[logo=\bcattention, noborder=true, barre=none]{some text here}
\end{bclogo}
有没有办法自定义如何在 Latex 中导出此文本块?
您可以在 org-mode 中使用自定义块这样做:
+begin_bclogo
这里有一些文字
+end_bclogo
然后,使用过滤器像这样修改导出:
(defun ox-mrkup-filter-special-block (text back-end info)
(let ((text (replace-regexp-in-string "\\begin{bclogo}" "\\begin{bclogo}[logo=\\bcattention, noborder=true, barre=none]{" text)))
(replace-regexp-in-string "\\end{bclogo}" "}\\end{bclogo}" text)))
(let ((org-export-filter-special-block-functions '(ox-mrkup-filter-special-block)))
(find-file (org-export-to-file 'latex "custom.tex")))
出口到:
\begin{bclogo}[logo=\bcattention, noborder=true, barre=none]{
some text here
}\end{bclogo}
这似乎接近你想要的。我不确定你怎么能在环境中得到一具尸体。我认为您需要使用一个属性来设置 {} 中的文本,然后将文本用作正文。这可能不容易在过滤器中实现,最好在自定义导出中实现。
您可以保留 NOTE
环境并通过 latex-specific 过滤器将其替换为 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-derived 后端执行此操作,你可以将 (eq backend 'latex)
替换为 (org-export-derived-backend-p backend 'latex)
。
如果要确保块以 \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))
我可以建议改用类似的东西吗:
#+LaTeX_HEADER: \usepackage[tikz]{bclogo}
...
#+ATTR_LATEX: :options [logo=\bcattention, noborder=true, barre=none]{some title here}
#+BEGIN_bclogo
some text here
#+END_bclogo
使用 LaTeX 特殊块非常适合这里,除非你真的想使用注释。
我的问题是导出这个组织块
#+BEGIN_NOTE
some text here
#+END_NOTE
到此 Latex 代码
\begin{bclogo}[logo=\bcattention, noborder=true, barre=none]{some text here}
\end{bclogo}
有没有办法自定义如何在 Latex 中导出此文本块?
您可以在 org-mode 中使用自定义块这样做:
+begin_bclogo
这里有一些文字
+end_bclogo
然后,使用过滤器像这样修改导出:
(defun ox-mrkup-filter-special-block (text back-end info)
(let ((text (replace-regexp-in-string "\\begin{bclogo}" "\\begin{bclogo}[logo=\\bcattention, noborder=true, barre=none]{" text)))
(replace-regexp-in-string "\\end{bclogo}" "}\\end{bclogo}" text)))
(let ((org-export-filter-special-block-functions '(ox-mrkup-filter-special-block)))
(find-file (org-export-to-file 'latex "custom.tex")))
出口到:
\begin{bclogo}[logo=\bcattention, noborder=true, barre=none]{
some text here
}\end{bclogo}
这似乎接近你想要的。我不确定你怎么能在环境中得到一具尸体。我认为您需要使用一个属性来设置 {} 中的文本,然后将文本用作正文。这可能不容易在过滤器中实现,最好在自定义导出中实现。
您可以保留 NOTE
环境并通过 latex-specific 过滤器将其替换为 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-derived 后端执行此操作,你可以将 (eq backend 'latex)
替换为 (org-export-derived-backend-p backend 'latex)
。
如果要确保块以 \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))
我可以建议改用类似的东西吗:
#+LaTeX_HEADER: \usepackage[tikz]{bclogo}
...
#+ATTR_LATEX: :options [logo=\bcattention, noborder=true, barre=none]{some title here}
#+BEGIN_bclogo
some text here
#+END_bclogo
使用 LaTeX 特殊块非常适合这里,除非你真的想使用注释。