1

I have a Lyx document. If I do "File --> Export --> HTML" it produces an HTML, but all inline equations are converted to single text and displayed equations to images. I want to keep the latex code so then I can use Mathjax or similar in the HTML file. Is this possible?

2
  • 1
    Is it any better if you try File > Export > LyXHTML?
    – scottkosty
    Jul 22, 2021 at 1:14
  • Much better indeed. However it converts equations to the unreadable MathML code. I want to keep equations in Latex.
    – user171780
    Jul 23, 2021 at 9:26

1 Answer 1

3

Use pandoc to convert latex to HTML output.

Math rendering in HTML by default will use Unicode characters when possible, but you can use the --mathjax option to use MathJax to display embedded TeX math in HTML output, or alternatively some other, these are the list of options to math rendering:

--mathjax
--mathml 
--webtex
--katex
--gladtex

See the pandoc manual for more details.

You do not need LyX for this conversion, but for convenience you can configure to make it to do that. Pandoc is already used for Lyx at least in ODT to HTML export, with this configuration:

pandoc -s -f odt -o $$o -t latex $$i

So, I guess that you need only make a new type of conversion (in Tools, Preferences, File Handling, Converters) with some like:

pandoc -s -f latex  -o $$o  --mathjax -t html  $$i

(Disclaimer: Not tested. Use at your own risk. If this destroys your hard disk, starts the Skynet apocalypses, or worse, it does not work at all, don't look at me.)

4
  • 1
    I like this. Will require some fine tuning but I think it can do what I want. Thanks.
    – user171780
    Jul 23, 2021 at 9:30
  • 1
    When I try this solution in toy documents it works. However, when I take a real document pandoc always complains about pandoc: Cannot decode byte '\xed': Data.Text.Internal.Encoding.decodeUtf8: Invalid UTF-8 stream where the problematic byte is not always the same.
    – user171780
    Jul 23, 2021 at 12:08
  • 2
    Unfortunalety, LyX still use the actually obsolete default \usepackage[latin9]{inputenc} so a simple document with "aeíou" causes this error, but in Document>Settings>Language> Encoding you can select "utf8" and to have \usepackage[utf8]{inputenc} instead (...or you can delete the above code in latex outputs, since today inputenc is already loaded by default by the utf8 option).
    – Fran
    Jul 24, 2021 at 7:42
  • Why is not this accepted? Oct 14, 2021 at 14:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .