Quick Start Guide to Pandoc File Converter on FreeBSD

Pandoc is a command line tool for converting files from one markup language to another. Markup languages use tags to annotate parts of a document. Commonly used markup languages include Markdown, ReStructuredText, HTML, LaTex, ePub, and Microsoft Word DOCX.

Pandoc is an open source command line utility that functions as a format converter, converting files between markup languages. It was created in 2006 by John MacFarlane and written in Haskell. This tool is compatible with Windows, CentOS, and most Unix-like systems. A markup language is an annotation system used to format text in a visually distinct way. In short, markup languages are essential to making the Internet beautiful.

Markup languages use tags to annotate parts of a document. Commonly used markup languages include Markdown, ReStructuredText, HTML, LaTex, ePub, and Microsoft Word DOCX. In plain English, Pandoc lets you convert multiple files from one markup language to another. Common examples include converting Markdown files to presentations, LaTeX, PDF, or even ePub.

Here are some examples of markup languages:
Markdown (considered lightweight markup)

pandoc installation

The utility or application used when handling several files using different formats is Pandoc. Pandoc's goal is to simply convert the markup of any document without changing the source content. This article will provide an overview of how to install Pandoc on FreeBSD 13.2 Stable.

On FreeBSD you can install Pandoc with FreeBSD Pckage pkg or with FreeBSD ports repository. In this article we will try to install Pandoc via pkg, apart from being easy, pkg also offers speed of installation without reducing the repository required by the application.

To run Pandoc on a FreeBSD system you have to install several applications that Pandoc needs to run on a FreeBSD system. You follow the following script to install Pandoc on FreeBSD.

root@router2:~ # pkg update
root@router2:~ #
pkg upgrade -y
root@router2:~ # pkg install ghc
root@router2:~ #
pkg install hs-cabal-install

Other Pandoc dependencies that you must install are tex-xetex and texlive-full. These dependencies are used to run latex and pdf-engine xelatex.

root@ns7:~ # pkg install texlive-full
root@ns7:~ # pkg install print/tex-xetex

If the supporting application has been installed, continue by installing Pandoc. To install pandoc, follow the following script.

root@router2:~ # pkg install hs-pandoc

After Pandoc is installed on your FreeBSD system. Now Pandoc is ready to be used to convert files.

How to Use Pandoc Converter

Below we will provide several examples of how to use the Pandoc application as a file converter program. Create a biblio.bib file in the /root folder, we will convert this file into an html file and we will name it example24a.html. The script below is an example of the biblio.bib file.

author="John Doe",
title="First Book",
publisher="Cambridge University Press"

author="John Doe",
journal="Journal of Generic Studies",

author="John Doe and Jenny Roe",
title="Why Water Is Wet",
booktitle="Third Book",
editor="Sam Smith",
publisher="Oxford University Press",

To change a file with the bib extension to html format, use the following script.

root@router2:~ # pandoc biblio.bib --citeproc -s -o biblio.html
Below you will be given several examples of Pandoc scripts for converting several types of file formats, you can practice these scripts directly.

root@router2:~ # pandoc MANUAL.txt -o example1.html
root@router2:~ #
pandoc -s MANUAL.txt -o example2.html
root@router2:~ #
pandoc -s --toc -c pandoc.css -A footer.html MANUAL.txt -o example3.html
root@router2:~ #
pandoc -s MANUAL.txt -o example4.tex
root@router2:~ #
pandoc -s example4.tex -o example5.text
root@router2:~ #
pandoc -s -t rst --toc MANUAL.txt -o example6.text
root@router2:~ #
pandoc -s MANUAL.txt -o example7.rtf
root@router2:~ #
pandoc -t beamer SLIDES -o example8.pdf
root@router2:~ #
pandoc -s -t docbook MANUAL.txt -o example9.db
root@router2:~ #
pandoc -s -t man pandoc.1.md -o example10.1
root@router2:~ #
pandoc -s -t context MANUAL.txt -o example11.tex
root@router2:~ #
pandoc -s -r html http://www.gnu.org/software/make/ -o example12.text
root@router2:~ #
pandoc MANUAL.txt --pdf-engine=xelatex -o example13.pdf
root@router2:~ #
pandoc example15.md -o example15.ipynb
root@router2:~ #
pandoc math.text -s -o mathDefault.html
root@router2:~ #
pandoc math.text -s -o mathDefault.html

To make it easier for you to learn Pandoc, we have prepared several files stored in the "/usr/local/www/data" directory. Use the ls command to view the entire contents of the file.

root@router2:/usr/local/www/data # ls
MANUAL.txt      README.md       Result          index.html      run.txt         sample.odt      sample1.epub    samplepaper.tex
a. Convert a web page (html) to docx

root@router2:/usr/local/www/data # pandoc -s -f html -t docx -o /usr/local/www/data/Result/unixBSDfile.docx http://www.baidu.com
b. Convert a html to markdown

root@router2:/usr/local/www/data # pandoc -f html -t markdown -o /usr/local/www/data/Result/unixBSDfile1.md https://www.unixwinbsd.site/2024/01/google-indexing-api-with-go-lang-for.html
root@router2:/usr/local/www/data # pandoc -f html -t markdown -o /usr/local/www/data/Result/unixBSDfile2.md index.html
c. Convert a markdown to mediawiki

root@router2:/usr/local/www/data # pandoc -f markdown -t mediawiki -o /usr/local/www/data/Result/unixBSDfile.wiki README.md
d. Convert a txt/tex to json

root@router2:/usr/local/www/data # pandoc run.txt -f latex+raw_tex -o /usr/local/www/data/Result/unixBSDfileTXT.json
root@router2:/usr/local/www/data # pandoc samplepaper.tex -f latex+raw_tex -o /usr/local/www/data/Result/unixBSDfileTEX.json
e. Convert a epub to pdf

root@router2:/usr/local/www/data # pandoc -f epub sample1.epub -t latex -s -o /usr/local/www/data/Result/unixBSDfile.pdf --pdf-engine=xelatex
f. Convert a txt to db

root@router2:/usr/local/www/data # pandoc -s -t docbook MANUAL.txt -o /usr/local/www/data/Result/unixBSDfile.db
g. Convert a odt to markdown md

root@router2:/usr/local/www/data # pandoc -o /usr/local/www/data/Result/unixBSDfile.odt -t markdown README.md
Let's look at the contents of the directory from the conversion results above.

root@ns7:/usr/local/www/data # cd Result
root@ns7:/usr/local/www/data/Result # ls
unixBSDfile.db          unixBSDfile.pdf         unixBSDfile1.md         unixBSDfileTEX.json
unixBSDfile.docx        unixBSDfile.wiki        unixBSDfile2.md         unixBSDfileTXT.json
Pandoc is often defined as a universal document converter, Pandoc is an open source software program for file conversion. If you need to convert files from any format imaginable to another, Pandoc is the answer. Pandoc shines best when used to convert file types such as Markdown, Microsoft Word (.docx), and XML into easier-to-use documents and markup languages, including PDF and HTML.

For further information about how to use Pandoc, you can read the official website: https://pandoc.org/demos.html.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post