GeneralFrom multiple md files to one tex

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

From multiple md files to one tex

Post by ziselos »

Hello,
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:

Code: Select all

pandoc file1.md -f markdown -t latex -s -o file1.tex
pandoc file2.md -f markdown -t latex -s -o file2.tex
…. 
pandoc file10.md -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

\documentclass{scrbook}
\begin{document}
\include{file1}
\include{file2}

\include{file10}
\end{document}


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.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

ziselos
Posts: 15
Joined: Sun Mar 04, 2018 12:03 pm

From multiple md files to one tex

Post by ziselos »

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: 10335
Joined: Mon Mar 10, 2008 9:44 pm

From multiple md files to one tex

Post by Stefan Kottwitz »

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!

Stefan
LaTeX.org admin
Post Reply