asciidoctor / kramdown-asciidoc

A kramdown extension for converting Markdown documents to AsciiDoc.
Other
207 stars 19 forks source link

Add converter for block LaTeX #78

Closed iyaja closed 3 years ago

iyaja commented 4 years ago

This PR adds the ability to convert block LaTeX embedded in markdown files (delimited by $$ on both left and right sides) into a passthrough block with the latexmath macro. methods.co has an example.

This also prevents kramdoc from throwing an error when it sees $$..$$ in an input markdown file. Normally, this would result in the following error:

undefined method `convert_math' for #<Kramdown::AsciiDoc::Converter:0x00007fdc8f072c18> (NoMethodError)
stallio commented 3 years ago

With the following adjustment, I was able to get this to work for inline LaTeX equations as well as blocks:

    def convert_math el, opts
      composed_text = el.value
      if el.options[:category] == :block
        mark_left = "\n[latexmath]\n++++\n"
        mark_right = "\n++++\n"
      else
        mark_left = "stem:["
        mark_right = "]"
      end
      opts[:writer].append %(#{mark_left}#{composed_text}#{mark_right})
    end

Note that the inline LaTeX must have $$ on both sides, rather than $, for this to work.

(Note also that I removed the \( and (\) delimiters because they didn't seem to be working for me.)

mojavelinux commented 3 years ago

Resolved by cdcde0a0d7436bc6175ef2fecfd67f534698b3aa with tests.