The vscode-pandoc Visual Studio Code extension lets you render markdown files as a PDF, word document, or html file.
Thanks to the previous work of @dfinke on this extension.
You need to install Pandoc - a universal document converter.
Alternatively you may set the useDocker
option to true and the extension runs Pandoc in a container using the latest official pandoc/latex image. This could result in a delay the first time it runs, or after an update to the container while it pulls down the new image.
Two ways to run the extension. You need to have a markdown file open.
F1
on Windows (shift+cmd+P
on Mac), type pandoc
, press Enter
ctrl+K
then P
(cmd+K
then P
on Mac)Choose from the list what document type you want to render and press enter
(you can also type in the box rather than cursor around).
Find pandoc
in settings.json and add the options you want to use. For example:
example:
//-------- Pandoc Option Configuration --------
// pandoc .pdf output option template that you would like to use
"pandoc.pdfOptString": "",
// pandoc .docx output option template that you would like to use
"pandoc.docxOptString": "",
// pandoc .html output option template that you would like to use
"pandoc.htmlOptString": "",
// path to the pandoc executable. By default gets from PATH variable
"pandoc.executable": "",
// enable running pandoc in a docker container
"pandoc.docker.enabled": "true",
// specify the docker options when "pandoc.docker.enabled" is "true"
"pandoc.docker.options": "",
// specify the docker image when "pandoc.docker.enabled" is "true"
"pandoc.docker.image": ""
You can set options for each output format.
default:
$ pandoc inFile.md -o outFile.{pdf|word|html}
For example, for Japanese documents.
"pandoc.pdfOptString": "--pdf-engine=lualatex -V documentclass=ltjarticle -V geometry:a4paper -V geometry:margin=2.5cm -V geometry:nohead",
--pdf-engine=lualatex
: need to create a Japanese PDF-V documentclass=ltjarticle
: need to create a Japanese PDF-V geometry:a4paper -V geometry:margin=2.5cm -V geometry:nohead"
: geometory optionsWord(docx)
pandoc.docxOptString": "",
HTML5
"pandoc.htmlOptString": "-s -t html5"
-s
: produce a standalone document-t html5
: HTML5 output formatFor more information please refer to the Pandoc User's Guide.
When running on linux systems (and possibly others) when using the docker, there may be file permission issues with the docker image. This can appear as an error such as the following:
stderr: pandoc: file.html: openFile: permission denied (Permission denied)
exec error: Error: Command failed: docker run --rm -v "/home/user/path:/data" pandoc/latex:latest "file.md" -o "file.html"
pandoc: file.html: openFile: permission denied (Permission denied)
This may occur due to the file/directory permissions being incorrect. To allow this to function, you can specify the docker options to set the uid/gid using the following:
"pandoc.docker.options": "--user $(id -u):$(id -g)"
If needed, you can also change the default pandoc docker image using the pandoc.docker.image
configuration setting.