I want to get rid of the title page in Quarto but did not get it. I've found some option that have no effect in my document https://github.com/periodicpoint/robusta/blob/master/settings/00_00_settings.yaml
custom_title_page: false
format:
pdf:
classoption:
- 'titlepage=false'
Maybe i'm just irritated and it's trivial
---
title: "test"
format: pdf
---
text
gives a title
---
format: pdf
---
text
gives no title. But maybe there is also a switch in yaml to omit the title page even if the title is set?
You can do this easily using a Pandoc Lua filter, which will remove the document title even if the title is set and this will work not just for pdf output, but also html and docx.
---
title: "Title"
format: pdf
filters: [remove_title.lua]
---
text
remove_title.lua
function Meta(m)
m.title = nil
return m
end
Related
I am struggling what what is likely a trivial markdown matter. I am hoping to avoid YAML and additional header templates and such if I can. So my question is straightforward and I welcome your feedback. For an R Markdown knitted as a PDF, how can I repeat the title and date on each printed page?
Alternatively I am happy to use headers using the '#' syntax. But if I can use the title parameters that would be preferred.
The Header thus far:
---
title: "Dashboard"
date: '`r paste(Sys.Date(), " to ", Sys.Date()+14)`'
output:
pdf_document:
latex_engine: xelatex
mainfont: Calibri
geometry: margin=1cm
classoption: landscape
params:
set_title: !r test_title
header-includes:
- \usepackage{titling}
- \pretitle{\begin{flushleft}\huge}
- \posttitle{\end{flushleft}}
- \preauthor{\begin{flushleft}}
- \postauthor{\end{flushleft}}
- \predate{\begin{flushleft}\large}
- \postdate{\end{flushleft}}
---
From the rmarkdown cookbook:
When a Rmd document is compiled, all of its metadata in the YAML section
will be stored in the list object rmarkdown::metadata. You can use this object
in your R code. For example, rmarkdown::metadata$title gives you the title
of the document.
I'd like to use pandoc lua filter when I convert multiple markdown files from markdown to pdf. I'd like the titles of individual markdown files to be used as chapters (first-level headers).
I learned the existing examples, and I think this one is close to what I need - basically I need to add pandoc.Header(1, doc.meta.title) to all my markdown files, however I'm struggling to write the lua filter and make it work.
I think this question is doing a similar action pandoc filter in lua and walk_block
The pandoc command:
pandoc -N --lua-filter add-title.lua blog/*.md --pdf-engine=xelatex --toc -s -o my_book.pdf
The add-title.lua (this is just wrong, no exceptions but nothing happens to the output):
function add_header (header)
return {
{Header = pandoc.Header(1, meta.title)}}
end
Input files:
1.md
---
title: Topic1
---
## Sample Header from file 1.md
text text text
2.md
---
title: Topic2
---
## Sample Header from file 2.md
text text text
Expected output equivalent to this markdown (but my final format is pdf)
---
title: Title from pandoc latex variable
---
# Topic1
## Sample Header from file 1.md
text text text
# Topic2
## Sample Header from file 2.md
text text text
I think the key problem is that the lua filters only run once the full set of documents have been parsed into a single AST. So the individual files are effectively concatenated prior to parsing to create a single document with a single set of metadata. The individual title settings in the yaml metadata blocks are being overridden before the filter has a chance to run. Assuming that you need to get the heading from each separate metadata block (and can't just put the header in directly) this means that you cannot let pandoc join the files. You will need to read and parse each file separately. Fortunately this is pretty easy with filters.
The first step is to make a single reference file that contains links to all of the other files.
---
title: Combined title
---
![First file](1.md){.markdown}
![Second file](2.md){.markdown}
Note that the links are specified using images with a special class .markdown. You could use some other method, but images are convenient because they support attributes and are easy to recognise.
Now we just need a filter that will replace these images with the parsed elements from the linked markdown file. We can do this by opening the files from lua, and parsing them as complete documents with pandoc.read (see https://www.pandoc.org/lua-filters.html#module-pandoc). Once we have the documents we can read the title from the metadata and insert the new header. Note that we apply the filter to a Para element rather than the Image itself. This is because pandoc separates Block elements from Inline elements, and the return value of the filter must be of the same type. An Image filter cannot return the list of blocks parsed from the file but a Para can.
So here is the resulting code.
function Para(elem)
if #elem.content == 1 and elem.content[1].t == "Image" then
local img = elem.content[1]
if img.classes:find('markdown',1) then
local f = io.open(img.src, 'r')
local doc = pandoc.read(f:read('*a'))
f:close()
-- now we need to create a header from the metadata
local title=pandoc.utils.stringify(doc.meta.title) or "Title has not been set"
local newHeader=pandoc.Header(1, {pandoc.Str(title)})
table.insert(doc.blocks, 1, newHeader)
return doc.blocks
end
end
end
If you run it on the combined file with
pandoc -f markdown -t markdown -i combined.md -s --lua-filter addtitle.lua
you will get
---
title: Combined title
---
Topic 1
=======
Sample Header from file 1.md
----------------------------
text text text
Topic 2
=======
Sample Header from file 2.md
----------------------------
text text text
as required.
Note that any other yaml metadata in the included files is lost. You could capture anything else by taking it from the individual meta object and placing it into the global one.
I compiling a short document using bookdown in Rstudio. I would simply like to drop the table of contents at the beginning of the document. I could "knit to pdf" instead of "knit to pdf_book" or "knit to pdf_document2", but then would loose a lot of the bookdown functions (cross references etc.).
Should be fairly easy, isn't it?
---
title: "MWE"
output:
bookdown::pdf_book:
toc: false
---
It also works with pdf_document2:
---
title: "MWE"
output:
bookdown::pdf_document2:
toc: false
---
As question, I am using knitr option (i.e. include=temp.switch) to compile multiple reports based on the value given to a "switch" (i.e. temp.switch), this are working well for the content, but I would like to use similar function to modify the cover page of the report, which is stored in the tex file read in yaml, like the one below:
---
output:
pdf_document:
# template: template.tex
number_sections: true
keep_tex: true
includes:
in_header: preamble.tex
before_body: doc-prefix.tex
papersize: a4
editor_options:
chunk_output_type: console
---
Can anyone tell me how to make the doc-prefix.tex "conditional" based on the value of the "switch"? Thanks!
I am new to the markdown. I want to write a report with python code and I would like to add title, author and date. I tried to use this code
---
title: My Title
author: My author
---
But this is not working. Can anyone suggest how to sort this problem.
Just by the syntax, it should be the right markdown format and pandoc should be able to format it. Try using this code:
import pypandoc
mytext = """
---
title: My Title
author: My author
--- """
pypandoc.convert_text(mytext,'pdf',format='markdown',
outputfile="output.pdf",
extra_args=['--pdf-engine','pdflatex'])
It should give you output.pdf that looks like this: