Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Org html export does not recognize custom latex macros

Tags:

emacs

org-mode

I have a org mode file which has some custom macros like

#+LATEX_HEADER: \newcommand{\opt}[1]{{#1}^{*}}

Sometimes I need to export the same document to html, where this appears as

undefined control sequence \opt

How should I define the same macro so that html exports can see them too?

like image 395
shyamupa Avatar asked Oct 20 '22 04:10

shyamupa


2 Answers

There is incomplete solution:

#+LATEX_HEADER: \newcommand{\opt}[1]{{#1}^{*}}
#+BEGIN_HTML
\(
\newcommand{\opt}[1]{{#1}^{*}}
\)
#+END_HTML

\opt{2} - works for 'latex backend

\( \opt{2} \) - works for 'html backend

It needs a way to combine them. You have to escape macros with \( depending on backend, for example like in answer https://stackoverflow.com/a/12719168/1937596, but from that time org-mode changed API

like image 93
artscan Avatar answered Nov 03 '22 01:11

artscan


If applicable to you, you could try using Org macros in such a way:

#+MACRO: opt @@latex:\opt{$1}@@@@html:$1@@

That is {{{opt(...)}}} gets converted to:

  • \opt{...} in LaTeX
  • ... only in HTML
like image 20
fniessen Avatar answered Nov 03 '22 01:11

fniessen