# How to install syntax highlight package minted on Windows 7?

I followed the instruction from this link: http://tug.ctan.org/tex-archive/macros/latex/contrib/minted/

Firstly, I install Python 2.7, then create a folder named Scripts in the directory:

C:\Python27


So I got C:\Python27\Scripts Then I create a file named pygmentize.cmd with the content:

@echo off
set PYTHONPATH=C:\Python27
%PYTHONPATH%\python.exe %PYTHONPATH%Scripts\pygmentize %*


At this point, I already set the path environment variable to C:\Python27 and C:\Python27\Scripts.
Next I installed setuptools-0.6c11.win32-py2.7.exe (md5) from http://pypi.python.org/pypi/setuptools And install Pygments with the following command

easy_install Pygments


Next I include the line \usepackage{minted} to let TexMaker do the installation.

Inside TexMaker, I also change the PdfLaTex option to: pdflatex -shell-escape -interaction=nonstopmode %.tex

Then I tried out a simple example:

\documentclass[12pt,letterpaper]{article}
\usepackage[latin1]{inputenc}
\usepackage[left=1in,right=1in,top=1in,bottom=1in]{geometry}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{minted}

\begin{document}
\begin{minted}{python}
def boring(args = None):
pass
\end{minted}
\end{document}


And the compiler generated these error:

!Emergency stop.<read 2> \TestAppExists{pygmentize}
!==> Fatal error occured, no output PDF file produced!


I guessed the pygmentize was not installed properly so TexMaker wasn't able to run it. I read the instruction over, and couldn't figure out what could cause these errors? Has anyone done it before could share me some lights?

Thank you,

-

On my Windows 7 system, the following got things working:

That is it install-wise: the current Pygmentize does come with a Windows executable. You can test this by doing pygmentize -V at the Command Prompt.

What I then found is that the test that minted uses for Pygmentize on Windows is broken. So I used the lines

\newcommand\TestAppExists[3]{#2}
\usepackage{minted}


to bypass the test (this basically forces the TRUE branch). The example document then compiles fine.

-
@Konrad Rudolph: Without the fix for \TestAppExists I get TeX asking for \@apppathifexists=, which does not much good! –  Joseph Wright Jul 19 '11 at 8:04
@Chan: Just to point out that I'm using TeX Live 2010. I don't think this should make too much difference to the result, although there are occasional differences in file handling between TeX Live and MiKTeX. –  Joseph Wright Jul 19 '11 at 8:06
Thank you for your solution. I think I got all the steps set up correctly, except the fix for \newcommand. I wonder where should I add these two lines? inside my .tex or inside the minted.sty. I added in my .tex and I got another error. –  Chan Jul 20 '11 at 2:42
I tried out your solution on Ubuntu and it worked perfectly. I still couldn't figure out why it was broken on Windows :(. –  Chan Jul 20 '11 at 4:02
@Chan: On my system, I added the \newcommand part in the main .tex file, just before loading minted. That was because my initial trial failed to work, with TeX waiting for some kind of keyboard input. The Pygmentize installation itself went fine, as checked at the Command Prompt using pymgmetize -V. –  Joseph Wright Jul 21 '11 at 6:53

The problem might be due to issues with setuptools (for example with UAC).

Here is an installation procedure which is working for me:

1. Install Python 2.7

2. Install distribute (replacement for setuptools because it is buggy and no more maintained)

3. Add C:\Python27\Scripts to your PATH

4. Install pip: easy_install pip

5. Install pygments: pip install pygments

These steps create a pygmentize.exe, so there is no need to create the batch file.

-

Re-installing minted fixed the issue. To uninstall a package in MikTex, go to Package Manager (Admin). Reinstall minted under TexMaker, after that I don't even need the \newcommand\TestAppExists[3]{#2}. Just make sure you add the scripts pygmentize.cmd to the C:\Python27\Scripts\ with the content:

@echo off
set PYTHONPATH=C:\Python27
%PYTHONPATH%\python.exe %PYTHONPATH%\Scripts\pygmentize %*


Note: The one in the instruction document missed a \ after %PYTHON%. Further, this solution only works under Windows environment, for Linux variants, you have to go with Joseph Wright's solution.

-

Here is another easy way how to set up Pygments on Windows 7 so that it works with minted:

1. Install Python 3.4 (PATH can be set during installation)
2. From a command prompt, run pip3.exe install Pygments
3. Done, minted should now work

This is easier than other solutions, because Python 3.4 comes with the package manager pipalready included, see http://www.python.org/dev/peps/pep-0453/ .
Installing Pygments will create a pygmentize.exe in the Pythons Scripts directory. Of course, pdfLaTeX (or whatever engine you use) still has to be called with the -shell-escape option.

-
You should have mentioned, though, that Python 3.4 is in the moment still in Beta state. –  Speravir Jan 17 at 21:16
You are right, and thanks for adding that information. A stable version will probably not be released before March 2014. That said, the current beta is stable enough to pygmentize my code examples like a charm. –  matth Jan 17 at 21:40

So this is a bit late, but I got everything to work on Windows 7 and I can compile and create my pdf within TeXworks using MiKTeX. (I apologize for improper formatting. Doing this late at night and have not done this before, but I wanted to type it somewhere before I forget)

1. Install Python 2.7
2. Install setuptools-0.6c11.win32-py2.7.exe
3. Add C:\Python27\Scripts to your PATH (just google how to do this if you don't know how)
4. Navigate to your Scripts folder and run "easy_install Pygments" in the command prompt
5. Make a file called "pygmentize.cmd" in the Scripts folder with the contents: @echo off set PYTHONPATH=C:\Python27 %PYTHONPATH%\python.exe %PYTHONPATH%\Scripts\pygmentize %*

As of now, if you run "pdflatex --shell-escape myFileName.tex" in the command prompt it will work. If you want it to work within TeXworks (and I assume other similar programs), you have to make one extra step.

1. Click edit-->preferences, then go to the Typesetting tab. Click the "+" and add your Scripts directory ("C:\Python27\Scripts")

Now it works! Yay! With this set of steps, the \newcommand\TestAppExists[3]{#2} is not needed.

-
Welcome to TeX.sx! –  mafp Apr 16 '13 at 9:17