True WYSIWYG LaTeX System
Windows     Mac     Linux  

Using Pygments in BaKoMa TeX.

This explanation is suitable for BaKoMa TeX 11.72 and later.

Preface.

Pygments is a generic syntax highlighter for a wide range of (over 300) languages and other text formats.
Output formats: HTML, RTF, LaTeX and ANSI sequences. It is usable as a library and command-line tool (pygmentize).

Several LaTeX packages use command-line tool pygmentize.

PackageCentaurTeXWordSizeYear/AuthorCommands
minted++
Efficient
Caching
1190
lines
2013-2017
Geoffrey M. Poore
\begin{minted} ... \end{minted} - embedded codes;
\mint{lang}|...| - short codes;
\inputminted[hoptionsi]{hlanguagei}{hfilenamei} - import entire file.
The package uses many redundand packages, code, and checks.
However, unlike to other (below) packages
it includes caching which improve responce under TeXWord.
texments++40
lines
2008
Marek Kubica
\includecode - highlighting files,
\begin{pygmented} ... \end{pygmented} - embedded codes,
\pygment{lang}{...} - short codes.
If you want to learn how to integrate Pygments with LaTeX. It is the best example.
verbments++150
lines
2011
Dejan Zivkovic
\begin{pyglist} ... \end{pyglist} - embedded codes;

Recommendations

Attention:
Pygmentize does not track synchronization information of source with output.
For this reason, editing the listing in the Page Window is not possible.

Installing Pygments

under Windows
To install Pygments under Windows do:
  1. Download and install a Python 3.X version from https://www.python.org/downloads
  2. Open a shell in administrator mode and issue pip install Pygments.

    NOTE: Before you must find pip.exe. So, on my computer it was at:
    C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python36\Scripts\
    So, I run FAR :=) As Administrator (I am not sure that it was required, because python was installed into user folder. However, in shared installations it will be required.)
    Then I find pip.exe and jump to the folder.
    Then I run the command 'pip install Pygments'.
    At end of installation I see 'pygmentize.exe in the same folder. Remember it !

Invoking Pygments from BaKoMa TeX.

minted
Let us consider one test file: minted.tex

\documentclass{article}

\usepackage{minted}

\begin{document}

Test of minted packages with on C language

\begin{minted}{c}
# include "stdio.h"

int main( int ac, char **av )
{
   int i;

   for ( i = 0 ; i < ac ; i ++ )
     fprintf(stderr,"arg[%d] = '%s'\n",i,av[i]);

   return 0;
}
\end{minted}

End

\end{document}

In this, first run, listing is not shown.
However, take attention on alarm button at right bottom corner of main window.
Appearance of this button indicates that TeX macros try to run some programs whose were declined by BaKoMa TeX.

Clicking the button will open 'External Programs' dialog:

We see that TeX package minted.sty try to run one program pygmentize.
TeX can't recognize what package try to run this program, but we know that it is minted.sty.

We see that location of the program is not found.
However I have remembered path to pygmentize.exe.
To choose executable file, I click button and select location of pygmentize program.

So, I see [Enable] button is now enabled.

I click it and see that program is now allowed.

I pass the document second time,
I see that pygmentize is run.
And ... Highlighted listing is appeared in our document.

The End.