3

I'm building a blog using Jekyll and hosting on Github Pages. I have a bunch of LaTeX documents that I'd like to upload as blog posts, but they contain a good deal of formatting that I'd have to go in and edit to make compatible with KramDown. For example, if I have \newline or \textit in LaTeX, I'd have to manually change those to \\\ and \*text\* in KramDown. I saw that KramDown has a built-in converter that will format markup into a Latex PDF output, but are there any tools in existence that will do the opposite?

  • Welcome to LaTeX! Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Regarding your question, you might want to have a look at Pandoc which will convert between a lot of formats, including MarkDown and LaTeX. – JP-Ellis Feb 12 '16 at 4:35
  • 2
    if you have existing LaTeX documents then it's nonsense to convert them to Markdown. You can convert them directly to HTML using tex4ht. You only need to replace HTML header with YAML header in these HTMLs. jekyll4ht can be used to automatize this. – michal.h21 Feb 12 '16 at 7:09
  • 1
    LaTeX to *down is harder than you might think (and no lightweight markup language is as expressive as *TeX). If the goal is to get to HTML, then use tex4ht to convert your LaTeX files. – jon Feb 12 '16 at 7:10
  • Thanks, I'll check out text4ht as well. – Danny Feb 12 '16 at 22:28
4

As jekyll and majority of other static site generators support HTML files with YAML frontmatter, it seems as better approach to me to convert LaTeX to HTML and modify it to the needed form. For example, tex4ht can be configured to produce the YAML frontmatter directly, and we can use make4ht library to create helper script, which will copy the HTML, CSS and image files to correct locations. The project is named jekyll4ht.

It can be used as following:

Create following structure

pathtoblog
  jekyllsite
     _posts
     img
     css
  texfiles
     .jekyll4ht
     firstpost
       firstpost.tex

your generated files will be copied to the jekyllsite, which must be configured in .jekyll4ht configuration file. It's minimal contents should be:

base="pathtoblog/jekyllsite/"

You can then create documents in texfiles directory, and publish them with

jekyll4ht -m publish filename.tex

when they are done. Note that this doesn't rebuild your site, it must be done manually using jekyll serve from jekyllsite.

  • Thanks, I will definitely try this! I like that it's jekyll specific. – Danny Feb 23 '16 at 5:34
4

@michal.h21 has provided a sensible approach that doesn't require converting from tex -> markdown. If you do want to convert a tex file to markdown/kramdown, pandoc can do that. For example:

pandoc source.tex -o source.md

Some caveats to keep in mind:

  1. Markdown doesn't support all the formatting provided by LaTeX, so you may lose something in the conversion
  2. Kramdown is a superset of Markdown. the PHP-extra extensions are supported by pandoc, but there may be other things that are not.

Some of the commenters have indicated that this conversion is silly. However, if you have a site that mixes articles typeset in LaTeX and Markdown, the resulting blog posts may be inconsistent. That is, the ones produced via tex4ht may have different formatting than those from markdown. Depending on the number of articles, and the extent of the formatting in the LaTeX source files, it may be easiest to deal with this by reducing everything to markdown format. (Or you may prefer going the other way, converting all your markdown into LaTeX).

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.