I am currently running the following command to populate my latex template.

pandoc -s --top-level-division=chapter --template=template.tex metadata.md content/*.md -o frommarkdown.tex

The content of the latex-ized *.md files are populating the template via the $body$ variable. However this happens verbatim, the $body$variable gets in-place substituted with the tex code generated from the md files. This generated a huge latex file with all my thesis chapters in one big file concatenated.

My ideal case would look like that I can \include all of the on the fly generated tex-files in my document, allowing me to keep a clean latex document which can come in handy when debugging or altering a larger project (e.g thesis).

I would ideally like to have something like that:

$for(include-chapters)$ \include($include-chapters$) $endfor$

My hunch was now to achieve this with a two step solution by first generating standalone tex files per *.md file (without the usage of a template). Then I would like to dynamically include these generated tex files in my main tex "template".

Can this be achieved with pandoc or do i need to write a custom shell script for this?

  • I don't think this can be achieved with pure pandoc. You can try pandoc-discuss for help building a custom filter for that. Have you considered working in your thesis entirely in markdown/pandoc instead of going back and forth to tex? – lf_araujo Mar 11 '17 at 11:43

I don't grasp what you are exactly trying to do but you can modify the template and make it include tex files.

  1. Get the latex template and save it to template.tex: pandoc -D latex > template.tex

  2. Open the template file and add the following code snippet below $body$:

  3. Now you can add the files you want to include to metadata.md:

    - content/chapter1
    - content/chapter2
  4. Run pandoc:

    pandoc -s -S --top-level-division=chapter \
           --template=template.tex \
           metadata.md -o frommarkdown.tex

Those steps will result in:




Still I don't recommend doing this. There are very powerful tools out there, which can do more and better, e.g. make

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.