How can you change the table of contents line spacing in Quarto when rendering to a PDF? - pdf

I am using Quarto for my dissertation and wish to change the table of contents line spacing to 1 when rendering to a PDF. I have my line spacing for the rest of the document set to 1.5 using linestretch: 1.5.
I have tried making up commands such as toc-linestretch: 1.5, which has not worked for me. From the basic documentation, I don't see how to change the toc spacing to 1 and keep the rest of the document spacing to 1.5. If anyone knows how to do this within the _quarto.yml file, please let me know!
I have also tried to make a custom toc.text file as a LaTeX/template partial, but so far it's not working. I based my toc.tex file on the defaul template provided in the Quarto source code (scroll to line ~337). My current toc.tex file is:
\usepackage{setspace}
\setstretch{1}
$if(has-frontmatter)$
\mainmatter
$endif$
$body$
I expected \setstretch{1} to work, but this is my first experience with LaTeX, so I wouldn't be surprised if my toc.tex file has issues, but I'm not sure what to try next. Thanks!

The toc.tex file you have provided here doesn't contain the necessary command (\tableofcontents) to generate the table of contents and you don't need to use the template.tex if you just need to modify the toc, you may use just the toc.tex instead.
So you can try to use the following toc.tex file (which I have modified a bit by removing lines for beamer format)
toc.tex
{\setstretch{1} % set the linestrech from here ------------------------
$if(toc)$
$if(toc-title)$
\renewcommand*\contentsname{$toc-title$}
$endif$
$if(colorlinks)$
\hypersetup{linkcolor=$if(toccolor)$$toccolor$$else$$endif$}
$endif$
\setcounter{tocdepth}{$toc-depth$}
\tableofcontents
$endif$
} % upto here ---------------------------------------------------------
$if(lof)$
\listoffigures
$endif$
$if(lot)$
\listoftables
$endif$
And then put the \usepackage{setspace} under include-in-header yaml key in the _quarto.yml file.
_quarto.yml
project:
type: book
book:
title: "Book"
author: "Jane Doe"
date: "1/4/2023"
chapters:
- index.qmd
- intro.qmd
- summary.qmd
- references.qmd
bibliography: references.bib
format:
pdf:
documentclass: scrreprt
linestretch: 1.5
include-in-header:
text: |
\usepackage{setspace}
template-partials:
- toc.tex

Related

How to Set Default Yaml For R Markdown Documents?

This is what I typically put at the top of my documents in R markdown:
---
title: Title
author: Amar Al-Zubaidi
date: \today
mainfont: Inconsolata Nerd Font
sansfont: Inconsolata Nerd Font
monofont: Inconsolata Nerd Font
fontsize: 11pt
table-use-row-colors: true
bibliography: /home/amarakon/Documents/bibliography.bib
csl: /home/amarakon/Documents/Citations/apa-no-initials.csl
classoption: letterpaper
output:
pdf_document:
keep_tex: true
latex_engine: xelatex
template: eisvogel
number_sections: true
---
I do pretty much the same thing for every document.
In fact, the only thing I change for every document is the title.
I want to know how I can put all of these values in a file (except for the title), and change my compile command to read that file when compiling. This is the command I use to compile:
R -e "rmarkdown::render('file.Rmd')"
My end goal is to only have to put something like this in my Rmarkdown document:
---
title: my-title
---
I answered a similar question not that long ago using this information.
Since I had worked on that question, I only had to clone my last template and update the skeleton to create your template.
You won't have a YAML with just your title. However, all of the elements that you specified you wanted would be pre-written in the RMD file when you open a new file using this template.
You can see this repository at fraupflaume/customYAML2.
To install this template (it's not a package per se; there's no library):
devtools::install_github("fraupflaume/customYAML2")
When you want to start a new RMD script, go to templates -> Custom YAML -> customYAML2.
If you wanted to change this down the road, you can fork or clone that repository and edit it to your heart's content.
BTW:: let me know if you want me to remove the images. (It has your name in them: here and on Github.)

How to add footer to pdf with pdfjam or pdftk?

I am using a shell script to modify many pdfs and would like to create a script that adds the page number (1 of X format) to the bottom of PDFs in a directory along with the text of the filename.
I tried using pdfjam with this format:
pdfjam --pagenumbering true
but it fails saying undefine pagenumbering
Any other recommendations how to do this? I am OK installing other tools but would like this to all be within a shell script.
Thank you
tl;dr: pdfjam --pagecommand '' input.pdf
By default, pdfjam adds the following LaTeX command to every page: \thispagestyle{empty}. By changing the command to an empty command, the default plain page style is used, which consists of a page number at the bottom. Of course you may want to play with other styles or layout options to position the page number differently.

Change font size of ATX-header in markdown

