# Markdown notes within tex document chapter

I wish to add blocks of markdown notes within my thesis. However, whenever I use \begin{markdown} it automatically starts a new chapter.

For example, this will generate two chapters, with the markdown list at the start of chapter 2:

main.tex:

\documentclass[a4paper,twoside]{ociamthesis}
\begin{document}
\chapter{\label{ch:1-intro}Introduction}

I want this to be in Chapter 1

\begin{markdown}
# I want this to be in Chapter 1 but somehow it starts Chapter 2
- bullet 1
- bullet 2
- bullet 3
\end{markdown}

I want this to be in Chapter 1 too
\end{document}


ociamthesis.cls:

\LoadClass[openright,12pt]{report}
\usepackage[hybrid]{markdown}


Is there anyway to include markdown code without starting a new chapter? (I'm using Overleaf)

• Welcome to TeX.SX! Please post a complete compilable but minimal example here. In order to know how to best help you, it is always better to know at least a bit about your set up and especially the packages you use Also, do you want the markdown code to be rendered as LaTeX or just print it as it is (verbatim)? May 12 '20 at 14:51

• I never used the markdown package before: There may be a better explanation.
• The package seems to be interesting, especially considering the authors (e. g. Hans Hagen who is the author of ConTeXt).
• You use ## within markdown which is apparently a 2nd-level heading.
• This is like a \section command and therefore you get 1.1 Test.
• --> The solution is to not use a markdown heading command (like ##) if you don't want a new heading :).

Remark 1: I had to run the code using the -shell-escape compile option. Otherwise I got a corresponding error message.

Remark 2: The original question used ## (2nd-level heading) later the code in the question was changed to #.

## Your Code (incl. ##)

%% pdflatex -shell-escape %.tex

\documentclass{report}
\usepackage[hybrid]{markdown} % [hybrid] is not relevant in this example.
\begin{document}
\chapter{Introduction}

I want this to be in Chapter 1

\begin{markdown}
## Test
**bold**
\end{markdown}

I want this to be in Chapter 1 too
\end{document}


## My Code (excl. ##)

%% pdflatex -shell-escape %.tex

\documentclass{report}
\usepackage[hybrid]{markdown} % [hybrid] is not relevant in this example.
\begin{document}
\chapter{Introduction}

I want this to be in Chapter 1

\begin{markdown}
**bold**
\end{markdown}

I want this to be in Chapter 1 too
\end{document}


• I realised the minimal example i originally fabricated actually puts everything into a single chapter (because i used "##"). I've changed my example back to "#" so everything would make sense to the future reader of this thread. May 13 '20 at 11:15
• @matohak Ok, good. I have noticed that your code and your problem description do not align but I did not mention it because is did not matter, May 13 '20 at 16:37

I'd use this opportunity to present a radically different and somewhat more flexible pipeline. It does not depend on markdown package at all. I use pandoc, but basically any markdown to TeX converter can be used.

Basically, I write a LaTeX main file, for example:

\documentclass{article}
\usepackage{microtype}

\begin{document}
\include{content} % !!!!
\end{document}


The content.md is a markdown file, for example:

## Heading

Hello, I am *markdown*, _not_ **markup**!


The magic happens in a Makefile (yeah, Linux and Mac world, but should work on Windows with corresponding additional software, such as Cygwun):

main.pdf : main.tex content.tex Makefile
latexmk -pdf main

content.tex : content.md Makefile
pandoc -f markdown+smart+raw_tex --natbib -t latex content.md -o content.tex

clean :
latexmk -C -pdf main
rm -f content.tex


Now, with a simple make command a document is built from Markdown to PDF with LaTeX using all the required LaTeX things from main.tex (such as journal paper formatting or fonts).

Notice, that my Makefile includes a raw_tex filter, so you can write in markdown file:

{=latex}
\begin{figure}[tb]
FIGURE
\end{figure}



The marked segment will be passed to LaTeX as is. From experience, pandoc detects many LaTeX commands even without it, so \mycommand{foo} works even without that filter.

• Thanks for the code. From what I read in the manual of the markdown package, the goal of the package is to avoid external tools. May 12 '20 at 18:38