LaTeX forum ⇒ GeneralFrom multiple md files to one tex Topic is solved

LaTeX specific issues not fitting into one of the other forums of this category.
Posts: 11
Joined: Sun Mar 04, 2018 12:03 pm

From multiple md files to one tex  Topic is solved

Postby ziselos » Tue Apr 10, 2018 5:29 pm

During my thesis I have multiple md (markdown) files in a git repository. All these md files are chapters of a final book pdf that I want to generate. I would like to use XeLatex so I am thinking of converting all md files to tex files (using pandoc) and then include them in final book.tex file that will export the pdf. (An alternative is to hard copy paste the content of 10 md files in a Latex book template but I think there is a more generic way)

I wrote a Makefile in order to convert md files to tex like below:
  1. pandoc -f markdown -t latex -s -o file1.tex
  2. pandoc -f markdown -t latex -s -o file2.tex
  3. ….
  4. pandoc -f markdown -t latex -s -o file10.tex

I run the Makefile and as a result I took 10 tex files. After that, I tried to include them in the final book.tex file



Each one tex file,as generated from pandoc, has it's own documentclass and i as a result i am getting error during compilation (Latex error: file1 can be used only in preamble). I tried to hard copy-paste the text of the first file in another tex file without documentclass and works fine, without errors.
Is there a way to get the final tex file without copy-paste the content of each sub file? I believe that i need to add something in my Makefile in order to give only one tex file as a result.

Thanks for your attention. I’m looking forward to your reply.


Posts: 11
Joined: Sun Mar 04, 2018 12:03 pm

Postby ziselos » Wed Apr 11, 2018 7:59 am

Removing -s (standalone) from Makefile solve my problem. Without -s i get only the content of each tex file and then i can include them in main tex file.

User avatar
Stefan Kottwitz
Site Admin
Posts: 8733
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany

Postby Stefan Kottwitz » Wed Apr 11, 2018 8:44 am

I use MD too. I also considered conversion with pandoc, but then I preferred using the LaTeX markdown package, because then I can use also LaTeX macros within the MD text. The whole document preamble with style definitions and setting comes in via \input. So I simplify the code for cooperating with my colleagues to write and to maintain documentation.

Thank you for telling us your solution!

Site admin

Return to “General”

Who is online

Users browsing this forum: No registered users and 13 guests