I would like to retain the syntax highlighting for code written in code blocks in the Quarto document (.qmd) after rendering a PDF. Please let me know if this is possible.
There is a difference between the syntax highlighting theme in your IDE (e.g., VS code) and the syntax highlighting that is used when rendering a PDF. Details can be found here: Quarto Synax Highlighting
You are able to choose from a list of supported themes (arrow, pygments, tango, espresso, zenburn, kate, monochrome, breezedark, haddock, atom-one, ayu, breeze, dracula, github, gruvbox, monokai, nord, oblivion, printing, radical, solarized, and vim), using the following command at the top of the document:
---
title: "title"
author: First Last
format:
pdf:
highlight-style: atom-one
---
You are also able to customize your own syntax highlighting style using the command (pandoc's needs to be installed) and setting the highlight-style to the newly created theme.
quarto pandoc --print-highlight-style pygments > mytheme.theme
---
title: "title"
author: First Last
format:
pdf:
highlight-style: mytheme.theme
---
You are then able to customize your theme file (mytheme.theme).
My goal was to try to get the color scheme of the code chunks in rendered PDF identical to the selected VS code theme (in my case Dark+). The best option I found was to use the 'Developer: Generate Color Theme From Current Settings' command (i.e., workbench.action.generateColorTheme) to generate a document of the current color theme. After several rounds or trial and error, I was able to create a theme similar to the VS Code Dark+ theme (see code below).
Information about the style attributes in the .theme file can be found in this GitHub Repo
The syntax highlighting in the editor and during output generation are two completely separate entities. It probably is possible somehow, but would require manual translation of the color theme into a pandoc highlighting theme.
2
Answers
There is a difference between the syntax highlighting theme in your IDE (e.g., VS code) and the syntax highlighting that is used when rendering a PDF. Details can be found here: Quarto Synax Highlighting
You are able to choose from a list of supported themes (arrow, pygments, tango, espresso, zenburn, kate, monochrome, breezedark, haddock, atom-one, ayu, breeze, dracula, github, gruvbox, monokai, nord, oblivion, printing, radical, solarized, and vim), using the following command at the top of the document:
You are also able to customize your own syntax highlighting style using the command (pandoc's needs to be installed) and setting the highlight-style to the newly created theme.
You are then able to customize your theme file (mytheme.theme).
My goal was to try to get the color scheme of the code chunks in rendered PDF identical to the selected VS code theme (in my case Dark+). The best option I found was to use the 'Developer: Generate Color Theme From Current Settings' command (i.e., workbench.action.generateColorTheme) to generate a document of the current color theme. After several rounds or trial and error, I was able to create a theme similar to the VS Code Dark+ theme (see code below).
Information about the style attributes in the .theme file can be found in this GitHub Repo
mytheme.theme file
}
The syntax highlighting in the editor and during output generation are two completely separate entities. It probably is possible somehow, but would require manual translation of the color theme into a pandoc highlighting theme.
See, for example, Pandoc: What are the available syntax highlighters?.