Search code examples
emacslatexorg-mode

Export org special text block to Latex


My problem is to export this org-block

#+BEGIN_NOTE
some text here
#+END_NOTE

to this Latex code

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

Is there a way to customize how to export in Latex this block of text?


Solution

  • You can do it like this with a custom block in org-mode:

    +begin_bclogo

    some text here

    +end_bclogo

    Then, use a filter to modify the export like this:

    (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")))
    

    That exports to:

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

    This seems to get close to what you want. I am not sure how you could get a body in the environment. I think you would need to use an attribute to set the text in {} and then use the text as the body. That is probably not easy to implement in a filter, and would be better implemented in a custom export.