[Tex/LaTex] Rendering VHDL in latex

codelistingspackagesrendering

I have a VHDL code which I want to insert into my latex document.
I need a package that takes care of syntax highlighting, indentation etc.
Is there a package which serves this purpose?

Best Answer

The minted package includes support for VHDL code. It uses the Python module Pygments to provide syntax highlighting, and Pygments supports VHDL.1

Once it’s installed, you get syntax highlighting, which can be configured in lots of ways (see the package documentation). You'll also need to use the -shell-escape flag when you run the file, since LaTeX is calling an external program (Pygments) to do the highlighting.

You can either type (VHDL) code directly into the document, using \begin{minted}{vhdl} ... \end{minted} or use \inputminted{vhdl}{somefile.vhdl} to include code from an external file:

Here's a minimal example:

\documentclass{article}

\usepackage{minted}

\begin{document}

This is some VHDL code:

\begin{minted}{vhdl}
process
begin
  CLK <= '1'; wait for 10 NS;
  CLK <= '0'; wait for 10 NS;
end process;
\end{minted}

and here I can drop in an external file:

\inputminted{vhdl}{wikipedia.vhdl}

\end{document}

I'd never heard of VHDL before, so the example code is taken from the Wikipedia page for VHDL.

This is what you get with those default settings:

enter image description here

The documentation (available on GitHub) goes into much more detail about how to customise the syntax highlighting, style, layout and so on.


1 You can check if a language is supported by Pygments by running

pygmentize -L lexers

at a command line and inspecting the output. Running on my machine, I get this (as part of a much longer output):

* vhdl:
    vhdl (filenames *.vhdl, *.vhd)