4

On my Windows 7 laptop with the MikTeX-21.6 installed, I needed to use the minted package which uses the Python's Pygments module so I've installed Pygments-2.9.0 (the latest version) and it works perfectly (I've pygmented a basic C file with pygmentize -l c -f latex -P commandprefix=PYG -F tokenmerge main.c and its output is the same as the reference sample) The path of the pygmentize.exe is set correctly in the Windows path.

When I try to compile the following .tex file:

xelatex.exe -shell-escape pygment_SAMPLE.tex

\documentclass{article}
\RequirePackage[cache=false]{minted}
\usepackage[cache=false]{minted}
\begin{document}
\begin{minted}[fontsize=\small]{c}
int main() {
  printf("hello, world");
}  
\end{minted}
\end{document}

it prompts :\minted@apppathifexists=

I enter t then it stops with:

! Package minted Error: Missing Pygments output; \inputminted was
probably given a file that does not exist--otherwise, you may need
the outputdir package option, or may be using an incompatible build tool,
or may be using frozencache with a missing file.

The problem seems to revolve around those lines:

for ^%i in (pygmentize.exe pygmentize.bat pygmentize.cmd) do set > pygment_SAMPLE.aex <nul: /p x=^%~$PATH:i>> pygment_SAMPLE.aex

Windows 7's failure to correctly process this line or the way the Windows 7 handles the paths or file permissions inside the minted context.

In order to debug this problem I've tried uncommenting the line 775 at minted.sty

               % For debugging, uncomment: %%%%
this line -->  % \immediate\typeout{\minted@cmd}%
               % %%%%

But it had no effect. I guess the minted.sty must be rebuilt / reinstalled and I don't know the internals of the .tex language.

I've posted this issue on the github issues page Win 10 - Texlive Failed to find installed pygmentize #280 and there they've suggested that I post this issue on StackOverflow so here you are: How to make the minted work correctly on Windows 7? Note that this issue affects Windows 10, too.

Update with extra info:

After adding these into the c:/Program Files/miktex-21.6/texmfs/config/miktex/config/miktex.ini

ShellCommandMode = Restricted
AllowedShellCommands[] = miktex-bibtex
AllowedShellCommands[] = miktex-bibtex8
AllowedShellCommands[] = miktex-epstopdf
AllowedShellCommands[] = miktex-gregorio
AllowedShellCommands[] = miktex-kpsewhich
AllowedShellCommands[] = miktex-makeindex
AllowedShellCommands[] = bibtex
AllowedShellCommands[] = bibtex8
AllowedShellCommands[] = extractbb
AllowedShellCommands[] = findtexmf
AllowedShellCommands[] = gregorio
AllowedShellCommands[] = kpsewhich
AllowedShellCommands[] = makeindex
AllowedShellCommands[] = texosquery-jre8
AllowedShellCommands[] = pygmentize

$ xelatex --restrict-write18 pygments_SAMPLE.tex -shell-escape

brings up with the same prompt:

C:\Users\Lars
>set  /p x=C:\Program Files\python-3.5.0\Scripts\pygmentize.exe 0<nul: 1>>pygments.aex

C:\Users\Lars
>set  /p x= 0<nul: 1>>pygments.aex

C:\Users\Lars
>set  /p x= 0<nul: 1>>pygments.aex

\minted@apppathifexists=

and whatever I enter into the \minted@apppathifexists= doesn't matter it ends up with the same error message.

1 Answer 1

2

First, make sure that the directory with the pygmentize executable is in your PATH (which you can edit under “Environment Variables” in System Properties > Advanced). You will also need to run your TeX program with the --shell-restricted option and edit your texmf.cnf to allow this specific program to run, or else throw caution to the wind and run with --shell-escape.

The default texmf.cnf in TeX Live 2021 says that pygmentize is not declared in shell_escape_commands by default because of concerns about the security of its filter feature. If you do want to change this, you would add

shell_escape_commands = \
bibtex,bibtex8,\
extractbb,\
gregorio,\
kpsewhich,\
makeindex,\
repstopdf,\
r-mpost,\
texosquery-jre8,\
pygmentize,\
%

to the custom texmf.cnf in texlive/YYYY/, not the one in texlive/YYYY/texmf-dist/web2c/.

On MikTeX, you probably instead want to run TeX wirh --restrict-write18 and run initexmf to modify miktex.ini. You would want to add a new AllowedShellCommands[] = pygmentize line.

7
  • Thank you for the answer. There's no texmf.cnf in the Miktext installation folder but there is a miktex.ini as c:/Program Files/miktex-21.6/texmfs/config/miktex/config/miktex.ini which have entries like [Core] LastUserMaintenance=1623612020 and [Setup] LastUserDiagnose=1623612025 where to enter the specific program ? pygmentize is already in path. Jun 16, 2021 at 14:16
  • I use TeX Live rather than MikTeX, but does a file search find a texmf.cnf anywhere?
    – Davislor
    Jun 16, 2021 at 14:43
  • I've already searched. No file named texmf with an extension of .cnf or .ini There are about 360 files with the extension .ini such as xelatex.ini latex.ini latex209.ini tex.ini lualatex.ini etc which makes it hard to decide which one to edit. Jun 16, 2021 at 14:59
  • @LarsMalmsteen Okay, I think I found the instructions for MikTeX. I don’t have a copy to test, however.
    – Davislor
    Jun 16, 2021 at 16:04
  • Tried with the --restrict-write18 and --shell-restricted and their combinations. No change in situation. I've added AlloweShellCommands[] = pygmentize under the [CORE] section in miktex.ini again no change in situtation. When I add the shell_escape_commands = ... into miktex.ini it gives error="invalid value definition" Segmentation fault The miktex.ini doesn't accept such a value, it seems (Update: the shell_escape_commands belongs to the TeX Live not MiKTeX) Jun 16, 2021 at 22:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .