0

I was thinking about this question: Configuring org-export to replace LaTeX def macros

It seems like you should be able to convert latex macros in org export using an export filter. e.g., in the linked question, convert \R to \mathbb{R}. However, I can't figure out the syntax. I tried:

(require 'ox)
(defun my-latex-filter-r-macro (text backend info)
  "Replace \\R with \\mathbb{R}"
  (when (org-export-derived-backend-p backend 'html)
    (replace-regexp-in-string "\\\\R" "\\\\mathbb{R}" text)))

(add-to-list 'org-export-filter-plain-text-functions
             'my-latex-filter-r-macro)

And then exported the following org file to html:

* This is a headline
  Here I refer to \R in normal text.

However, the \R is not altered in export. I've tried different numbers of backslashes, with no success - 0, 1, 2 or 3 backslashes, and every r except for the escaped \R is converted to \mathbb{r}. With 4 or more backslashes, none of the r characters gets converted. So it looks like escaped characters are protected from export filters - is this so? Is ther anyway to pre-process escaped characters in org export?

1

The filter org-export-filter-plain-text-functions never sees \R, try to filter org-export-filter-latex-fragment-functions. For example, this works for me:

(require 'ox)
(defun my-latex-filter-r-macro (text backend info)
  "Replace \\R with \\mathbb{R}"
  (when (org-export-derived-backend-p backend 'html)
    (replace-regexp-in-string "\\\\R" "\\\\mathbb{R}" text)))

(add-to-list 'org-export-filter-latex-fragment-functions
             'my-latex-filter-r-macro)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.