# Pandoc / Latex / Markdown

For a project, I would like to use .md files and convert them to a .docx file. I would also like to include some \latex\ commands within the .md files. I just do not want to mess up the system that I am currently using because it works well. Which is contradictory, but hopefully it can be done.

Here is my pandoc setup:

pandoc --reference-doc=pandoc/reference.docx frontmatter1.md fm2.md fm3.md fm4.md f5.md ch1.md ch2.md ch3.md bib.md endmatter.md em.md -o article.docx

I know latex makes much more sense for what I am trying to do above, but working with .docx is a painstaking process. The reference.docx solution works well for me. I just highlight the sections and select the style.

Finally, my question. Can I insert \latex\ commands such as \newpage at the end of my .md files? So far, I have been unsuccessful.

Here is an example of a .md file I would like to get working with latex / pandoc / word:

# heading
Some text here.
More text here.

\newpage


I'm not sure if I should be posting an answer on my question, but the real answer seems to be that it just doesn't exist. See the following:

GitHub
Pandoc Open Issue

As noted by @hearsay, there is no build-in way of doing this. However, using a few lines of Lua allows to convert all \newpage LaTeX snippets into the respective OpenXML structure:

-- write to file: docx-pagebreaks.lua
function RawBlock (blk)
if FORMAT == 'docx' and blk.format == 'latex' and blk.text == '\\newpage' then
return pandoc.RawBlock(
'openxml',
'<w:p><w:r><w:br w:type="page"/></w:r></w:p>'
)
end
end


Run with

pandoc --reference-doc=pandoc/reference.docx \
--lua-filter=docx-pagebreaks.lua
frontmatter1.md fm*.md ch*.md bib.md endmatter.md em.md \
-o article.docx


You can perfectly include LaTeX commands in markdown to export with pandoc to a LaTeX document, then the LaTeX document can be converted to docx and some of these commands will produce the desired effect in the .docx files, as \emph{text}, while others will be ignored, as \newpage.

That is, you cannot export LaTeX commands in .md → .docx conversion as all the latex code will be ignored, but as far as possible you can do it in a .md → . tex. → .docx process like:

 $pandoc -s test.md -o test.tex$ pandoc borra.tex -o borra.docx