gpoore / minted

minted is a LaTeX package that provides syntax highlighting using the Pygments library. Highlighted source code can be customized using fancyvrb.
1.73k stars 125 forks source link

Failed Compilation with MikTeX on windows #386

Closed ohly87 closed 2 months ago

ohly87 commented 5 months ago

Hello, I cannot use minted to format a formula in beamer class on windows using miktex. I made an example (minimalbeispiel.tex):

\documentclass{beamer} \usepackage[cache=false]{minted} \BeforeBeginEnvironment{minted}{\vspace{-5pt}} \AfterEndEnvironment{minted}{\vspace{-20pt}\par} \setminted[modelica]{fontsize=\scriptsize, linenos=true, breaklines=true, framerule=0pt, framesep=1.5pt, bgcolor=gray!10, highlightcolor=orange!50} \setmintedinline[modelica]{fontsize=\normalsize} \usetheme{default} \title{Modelica} \begin{document} \begin{frame}[fragile]{Minimal Example} \begin{minted}[linenos=true,breaklines=true,bgcolor=gray!10,highlightcolor=orange!50]{modelica} model FirstOrder Real x; equation der(x) = 1 - x; end FirstOrder; \end{minted} \end{frame} \end{document}

I run this code in command window using "xelatex -shell-escape minimalbeispiel.tex" I enabled the advanced debugging information in minted and got the following error: "pygmentize -l "modelica" -f latex -P commandprefix=PYG -F tokenmerge -P stripnl="False" -o minimalbeispiel.out.pyg minimalbeispiel.pyg Error: Invalid value 'False -o minimalbeispiel.out.pyg minimalbeispiel.pyg' for option stripnl; use 1/0, yes/no, true/false, on/off"

When I manually execute the command, minimalbeispiel.pyg is correctly converted to minimalbeispiel.out.pyg

I updated all packages and don't know where to look anymore. The example works on a colleagues Linux OS. I cannot get it to work on my MiKTeX&Anaconda on windows. It would help to know if other windows users can correctly execute the example.

gpoore commented 5 months ago

Which version of Pygments are you using? You can run pygmentize -V to get the version.

This works for me under Windows with TeX Live and Pygments 2.15.1.

ohly87 commented 5 months ago

Thanks for getting back to me. I also have Pygments 2.15.1. I now understand that the problem is general and has nothing to do with my example. The minimal introductory example from the documentation produces the same error. It does work on Overleaf. I will try Tex Live now and see what happens.

muzimuzhi commented 5 months ago

I enabled the advanced debugging information in minted and got the following error: "pygmentize -l "modelica" -f latex -P commandprefix=PYG -F tokenmerge -P stripnl="False" -o minimalbeispiel.out.pyg minimalbeispiel.pyg Error: Invalid value 'False -o minimalbeispiel.out.pyg minimalbeispiel.pyg' for option stripnl; use 1/0, yes/no, true/false, on/off"

Looks like a quoting problem. It seems to me the " just before pygmentize is suspicious. Can you share the complete log file?

ohly87 commented 5 months ago

sorry, that was me misquoting i think. i tried it with texlive and a different python distribution, same error. i try to be more systematic with my error report. i just made a min.tex file from the example from the documentation, section 3.2 i am running the windows command window as administrator.

pygmentize -V gives the following output: Pygments version 2.15.1, (c) 2006-2023 by Georg Brandl, Matthäus Chajdas and contributors.

