minted
is a LaTeX package that allows syntax highlighting in your LaTeX source code using the Pygments library. You can read more about it and see some examples at github.com/gpoore/minted
Installing dependencies
You will need Pygments, the syntax highlighter used by minted
. This can be done by running
sudo easy_install Pygments
in a Terminal window. Please see pygments.org/download/
Shell Escape
minted
requires Shell Escape to be enabled. This is a potential security hole and is not enabled by default by Texifier. To enable Shell escape open Preferences, switch to the Typesetting pane and check the -shell-escape box. In Texifier macOS 1.8, minted
will be detected by Texifier automatically and a suggestion dialogue will be presented to you to this effect.
Typesetting while hiding intermediate files
By default Texifier invokes LaTeX in such a way that all intermediate files are kept hidden out of sight in the .texpadtmp
directory (a hidden directory at the same path as the root file). Unfortunately the minted
package requires that this directory must be defined as an option to its \usepackage{minted}
command. This may be done by modifying the command to
\usepackage[outputdir=.texpadtmp]{minted}
An alternative is to turn off .texpadtmp
. This may be done by opening preferences, choosing the typesetting pane, and unchecking “Hide Intermediate Files”.
An example
This simple example will print the included C++ code with syntax highlighting in your PDF. Note the use of correct options in \usepackage[outputdir=.texpadtmp]{minted}
to make minted
work with Texifier’s .texpadtmp
.
\documentclass[12pt,a4paper]{article} \usepackage[utf8]{inputenc} \usepackage[outputdir=.texpadtmp]{minted} \begin{document} \begin{figure}[h!tb] \caption{helloworld.cpp} \begin{minted}[linenos=true]{cpp} int main() { // code } \end{minted} \end{figure} \end{document}