shyamupa
shyamupa

Reputation: 1618

Org html export does not recognize custom latex macros

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?

Upvotes: 6

Views: 953

Answers (2)

fniessen
fniessen

Reputation: 4506

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

Upvotes: 2

artscan
artscan

Reputation: 2350

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

Upvotes: 2

Related Questions