xelatex -version gives the following ouput: MiKTeX-XeTeX 4.10 (MiKTeX 24.1) © 1994-2008 SIL International, © 2009-2023 Jonathan Kew, © 2010-2012 Hàn Thế Thành, © 2012-2013 Khaled Hosny TeX is a trademark of the American Mathematical Society using bzip2 version 1.0.8, 13-Jul-2019 compiled with curl version 8.4.0; using libcurl/8.4.0 Schannel compiled with expat version 2.5; using expat_2.5.0 compiled with fontconfig version 2.13.1; using 2.13.1 compiled with freetype2 version 2.12.1; using 2.12.1 compiled with graphite2 version 1.3.14; using 1.3.14 compiled with harfbuzz version 8.2.1; using 8.2.1 compiled with icu version 74.2; using 74.2 compiled with jpeg version 9.5 compiled with liblzma version 50040002; using 50040002 compiled with libpng version 1.6.39; using 1.6.39 compiled with libressl version LibreSSL 3.8.1; using LibreSSL 3.8.1 compiled with MiKTeX Application Framework version 4.8; using 4.8 compiled with MiKTeX Core version 4.23; using 4.23 compiled with MiKTeX Archive Extractor version 4.1; using 4.1 compiled with MiKTeX Package Manager version 4.10; using 4.10 compiled with pplib version v2.05 less toxic i hope using teckit version 2.4 compiled with uriparser version 0.9.7 compiled with zlib version 1.2.13; using 1.2.13

i compile with the command: xelatex --shell-escape min.tex

i will append the log file.

thank you for the support! min.log

muzimuzhi commented 5 months ago

Excerpted from log,

pygmentize -l "c" -f latex -P commandprefix=PYG -F tokenmerge -P stripnl="True"
 -o min.out.pyg min.pyg
runsystem(pygmentize -l "c" -f latex -P commandprefix=PYG -F tokenmerge -P stri
pnl="True" -o _minted-min/7AA725D760D07893EF77B2DA22ECFD635061F79E82246538E85B9
D541DA235D3.pygtex min.pyg)...executed.

! 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.

See the minted package documentation for explanation.

Does manual execution of

pygmentize -l "c" -f latex -P commandprefix=PYG -F tokenmerge -P stripnl="True" min.pyg

succeed? min.pyg can be replaced with any file name which contains some (dummy) LaTeX content.

ohly87 commented 5 months ago

when i run

xelatex -shell-escape min.tex

and exit by pressing "x"+enter after the error message, there is a min.pyg file in the folder, otherwise the compiler deletes it. once min.pyg is there and i execute

pygmentize -l "c" -f latex -P commandprefix=PYG -F tokenmerge -P stripnl="True" min.pyg

the following output is produced:

\begin{Verbatim}[commandchars=\{}] \PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{main}\PYG{p}{()}\PYG{+w}{ }\PYG{p}{\PYGZob{}} \PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}hello, world\PYGZdq{}}\PYG{p}{);} \PYG{k}{return}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{;} \PYG{p}{\PYGZcb{}} \end{Verbatim}

so to my understanding, yes, if i manually execute the code snippet, it succeeds.

ohly87 commented 5 months ago

I see that the log doesn't provide the full error message. this is the console output:

(C:\Users\ohly\AppData\Local\Programs\MiKTeX\tex/latex/base\ts1cmr.fd) (_minted-min/default.pygstyle) pygmentize -l "c" -f latex -P commandprefix=PYG -F tokenmerge -P stripnl="True" -o min.out.pyg min.pyg Error: Invalid value 'True -o _minted-min/7AA725D760D07893EF77B2DA22ECFD635061F79E82246538E85B9D541DA235D3.pygtex min.pyg' for option stripnl; use 1/0, yes/no, true/false, on/off

! 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.`

DE3000 commented 4 months ago

I am also experiencing the same issue.

I have updated the MikTeX as a whole and the error popped up after the update. I have tested just downgrading the minted package but that didn't change the error.

muzimuzhi commented 4 months ago

@ohly87 @DE3000 Can you try this example?

\begin{filecontents}[noheader,force]{\jobname.abc}
def inc(x):
  return x + 1
\end{filecontents}

\documentclass{article}
\usepackage{minted}

\begin{document}
\ShellEscape{%
  pygmentize
  -l "python" -f latex -P commandprefix=PYG -F tokenmerge -P stripnl="True"
  -o _minted-\jobname/0011AABB.pygtex
  \jobname.abc}
\end{document}

If it compiles, then how about replacing 0011AABB.pygtex with a full-length hash name 7AA725D760D07893EF77B2DA22ECFD635061F79E82246538E85B9D541DA235D3.pygtex?

Edit: pygmentize -l "c" changed to pygmentize -l "python".

DE3000 commented 4 months ago

The example as is fails with the same message:

Error: Invalid value 'True -o _minted-min2/0011AABB.pygtex min2.abc' for option stripnl; use 1/0, yes/no, true/false, on/off

Removing the quotes around stripnl="True" results in:

Error: no lexer for alias 'c -f latex -P commandprefix=PYG -F tokenmerge -P stripnl=True -o _minted-min2/0011AABB.pygtex min2.abc' found

However taking out the quotes from the command:

pygmentize
  -l c -f latex -P commandprefix=PYG -F tokenmerge -P stripnl=True
  -o _minted-\jobname/0011AABB.pygtex

This compiles fine, even with the full-length hash name.

I was testing out a few other things with the original MWE in the first post, adding \setminted{stripnl=true} to the MWE results in the following debug output from minted:

pygmentize -l "modelica" -f latex -P commandprefix=PYG -F tokenmerge -P stripnl
="True" -P stripnl="False" -o min.out.pyg min.pyg

Notice the double stripnl in the command.

muzimuzhi commented 4 months ago

Then this is more like a MiKTeX problem, which can/should be reported to https://github.com/MiKTeX/miktex/issues.

It seems the culprit is that MiKTeX quotes the whole command inside "...".

muzimuzhi commented 4 months ago

To double check, could you test what does \ShellEscape{mkdir "dirname with space"} create?

DE3000 commented 4 months ago

To double check, could you test what does \ShellEscape{mkdir "dirname with space"} create?

Creates the directory without issue.

muzimuzhi commented 4 months ago

A single directory named dirname with space is created? Maybe quotes need to be in the middle, like

\ShellEscape{mkdir "dirname with space"}
\ShellEscape{mkdir dirname}
\ShellEscape{del "dirname with space" dirname}

I might find time to play with it myself, by installing MiKTeX in a GitHub Actions' Windows runner.

DE3000 commented 4 months ago

A single directory named dirname with space is created?

Yes.

I tested with the following:

\ShellEscape{mkdir "dirname with space"}
\ShellEscape{copy nul "dirname with space/test.txt"}
\ShellEscape{robocopy "dirname with space" dirname}

Robocopy shows a helpful information panel when it's run:

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows
-------------------------------------------------------------------------------

  Started : Friday, 09 February 2024 21:43:34
   Source : E:\temp\minted-test\dirname with space dirname\
     Dest -

    Files : *.*

  Options : *.* /DCOPY:DA /COPY:DAT /R:1000000 /W:30

------------------------------------------------------------------------------

The source folder is taken as dirname with space dirname with no destination.

Running the robocopy command in cmd shows:

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows
-------------------------------------------------------------------------------

  Started : Friday, 09 February 2024 21:43:40
   Source : E:\temp\minted-test\dirname with space\
     Dest : E:\temp\minted-test\dirname\

    Files : *.*

  Options : *.* /DCOPY:DA /COPY:DAT /R:1000000 /W:30

------------------------------------------------------------------------------

Where the source and destination are correct.

muzimuzhi commented 3 months ago

@ohly87 Can you check if the problem is resolved in MiKTeX 24.3?

This MiKTeX release ships with a fix to the related but more general MiKTeX issue https://github.com/MiKTeX/miktex/issues/1447.

ohly87 commented 3 months ago

@ohly87 Can you check if the problem is resolved in MiKTeX 24.3?

This MiKTeX release ships with a fix to the related but more general MiKTeX issue MiKTeX/miktex#1447.

YES! actually just updating miktex through the console was enough, they have already included the fixes there :) thank you for your support, although it turns out the issue was not even with your package :)

muzimuzhi commented 3 months ago

Congrats! Well I'm neither author nor maintainer of minted, just user. 😄

DE3000 commented 2 months ago

@ohly87 you should probably close the issue.