1

I'm trying to convert a markdown file to docx using pandoc. In particular, my markdown file makes use of YAML and LaTEX syntax (I use markdown as much as possible for simplicity). This is the document sample:

% Title

---
author: Name
header-includes:
    - \usepackage{cleveref}
toc-title: Content
---

# Heading

See \cref{image}.

![Image caption\label{image}](image.png)

If I run pandoc source.md -o output.docx --table-of-contents it does not render appropriately the \cref{image}. However, if I convert it to PDF (pandoc source.md -o output.pdf --table-of-contents) it does; but then other Markdown syntax (e.g. [see @citation]) does not.

What am I doing wrong?

6
  • Doesn't pandoc require you to give a bibliography command (e.g., --biblatex or --natbib)?
    – jon
    Feb 24, 2017 at 17:02
  • Yep in order to use citations I use --bibliography, but here I wanted to focus on how to implement latex pure commands (which I need for example to render the list of figures) with plain markdown text (that is a lot easier for example when it come to tables rendering)
    – cellulosa
    Feb 24, 2017 at 17:06
  • Hmm, well, I think pandoc-to-docx questions are off-topic for this site, so the only part of the question that fits is the one about the bibliography. And it sounds like you know how to make @citation work..? (As an aside, I do not really know anything about to-docx conversions.)
    – jon
    Feb 24, 2017 at 17:12
  • Ouch ok then I opened a ticket here. Thanks for your help.
    – cellulosa
    Feb 24, 2017 at 17:58
  • For converting to PDF are you using --filter=pandoc-citeproc? Mar 2, 2017 at 14:59

1 Answer 1

2

These are two questions. It takes some time to get used to the proper syntax, you seem to get the yaml a little off (remember to refer to the user manual frequently). So here we go:

  1. Picture does not get printed in the pdf. This happens because pandoc usually does not understand plain latex within the markdown unless the -s flag is passed. So if you want this image to get rendered in both pdf and docx you need to use proper pandoc syntax: ![la lune](lalune.jpg "Voyage to the moon"). Remove the \label{image} part. If you want a label, you will need to pass the flag --filter pandoc-crossref. The syntax also changes slightly to accept the label: ![Caption](file.ext){#fig:label}

  2. Citation is not picked up by pandoc. Here you have some problems, first you have to point to a bibtex file in the yaml. The syntax is bibliography: '/file.bib'. Second you have to pass another flag --filter pandoc-citeproc to pandoc. Third, use @citation to refer to it.

Finally, your md should look more like:

---
title: Title
author: Name
toc-title: Content
bibliography: '/file.bib'
header-includes:
    - \usepackage{cleveref}
---

# Heading

See @fig:label. This dude has talked about it previously: @thedude2017

![Caption](file.ext){#fig:label}

# References

Build it with pandoc file.md --filter pandoc-crossref --filter pandoc-citeproc -o file.pdf.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .