Is there any package with Markdown support?

There is a new package for the inclusion of Markdown in plain TeX, LaTeX, and ConTeXt documents. Much like the package suggested by Michal in the accepted answer, this package is also based on the Lunamark parser. This time around, the parser was heavily modified, so that it allows the user to control the expansion of Markdown tokens to TeX tokens:

\documentclass{article}
\usepackage{markdown}
\markdownSetup{
  renderers = {
    link     = {#1},        % Render a link as the link label.
    emphasis = {\emph{#1}}, % Render emphasis using `\emph`.
  }
}
\begin{document}
\begin{markdown}
  _Hello,_ [Stack Exchange](http://tex.stackexchange.com)!
\end{markdown}
\end{document}

The above code produces “Hello, Stack Exchange!”. Note that setting up these mappings is not mandatory (though often useful); the defaults should be quite sane. Package authors are encouraged to redefine renderer prototypes (see section 2.2.4 in the package documentation) to override the defaults without overriding the user mappings.

Any engine that supports shell access (pdfTeX, XeTeX) can be used, not just LuaTeX. Note, however, that you need to provide the --shell-escape option or set shell_escape=t in the texmf.cnf file when you don't use LuaTeX. This is similar to other packages (such as Geoffrey M. Poore's minted) that require shell access.

The package also supports syntax extensions such as citations, fenced code blocks, and other (see section 2.1.2 in the package documentation), although I did backport these to Lunamark, so they can now be used with Michal's package as well.


Edit:

I've put this code on github - latexmark, and extended little bit.

New package options are provided:

extensions: select lunamark extensions

document: process whole everything between \begin{document} ... \end{document}

template: select Cosmo template which will be used for printing converted text

new command was added:

\markdownfile{filename}

typeset markdown file.


It is possible to use lunamark with LuaTeX, but it is little bit harder to install it. You need to add to your local texmf tree (usually ~/texmf/scripts/lua, you may need to create this directory) new directory lunamark and copy contents of standalone/src directory from lunamark sources.

Test if that works with command:

kpsewhich lunamark.lua

path to this file should be printed.

After successful installation, we can create simple lua module for lunamark loading, latexmark.lua

local latexmark = {}
local lunamark = require("lunamark")
local writer = lunamark.writer.latex.new()
local util = lunamark.util
writer.string = function(s) return s end
writer.definitionlist= function(items)
    local buffer = {}
    for _,item in ipairs(items) do
      local defs = {}
      buffer[#buffer + 1] = {"\\item[",item.term,"] ", util.intersperse(item.definitions,"\n")}
    end
    local contents = util.intersperse(buffer, "\n")
    return {"\\begin{description}\n",contents,"\n\\end{description}"}
 end
latexmark.init = function(extensions)
   local extensions = extensions or { smart = true, definition_lists=true}
   latexmark.parser = lunamark.reader.markdown.new(writer, extensions)
end

latexmark.end_env = "%s*\\end{latexmark}"
local buffer = {}
latexmark.callback = function(buf)
  if buf:match(latexmark.end_env) then
    --local ret =  latexmark.process() 
    --table.insert(ret, buf)
    return ret
  end
  buffer[#buffer+1] = buf
  return ''
end

latexmark.process = function()
  local result = latexmark.parser(table.concat(buffer,"\n"))
  buffer = {}
  local lines = string.explode(result,"\n")
  for _, line in ipairs(lines) do
    print(line)
    tex.print(line)
  end
  return lines
end

return latexmark

lunamark is being initialized and function for LuaTeX's process_input_filter is provided. now some simple LaTeX package, latexmark.sty:

\ProvidesPackage{latexmark}

\RequirePackage{luatexbase}

\directlua{%
  latexmark = require "latexmark"
  latexmark.init()
}


\newenvironment{latexmark}
{\directlua{luatexbase.add_to_callback("process_input_buffer",latexmark.callback,"latexmark")}}
{\directlua{%
    luatexbase.remove_from_callback("process_input_buffer", "latexmark")
    latexmark.process()
}}

\endinput

new environment, latexmark is provided, it's contents will be converted. It is really easy to use:

\documentclass{article}
\usepackage{fontspec}
\usepackage{latexmark}
\begin{document}

\begin{latexmark}
# Hello world

1. enumerated
2. list

some \LaTeX\ stuff: $a = \sqrt{b}$

what
: it is easy to provide description lists

and also `monospaced`, or *emphatized* texts

\end{latexmark}
\end{document}

enter image description here

Some sample file: