Latex Commands in Julia Markdown

Viewed 490

I have a simple Julia Markdown script, that I would like to turn into a PDF using Weave.jl:

---
title: Just a test
author: Me
date: 2022-01-03
output: pdf_document
---

# Some header
Some text.

\newpage

## Some other header
More text.

Now, the crux in that document is the \newpage command, which is meant to be executed as a Latex command, i.e. "create a pagebreak". But when using weave("myfile.jmd", doctype="md2pdf") Weave (or something else) becomes super smart and translates it to {\textbackslash}newpage - a smart way of refusing to let me do exactly what I want to do: Latex commands.

Is there any way to avoid this?

3 Answers

You can use "pandoc2pdf" instead to let pandoc interpret the markdown in the file: weave("myfile.jmd", doctype="pandoc2pdf") with your given script works and produces the expected pdf.


Alternate answer:

Weave documentation mentions that "md2pdf" uses Julia Markdown, and the Julia Markdown page specifies that LaTeX syntax goes between double backticks.

---
title: Just a test
author: Me
date: 2022-01-03
output: pdf_document
---

# Some header
Some text.

``\pagebreak``

## Some other header
More text.

This works and produces the intended output. (``\newpage`` errors out for some reason, and I'm not comfortable enough with LaTeX to figure out why.)

That may be your rendering engine. This is tagged julia and you state using a .jmd file.

I happen to use this idiom of injecting 'plain LaTeX' a lot so I just saved your file 'as is' as foo.Rmd and used my usual shorthand caller for Rmarkdown on it:

enter image description here

I would recommend decomposing the commands as much as you can, and maybe try just pandoc on it too. You may find what wrapped that stray command.


As per the other answer, it simply is a bug in weave.jl. It should not do that yet it does.

The answer by @SundarR suggests a workaround using a different subrender (just how I had hinted at pandoc) as well as a (required for this "dialect" of markdown?) workaround with two backticks.

Related