Pandoc
Versione italiana
Che cos’è Pandoc?
Pandoc è un potente strumento di conversione di documenti, gratuito e open source, che consente di trasformare file in vari formati. È particolarmente utile per chi lavora con testi e documenti in formati diversi, come Markdown, LaTeX, HTML, DOCX, PDF e molti altri.
Ecco alcune caratteristiche principali di Pandoc:
Conversione tra formati: Pandoc supporta una vasta gamma di formati di input e output, permettendo di convertire documenti da un formato all’altro con facilità.
Markdown avanzato: Pandoc estende il linguaggio Markdown standard, aggiungendo funzionalità come tabelle, note a piè di pagina e citazioni, rendendolo più potente per la scrittura di documenti complessi.
Template personalizzabili: Gli utenti possono creare e utilizzare template personalizzati per controllare l’aspetto finale dei documenti convertiti.
Supporto per metadati: Pandoc consente di includere metadati nei documenti, come titolo, autore e data, che possono essere utilizzati per generare automaticamente intestazioni e bibliografie.
Integrazione con strumenti di scrittura: Può essere integrato in vari flussi di lavoro e strumenti di scrittura, come editor di testo e sistemi di gestione dei contenuti.
Utilizzo da riga di comando: Pandoc è principalmente uno strumento da riga di comando, il che lo rende adatto per l’automazione e l’integrazione in script e processi di build.
In sintesi, Pandoc è uno strumento versatile e potente per chiunque abbia bisogno di lavorare con documenti in diversi formati, rendendo la scrittura e la pubblicazione più fluide e flessibili.
E' possibile integrare Pandoc in VS Codium (o Visual Studio Code) utilizzando estensioni e configurazioni specifiche. Anche se non esiste un’estensione ufficiale di Pandoc, ci sono alcune opzioni che puoi considerare per facilitare l’uso di Pandoc all’interno dell’editor:
Estensioni per Markdown: Ci sono diverse estensioni per Markdown che possono migliorare l’esperienza di scrittura e che possono essere utilizzate insieme a Pandoc. Ad esempio, estensioni come “Markdown All in One” offrono funzionalità avanzate per la scrittura in Markdown.
Terminale integrato: Puoi utilizzare il terminale integrato di VS Codium per eseguire i comandi di Pandoc direttamente. Basta aprire il terminale (con
Ctrl +
) e digitare i comandi Pandoc per convertire i tuoi documenti.Task di VS Codium: Puoi configurare un task in VS Codium per eseguire automaticamente i comandi di Pandoc. Questo ti permette di eseguire la conversione con una semplice scorciatoia da tastiera. Puoi farlo creando un file
tasks.json
nella cartella.vscode
del tuo progetto.Snippet e scorciatoie: Puoi anche creare snippet personalizzati o scorciatoie da tastiera per facilitare l’inserimento di comandi Pandoc.
Estensioni di terze parti: Esplora il marketplace delle estensioni di VS Codium per vedere se ci sono estensioni di terze parti che offrono integrazioni specifiche con Pandoc.
Comandi di base
pandoc [opzioni] [file di input] -o [file di output]
Opzioni comuni
-o, --output=FILE
: Specifica il file di output.-f, --from=FORMAT
: Specifica il formato di input (es.markdown
,html
,latex
,docx
, ecc.).-t, --to=FORMAT
: Specifica il formato di output (es.markdown
,html
,pdf
,docx
, ecc.).-s, --standalone
: Crea un documento autonomo (inclusi header e footer).-V, --variable=VAR:VALUE
: Imposta una variabile per il template (es.-V title="Il mio titolo"
).--template=FILE
: Specifica un template personalizzato da utilizzare per la conversione.--metadata=KEY:VALUE
: Aggiunge metadati al documento.--pdf-engine=ENGINE
: Specifica il motore per la generazione di PDF (es.pdflatex
,xelatex
,lualatex
).--toc
: Genera un sommario (table of contents).--toc-depth=N
: Specifica la profondità del sommario.--highlight-style=STYLE
: Specifica lo stile di evidenziazione del codice (es.pygments
,tango
,haddock
, ecc.).--filter=FILTER
: Applica un filtro a Pandoc (utilizzato per elaborazioni personalizzate).
Ulteriori informazioni
Per un elenco completo e dettagliato di tutte le opzioni e i comandi, puoi consultare la documentazione ufficiale di Pandoc, disponibile sul sito web di Pandoc: Pandoc User’s Guide.
Questa guida fornisce informazioni approfondite su tutte le funzionalità e le opzioni disponibili, oltre a esempi pratici di utilizzo.
Comandi principali di Pandoc
1. Generare un file DOCX da Markdown
Se hai un file Markdown (input.md
) e desideri convertirlo in un file Word (output.docx
), puoi utilizzare il seguente comando:
pandoc input.md -o output.docx
2. Generare un file DOCX da LaTeX
Se hai un file LaTeX (input.tex
) e desideri convertirlo in un file Word, puoi utilizzare:
pandoc input.tex -o output.docx
3. Generare un file PPTX da Markdown
Se desideri creare una presentazione PowerPoint a partire da un file Markdown, puoi utilizzare il seguente comando:
pandoc input.md -o output.pptx
4. Utilizzare un template per DOCX
Se desideri utilizzare un template personalizzato per il tuo file DOCX, puoi specificarlo con l’opzione --reference-doc
:
pandoc input.md -o output.docx --reference-doc=mytemplate.docx
5. Convertire un file HTML in DOCX
Se hai un file HTML (input.html
) e desideri convertirlo in un file Word, puoi utilizzare:
pandoc input.html -o output.docx
6. Convertire un file RTF in DOCX
Se hai un file RTF (input.rtf
) e desideri convertirlo in DOCX, puoi utilizzare:
pandoc input.rtf -o output.docx
Note aggiuntive
- Assicurati di avere installato Pandoc e, se necessario, anche un motore di conversione per PDF (come
pandoc
supporta la generazione di PDF, ma non è necessario per DOCX e PPTX). - Puoi anche combinare più file in un’unica conversione. Ad esempio, per unire più file Markdown in un unico file DOCX:
pandoc file1.md file2.md -o output.docx
Informazioni sui file e cartelle
Per convertire correttamente un file markdown in altri formati, è necessario che: - nel terminali, bisogna essere nella cartella in cui si trova il file di input altrimenti non avviene la conversione - il file deve avere una sintassi markdown perfetta, altrimenti non viene convertito - il nome del file di input e output non devono contenere spazi, per inserire un file il cui nome ha spazi si deve fare come qui - per convertire un file md in pdf è necessario installare Text Live o MikTex, questo però cnverte solo un file senza formule latex - per convertire un file md che contiene equazioni latex in pdf, coviene convertirlo prima in word e poi in pdf con un editor di documenti
Pandoc: nomi di file con spazi
I nomi dei file in input e output possono contenere spazi quando si utilizza Pandoc, ma è importante gestire correttamente i nomi dei file con spazi nel terminale. Ecco come farlo:
1. Utilizzare le Virgolette
Puoi racchiudere il nome del file tra virgolette per gestire gli spazi. Ad esempio:
pandoc "file con spazi.md" -o "file di output.docx"
2. Utilizzare il Backslash
In alternativa, puoi utilizzare il backslash (\
) per “escapare” gli spazi. Ad esempio:
pandoc file\ con\ spazi.md -o file\ di\ output.docx
Esempio Completo
Supponiamo di avere un file Markdown chiamato documento con spazi.md
e desideri convertirlo in un file DOCX chiamato output finale.docx
. Puoi utilizzare uno dei seguenti comandi:
Con Virgolette
pandoc "documento con spazi.md" -o "output finale.docx"
Con Backslash
pandoc documento\ con\ spazi.md -o output\ finale.docx
TeX Live e MiKTeX
Per convertire un file md in pdf con Pandoc, è necessario avere installato un sistema di distribuzione TeX. Le due distribuzioni più comuni sono:
TeX Live
Installazione su Linux: Puoi installare TeX Live utilizzando il gestore di pacchetti della tua distribuzione. Ad esempio, su Ubuntu puoi usare:
sudo apt install texlive
Se desideri installare anche i pacchetti aggiuntivi, puoi usare:
sudo apt install texlive-full
Installazione su macOS: Puoi installare TeX Live tramite Homebrew:
brew install --cask mactex
Installazione su Windows: Puoi scaricare e installare TeX Live dal sito ufficiale di TeX Live.
MiKTeX
Installazione su Windows: MiKTeX è un’altra distribuzione popolare per Windows. Puoi scaricarlo dal sito ufficiale di MiKTeX.
Installazione su Linux: Puoi installare MiKTeX su Linux seguendo le istruzioni sul sito ufficiale di MiKTeX.
Formattazione YAML in Pandoc Markdown
In Pandoc, puoi usare un blocco YAML metadata all’inizio del file Markdown per specificare informazioni sul documento come il titolo, l’autore, la data e altre impostazioni di formattazione.
1. Struttura di base del blocco YAML
Il blocco YAML si scrive tra ---
all’inizio del file:
---
title: "Titolo del documento"
author: "Nome Cognome"
date: "11 Febbraio 2025"
---
Quando converti il file Markdown in PDF con Pandoc, questi metadati vengono interpretati e usati nel documento finale.
Esempio di comando:
pandoc documento.md -o output.pdf
2. Aggiunta di più autori
Se il documento ha più autori, puoi specificarli come un elenco:
---
title: "Analisi dei dati"
author:
- "Mario Rossi"
- "Giulia Bianchi"
date: "2025-02-11"
---
3. Aggiungere un abstract
Se vuoi includere un riassunto del documento, puoi usare abstract
:
---
title: "Studio sulle onde elettromagnetiche"
author: "Dr. A. Verdi"
date: "Febbraio 2025"
abstract: |
Questo documento analizza la propagazione delle onde elettromagnetiche
in diversi materiali e condizioni ambientali.---
L’abstract verrà incluso all’inizio del PDF generato.
4. Cambiare la lingua del documento
Puoi specificare la lingua con lang
:
---
title: "Documento in Italiano"
author: "Mario Rossi"
lang: "it"
---
Questo è utile per cambiare la sillabazione e altre impostazioni di formattazione nel PDF.
5. Scegliere il motore PDF
Pandoc usa LaTeX per generare i PDF. Puoi specificare quale motore usare (es. xelatex
o lualatex
per supportare meglio caratteri speciali e font personalizzati):
---
title: "Documento con XeLaTeX"
author: "Maria Verdi"
date: "2025-02-11"
pdf-engine: "xelatex"
---
Comando per generare il PDF:
pandoc documento.md -o output.pdf
Se usi xelatex
o lualatex
, puoi anche impostare font personalizzati:
---
title: "Documento con font personalizzato"
author: "Luca Bianchi"
pdf-engine: "xelatex"
mainfont: "Times New Roman"
---
6. Personalizzare la classe LaTeX
Se vuoi usare una classe LaTeX personalizzata (ad esempio, article
, report
, book
), puoi farlo così:
---
title: "Il mio libro"
author: "Giovanni Neri"
documentclass: book
---
Questo cambierà la formattazione nel PDF generato.
7. Aggiungere un TOC (Table of Contents)
Se vuoi un indice automatico:
---
title: "Relazione tecnica"
author: "Francesco Rossi"
toc: true
---
Pandoc genererà automaticamente un indice nel PDF.
8. Impostare la profondità della TOC
Se vuoi impostare la profondita della TOC:
---
title: "Documento con TOC"
author: "Mario Rossi"
toc: true
toc-depth: 2
---
9. Aggiungere numerazione alle sezioni
Se vuoi che le sezioni abbiano numerazione (1. Introduzione
, 2. Metodi
, ecc.), puoi attivarla così:
---
title: "Documento con sezioni numerate"
author: "Elena Bianchi"
number-sections: true
---
### English version
title: Pandoc author: toc: true toc-depth: 2 —
What is Pandoc?
Pandoc is a powerful document conversion tool that allows you to convert files into various formats. It is especially useful for those who work with texts and documents in different formats, such as Markdown, LaTeX, HTML, DOCX, PDF and many others.
Here are some of the main features of Pandoc:
Conversion between formats: Pandoc supports a wide range of input and output formats, allowing you to convert documents from one format to another with ease.
Advanced Markdown: Pandoc extends the standard Markdown language, adding features such as tables, footnotes and citations, making it more powerful for writing complex documents.
Customizable templates: Users can create and use custom templates to control the final appearance of converted documents.
Metadata support: Pandoc allows you to include metadata in your documents, such as title, author, and date, which can be used to automatically generate headings and bibliographies.
Writing tool integration: It can be integrated into various workflows and writing tools, such as text editors and content management systems.
Command line usage: Pandoc is primarily a command line tool, which makes it suitable for automation and integration into scripts and build processes.
In summary, Pandoc is a versatile and powerful tool for anyone who needs to work with documents in different formats, making writing and publishing more fluid and flexible.
Yes, it is possible to integrate Pandoc into VS Codium (or Visual Studio Code) using specific extensions and configurations. While there is no official Pandoc extension, there are a few options you can consider to make it easier to use Pandoc within the editor:
Markdown Extensions: There are several Markdown extensions that can improve your writing experience and can be used in conjunction with Pandoc. For example, extensions like “Markdown All in One” offer advanced features for writing in Markdown.
Integrated Terminal: You can use VS Codium’s integrated terminal to run Pandoc commands directly. Simply open the terminal (with
Ctrl +
) and type Pandoc commands to convert your documents.VS Codium Tasks: You can set up a task in VS Codium to automatically run Pandoc commands. This allows you to perform the conversion with a simple keyboard shortcut. You can do this by creating a
tasks.json
file in your project’s.vscode
folder.Snippets and Shortcuts: You can also create custom snippets or keyboard shortcuts to make it easier to enter Pandoc commands.
Third-Party Extensions: Explore the VS Codium Extensions Marketplace to see if there are any third-party extensions that offer specific integrations with Pandoc.
In summary, while there is no official Pandoc integration in VS Codium, you can still use Pandoc effectively by combining the editor’s features with the terminal and available extensions.
Pandoc offers a wide range of commands and options for converting documents. Below, I provide a list of the main commands and the most common options. Please note that the list is not exhaustive, but covers the most used features.
Basic commands
pandoc [options] [input file] -o [output file]
Common options
-o, --output=FILE
: Specifies the output file.-f, --from=FORMAT
: Specifies the input format (e.g.markdown
,html
,latex
,docx
, etc.).-t, --to=FORMAT
: Specifies the output format (e.g.markdown
,html
,pdf
,docx
, etc.).-s, --standalone
: Creates a standalone document (including header and footer).-V, --variable=VAR:VALUE
: Sets a template variable (e.g.-V title="My title"
).--template=FILE
: Specifies a custom template to use for conversion.--metadata=KEY:VALUE
: Adds metadata to the document.--pdf-engine=ENGINE
: Specifies the engine for generating PDF (e.g.pdflatex
,xelatex
,lualatex
).--toc
: Generates a table of contents.--toc-depth=N
: Specifies the depth of the table of contents.--highlight-style=STYLE
: Specifies the style of highlighting the code (e.g.pygments
,tango
,haddock
, etc.).--filter=FILTER
: Applies a filter to Pandoc (used for custom processing).
More information
For a complete and detailed list of all options and commands, you can consult the official Pandoc documentation, available on the Pandoc website: Pandoc User’s Guide.
This guide provides in-depth information on all available features and options, as well as practical examples of use.
Main Pandoc commands
1. Generate a DOCX file from Markdown
If you have a Markdown file (input.md
) and you want to convert it to a Word file (output.docx
), you can use the following command:
pandoc input.md -o output.docx
2. Generate a DOCX file from LaTeX
If you have a LaTeX file (input.tex
) and you want to convert it to a Word file, you can use:
pandoc input.tex -o output.docx
3. Generate a PPTX file from Markdown
If you want to create a PowerPoint presentation from a Markdown file, you can use the following command:
pandoc input.md -o output.pptx
4. Use a DOCX template
If you want to use a custom template for your DOCX file, you can specify it with the --reference-doc
option:
pandoc input.md -o output.docx --reference-doc=mytemplate.docx
5. Converting an HTML file to DOCX
If you have an HTML file (input.html
) and you want to convert it to a Word file, you can use:
pandoc input.html -o output.docx
6. Converting an RTF file to DOCX
If you have an RTF file (input.rtf
) and you want to convert it to DOCX, you can use:
pandoc input.rtf -o output.docx
Additional notes
- Make sure you have Pandoc installed and, if necessary, also a PDF conversion engine (as
pandoc
supports PDF generation, but it is not necessary for DOCX and PPTX). - You can also combine multiple files into one conversion. For example, to merge multiple Markdown files into a single DOCX file:
pandoc file1.md file2.md -o output.docx
Information about files and folders
To correctly convert a markdown file to other formats, you must: - in the terminal, you must be in the folder where the input file is located, otherwise the conversion will not occur - the file must have perfect markdown syntax, otherwise it will not be converted - the name of the input and output file must not contain spaces, to insert a file whose name has spaces you must do as here - to convert an md file to pdf you must install Text Live or MikTex, but this only converts a file without latex formulas - to convert an md file that contains latex equations to pdf, it is best to convert it first to word and then to pdf with a word processor documents
Pandoc: Filenames with Spaces
Input and output filenames can contain spaces when using Pandoc, but it is important to handle filenames with spaces correctly in the terminal. Here is how to do it:
1. Use Quotation Marks
You can enclose the filename in quotation marks to handle spaces. For example:
pandoc "file with spaces.md" -o "output file.docx"
2. Use Backslash
Alternatively, you can use the backslash (\
) to “escape” spaces. For example:
pandoc file\ with\ spaces.md -o file\ of\ output.docx
Complete Example
Suppose you have a Markdown file called document with spaces.md
and you want to convert it to a DOCX file called final output.docx
. You can use one of the following commands:
With Quotes
pandoc "document with spaces.md" -o "final output.docx"
With Backslash
pandoc document\ with\ spaces.md -o output\ final.docx
TeX Live and MiKTeX
To convert an md file to pdf with Pandoc, you need to have a TeX distribution system installed. The two most common distributions are:
TeX Live
- Installation on Linux: You can install TeX Live using your distribution’s package manager. For example, on Ubuntu you can use:
sudo apt install texlive
If you also want to install the additional packages, you can use:
sudo apt install texlive-full
- Installation on macOS: You can install TeX Live via Homebrew:
brew install --cask mactex
- Installation on Windows: You can download and install TeX Live from the TeX Live official site.
MiKTeX
Installation on Windows: MiKTeX is another popular distribution for Windows. You can download it from the MiKTeX official site.
Installation on Linux: You can install MiKTeX on Linux by following the instructions on the official MiKTeX website.
YAML Formatting in Pandoc Markdown
In Pandoc, you can use a YAML metadata block at the beginning of the Markdown file to specify information about the document such as the title, author, date and other formatting settings.
1. Basic structure of the YAML block
The YAML block is written between ---
at the beginning of the file:
---
title: "Title of the document"
author: "First Name Last Name"
date: "February 11, 2025"
---
When you convert the Markdown file to PDF with Pandoc, this metadata is interpreted and used in the final document.
Command example:
pandoc document.md -o output.pdf
2. Adding multiple authors
If the document has multiple authors, you can specify them as a list:
---
title: "Data Analysis"
author:
- "Mario Rossi"
- "Giulia Bianchi"
date: "2025-02-11"
---
3. Add an abstract
If you want to include a summary of the document, you can use abstract
:
---
title: "Study on electromagnetic waves"
author: "Dr. A. Verdi"
date: "February 2025"
abstract: |
This document analyzes the propagation of electromagnetic waves
in different materials and environmental conditions.
---
The abstract will be included at the beginning of the generated PDF.
4. Change the language of the document
You can specify the language with lang
:
---
title: "Document in Italian"
author: "Mario Rossi"
lang: "it"
---
This is useful for changing hyphenation and other formatting settings in the PDF.
5. Choose the PDF engine
Pandoc uses LaTeX to generate PDFs. You can specify which engine to use (e.g. xelatex
or lualatex
to better support special characters and custom fonts):
---
title: "Document with XeLaTeX"
author: "Maria Verdi"
date: "2025-02-11"
pdf-engine: "xelatex"
---
Command to generate PDF:
pandoc document.md -o output.pdf
If you use xelatex
or lualatex
, you can also set custom fonts:
---
title: "Document with custom font"
author: "Luca Bianchi"
pdf-engine: "xelatex"
mainfont: "Times New Roman"
---
6. Customize the LaTeX class
If you want to use a custom LaTeX class (for example, article
, report
, book
), you can do it like this:
---
title: "My book"
author: "Giovanni Neri"
documentclass: book
---
This will change the formatting in the generated PDF.
7. Add a TOC (Table of Contents)
If you want an automatic table of contents:
---
title: "Technical report"
author: "Francesco Rossi"
toc: true
---
Pandoc will automatically generate a table of contents in the PDF.
8. Set TOC depth
If you want to set the depth of the TOC:
---
title: "Document with TOC"
author: "Mario Rossi"
toc: true
toc-depth: 2
---
9. Add numbering to sections
If you want sections to have numbering (1. Introduction
, 2. Methods
, etc.), you can enable it like this:
---
title: "Document with numbered sections"
author: "Elena Bianchi"
number-sections: true
---
Commenti
Posta un commento