I am writing a book with bookdown. Unfortunately, I have no clue how to format (e.g. setting font size) ATX-hearder (#, ##, ## etc.). So far, it does not work via pandoc or preamble.tex.
I have tried the following, with regard to this.
Unfortunately, there is an error message :
\usepackage{titlesec} \titleformat{\chapter}[display] {\normalfont\sffamily\huge\bfseries\color{blue}} {\chaptertitlename\ \thechapter}{20pt}{\Huge}
Thanks in advance!
Your best bet here is to add a LaTeX preamble to the document. In here, you can define the required LaTeX packages. Two changes are made to the base template:
We need to add subparagraph: true to make titlesec work with R Markdown, as explained here
# refers to a level one header in pandoc, and therefore you need to make the style changes for section not chapter https://www.sharelatex.com/learn/Sections_and_chapters
Here is a minimal example
---
output:
pdf_document:
includes:
in_header: header.tex
subparagraph: true
---
# Section
## Subsection
The preamble.tex file is saved in the same directory:
\usepackage{titlesec}
\usepackage{color}
\titleformat*{\section}{\LARGE}
\titleformat{\subsection}[display]
{\normalfont\sffamily\huge\bfseries\color{blue}} {\chaptertitlename\ \thechapter}{20pt}{\Huge}

Knitr + Beamer to PDF: Incorrect Font Symbols

I'm using TexStudio 2.8.4 to create a pdf containing knitr output and I'm running into issues with symbols showing up incorrectly either in the pdf or when copy and pasted from the pdf. Here's a minimal working example.
\documentclass{beamer}
\begin{document}
\begin{frame}[fragile]
<<>>=
#dollar$sign
if(2+2 == 4){print("math")}
#
\end{frame}
\end{document}
In my pdf output, the $ in the commented out font shows up as the pound (currency) sign, but when copy and pasted shows up correctly as a dollar sign. This does not occur when it is not commented out.
More problematically, while the braces {} appear correct in the pdf output, when copied and pasted they are f and g. This confusion does not affect R's interpretation of the braces, however.
Do you have any thoughts/suggestions for fixing this? As a work around, I'm just using a non-echoed knitr block and using a latex verbatim environment for the code on the front side, though this is not ideal.
The command I'm using in my custom build is:
"C:/Program Files/R/R-3.2.2/bin/Rscript.exe" -e "library(knitr); knit2pdf('%.Rnw')" | pdflatex -synctex=1 -interaction=nonstopmode %.tex | "C:/Program Files (x86)/Adobe/Reader 11.0/Reader/AcroRd32.exe" "?am.pdf"
Cheers!
This seems to be a problem with LaTeX encoding. The solution is adding \usepackage[T1]{fontenc} to your preamble as suggested here.

Is there an "Export to Pdf" plugin for Tiddlywiki?

Has anyone put together a plugin or tool for exporting a Tiddlywiki to pdf?
No, there isn't.
As a workaround, I write or find a decent printable stylesheet, then print to PDF.
Why not select the target tiddler to "Open in new window", and print it to PDF with any installed PDF printer?
To accomplish this I used a tool to convert HTML to PDF. These steps are a bit long but well worth it. Once you've got it working it is easily repeated.
In each tiddler that I want in my PDF, I mark with a specific tag; I used TableOfContents.
In each tiddler that is marked with this tag, I added an order field--to be used to define the order of tiddlers to appear in the PDF.
Ensure your HTML headers are properly defined for the document. I think tiddler titles use <h2>, so properly defining subheadings using <h3><h4> etc will ensure, if you want, a nice auto-generated Table of Contents in your PDF.
If you want each tiddler to start on a new page (in the PDF), we need to add this HTML to the end of each tiddler:
<div style = "display:block; clear:both; page-break-after:always;"></div>
With a completed TiddlyWiki document export the tiddlers to a single HTML file--this will be used to generate a PDF document. To export, go to the AdvancedSearch, select the Filter tab. In the search textbox enter your filter criteria--for me that was:
[tag[TableOfContents]sort[order]]
You'll see, immediately, on-screen a list of the tiddlers the system found based on that criteria. Then click on the Export icon and select Static HTML.
Optionally, but I think it's a great idea, manually create a cover page (in your favorite editor)--this will be a single HTML file to act as the cover page in the PDF document; call it cover.html. More on this later.
Download and install wkhtmltopdf (command-line tool to generate PDF from an HTML file).
https://wkhtmltopdf.org/downloads.html
Learn and get familiar with the wkhtmltopdf command line syntax. There are numerous features here so the command you end up with maybe lengthy. Use wkhtmltopdf /? to view general help, then wkhtmltopdf --extended-help to view details (well worth the read).
Generate a PDF document. At the command prompt navigate to the folder where your TiddlyWiki document is located. Here is a list of my favorite command-line switches. My app is installed in C:\Program Files..., so my command line starts with that...
"c:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"
Add this switch for a header on the left:
--header-left "My document title"
For a header on the right:
--header-right "v1.0.0.1"
Font size of header:
--header-font-size 8
Display a line below the header:
--header-line
Spacing between header and content in mm (default 0):
--header-spacing 5
A left-footer ([section] is replaced with the name of the current section:
--footer-left "[section]"
A centered footer:
--footer-center "Page [page] of [topage]"
Footer font size:
--footer-font-size 8
Footer spacing:
--footer-spacing 5
If you want titles to hyperlink (in the PDF) to go back to the TOC:
--enable-toc-back-links
Make sure no background images get printed:
--no-background
I added special styles in the TiddlyWiki document for print media--to hide tags and clean up the spacing. Then I used this switch to ensure print media is used:
--print-media-type
Being in North America I want letter-size pages; I think the default is A4:
-s Letter
IMPORTANT--give the tool access to local files, otherwise your images will be missing in the PDF:
--enable-local-file-access
Use this if you want to have a cover page (see step 6 above):
cover "cover.htm"
And use this if you want a TOC automatically generated. Without a cover page, the TOC will be your first page, so create a cover page:
toc
After the toc identify your exported tiddler HTML file as input to the tool:
tiddlers.html
And, the final argument on the command line is the output PDF file name:
MyDocument.pdf
Export the tid to html.
Then in the terminal, issue:
html2pdf $myTid.html $myTid.pdf
$myTid is only a var and can be any name
:)