Go to page:

Search:   Help



LyX documentation


Shared groups



Categories: Tips, Markdown
<< | Page list | >>

Importing and exporting Markdown documents to/in LyX

It is possible to import Markdown documents in LyX, directly from LyX, and export LyX documents to Markdown.

Pandoc is able to make these conversions in a very flexible way.

This page gives the very basic tips to get started, but you can find more information in the Pandoc documentation.

Shortly, in order to convert From/To Markdown, you need a full chain of conversion between Markdown, Plain LaTeX, and LyX. The last element of the chain is already present in vanilla LyX, so we need to configure the part Markdown-Plain LaTeX.

We need first to create a document type in Preferences / File Handling / File Formats. Use the following configuration:

  • format: Markdown,
  • short name: markdown,
  • extension: md,
  • check the box Document Format.

From Markdown to LyX

Now that the Markdown format is known to LyX, we can configure and converter from Markdown to LaTeX (plain) in Preferences/ File Handling Converters : We start with the selected converter, we select Markdown for From format and LaTeX (plain) for the To format.

You can simply use then in the Converter box the simplest Pandoc command line:

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

You can also use a more complete one. This one will give a cleaner LaTeX file, and allows the inclusion of raw LaTeX commands in the Markdown file:

pandoc -s -f markdown-auto_identifiers+raw_tex -t latex -o $$o $$i

Letting other options to their default values, you can click the Add button on the top part of the panel, next to Converters list.

From LyX to Markdown

This is just the inverse conversion. We need to select LaTeX (plain) in the From: box, and Markdown in the To: box. We use the simple command in the Converter box:

pandoc  --wrap=none -f latex -t markdown -o $$o $$i

Again, click on Add button on the top part, to create this new converter.

Now, LyX should propose Markdown as a possibility in the File / Export menu.

More options

The pandoc documentation is very complete and Pandoc has a full set of sophisticated options. One of them is using your personal document template during these conversions. For example, this GitHub page proposes a very sophisticated one that you can customize (thanks to Eberhard W. Lisse for pointing to this possibility!).

You can also automatize this conversion each time you save the Markdown document, using a CRON job or Hazel task in macOS, and running a tool like Pandocomatic.


Tips Markdown

Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2021-07-28 10:51 CEST