# Org-mode export to HTML filter: Replace LaTeX commands

I am trying to export org-mode file to HTML. Because I am exportig the same file also to LaTeX format, I am having in the org-mode file a few LaTeX commands, for example \LaTeX command.

For HTML export I would like to replace this command with its transcript in normal letters, simply "LaTeX." I am also using Doom Emacs and running org-mode export in --batch mode (or with -nv flag), to run emacs export commands non-interactively (and via makefile).

Using this filter function written in exportConfig.el file:

(with-eval-after-load 'ox

(defun my-latex-filter-example (text backend info)
"Replace \LaTeX with \"LaTeX\" in HTML output."
(when (org-export-derived-backend-p backend 'html)
(replace-regexp-in-string "\\\\LaTeX" "LaTeX" text)))

'my-latex-filter-example))
))


(those with-eval-after-load functions might be redundant because of -nw emacs start flag.)

But in the resulting exported HTML I still get \LaTeX sequences converted to regular strings. I also tried to add the filter function to org-export-filter-plain-tex-functions alist, but that did not work either.

How can I correctly replace simple LaTeX commands like this for org-mode export to HTML?

EDIT:

Command I am using is:

emacs main.org -nw -l exportConfig.el -f org-html-export-to-html --kill


Previously I have misspelled the emacs start flag to -nv, I have corrected that. I am using approach recommended here: Using htmlize in batch mode

Yes, I want to replace "\LaTeX" command in org-mode source with simple "LaTeX" string for HTML export.

Currently, my-latex-filter-example function doesnt replace it, so the exported HTML contains string "\LaTeX" in multiple places.

• Try the export interactively: I believe it works fine. So maybe what does not work is the batch command you are using. Please edit your question and add that command. On second thought, I don't know what you mean when you say "I still get \LaTeX sequences converted to regular strings". IIUC, you are trying to change \LaTeX to LaTeX in the HTML output - correct? – NickD Mar 22 at 1:09
• @NickD That is correct sir. I made edits to my question according to you comment. Hopefully I have clarified everything. Thank you for your help in advance. – Tomáš Kruliš Mar 22 at 7:57
• Thanks for the edits and the clarifications. – NickD Mar 22 at 8:35

A couple of problems I think:

• with-eval-after-load will do something after the indicated file is loaded, but you have to load that file somehow. Indeed, what happens is that since the files are not loaded by anybody, the with-eval-after-loads never trigger, so your filter never gets installed. I suggest a plain (require 'ox) and similar.
• -nw does not imply --batch so I suggest you change your command to do that explicitly.

The following seems to work for me (I called the file init.el, but you can call it anything you want, as long as you use the correct name in the Makefile below):

(require 'ox)
(require 'ox-html)

(defun my-latex-filter-example (text backend info)
"Replace \LaTeX with \"LaTeX\" in HTML output."
(when (org-export-derived-backend-p backend 'html)
(replace-regexp-in-string "\\\\LaTeX" "LaTeX" text)))

'my-latex-filter-example)


There is no need to load htmlize AFAICT (but if you need it, then load it with (require 'htmlize)).

The Makefile looks like this:

%.html: %.org
emacs --batch -l init.el \$< -f org-html-export-to-html --kill


and if my org file is called foo.org, I invoke the Makefile with make foo.html.

• Thank you for your answer, solved my problem. I really didnt know exactly what with-eval-after-load does. However, if I add --batch flag to emacs, as you have written, I am unable to make the export. I get error about "htmlize has to have version > 1.34" leading me to think that in --batch mode is htmlize simply not to be found (even if I explicitly require it). That might be somehow connected to fact that I am using Doom Emacs. Omiting --batch flag and using -nw flag gets me where I need, in accordance with the linked question. – Tomáš Kruliš Mar 22 at 13:37
• OK - omitting --batch is reasonable: it just makes the process depend on your init file. I'll add some comments/suggestions about what to do if you want to make the process completely independent of your init file (.e.g. to share it more easily with somebody else). – NickD Mar 22 at 18:06