2

I am using Pandoc to convert LaTeX files to HTML files. Since these LaTeX files are mathematical documents, they contain theorem-like environments using amsthm. In the output HTML files these environments are missing.

More precisely, the contents of the environments are there but e.g. the word "Theorem" and the theorem number are missing.

Is there a way to automatically convert these environments as well?

Edit: Please find below a MWE:

\documentclass{scrartcl}
\usepackage{amsthm}

\newtheorem{theorem}{Theorem}

\begin{document}
  \begin{theorem}
    There is no largest prime number.
  \end{theorem}
\end{document}

which is compiled by pdflatex to (which is the desired output) enter image description here

Using pandoc with the command

pandoc MWE_pandoc.tex -f latex -s --mathjax -o MWE_pandoc.html

this generates the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <meta http-equiv="Content-Style-Type" content="text/css" />
   <meta name="generator" content="pandoc" />
   <title></title>
   <style type="text/css">code{white-space: pre;}</style>
 </head>
 <body>
   <p>There is no largest prime number.</p>
 </body>

which is (correctly) rendered to:

enter image description here

The pandoc version I used is pandoc 1.16.0.2

  • Could you provide a MWE ? A document sample in tex format, and maybe also what command you use, what version of pandoc, a screenshot of the output, or the expected output ? – Clément Apr 11 '17 at 14:43
  • 1
    Is using htlatex instead of pandoc an option? Something like htlatex MWE_pandoc.tex "xhtml, mathml, charset=utf-8" " -cunihtf -utf8" might do the job (at least, something like "Theorem 1" is written) – Clément Apr 11 '17 at 14:54
  • 1
    Actually, there has been some worked toward supporting amsmath in pandoc, cf. github.com/jgm/pandoc/issues/1608 and github.com/ickc/pandoc-amsthm and ickc.github.io/pandoc-amsthm, but it looks like it is only from markdown to latex and html, not from latex to html – Clément Apr 11 '17 at 15:00
  • @Clément: Thank you! htlatex might indeed be an option. – Christian Apr 11 '17 at 15:01
3

Your MWE_pandoc.tex document, when processed with tex4ht, using

 make4ht -u MWE_pandoc.tex "html5,mathml"

(see this page for other options) gives:

<?xml version="1.0" encoding="utf-8" ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" 
"http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd" > 
<html xmlns="http://www.w3.org/1999/xhtml"  
> 
<head><title></title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" /> 
<meta name="originator" content="TeX4ht (http://www.tug.org/tex4ht/)" /> 
<!-- xhtml,html5,mathml,charset=utf-8,html --> 
<meta name="src" content="MWE_pandoc.tex" /> 
<link rel="stylesheet" type="text/css" href="MWE_pandoc.css" /> 
</head><body 
>
  <div class="newtheorem">
<!--l. 7--><p class="noindent" ><span class="head">
<a 
 id="x1-2r1"></a>
<span 
class="cmbx-10x-x-109">Theorem 1.</span>  </span><span 
class="cmti-10x-x-109">There is no largest prime number.</span>
</p>
  </div>

</body></html> 

which is rendered as

enter image description here

As a side note, I find pandoc more flexible to use, so if I were you, I would watch this topic on github, to see if a reliable interface amsmath / pandoc sees the day. But that's probably just a matter of personal taste…

  • tex4ht supports html5 in fact, but not by default. You can try html5 option. – michal.h21 Apr 11 '17 at 15:24
  • and command used to compile the example can be simplified to make4ht -u MWE_pandoc.tex "html5,mathml" – michal.h21 Apr 11 '17 at 15:26
  • 1
    when used with htlatex, html5 can be requested like this: htlatex filename.tex "xhtml,html5". The docs haven't been updated yet, unfortunately. – michal.h21 Apr 11 '17 at 15:29
  • 1
    the code of tex4ht is updated regularly, but the fixes goes directly to TeX Live, not to CTAN, so the updates aren't visible at the first sight. This is quite unfortunate, but there are some issues which prevents us from CTAN update. – michal.h21 Apr 11 '17 at 15:45
  • 1
    @Clément Thank you for your answer. I will look into tex4ht. In case someone knows a pandoc solution I will wait a little bit before I accept the answer. – Christian Apr 11 '17 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.