3

Installed MacTex2023 on a new Mac and all is well except for a nagging issue with "pygmentize" that I've already installed. I cannot find how to adjust system to recognise the installed "pygmentize" that exists in my "/Users//Library/Python/3.9/bin" folder.

I have upgraded to Python 3.11 and used pip3 to confirm that Pygments 2.14.0 is installed.

I've already checked those SE pages that discuss Pygmentize issues, e.g. at Pygmentize not working properly with minted package in TexShop on OS X

Additional specs via 'pip3 list': Package Version


  1. altgraph 0.17.2
  2. future 0.18.2
  3. macholib 1.15.2
  4. pip 23.0.1
  5. Pygments 2.14.0
  6. setuptools 67.6.0
  7. six 1.15.0
  8. wheel 0.40.0

Note: When I run the following minimal LaTeX package, I see the same error:

\documentclass{article}
\usepackage{minted}
\begin{document}
    \begin{minted}{c}
    int main() {
    printf("hello, world");
    return 0;
    }
    \end{minted}
\end{document}

e.g.: 'Package minted Error: You must have `pygmentize' installed to use this package.'

Note 2: I Typeset to LaTeX using TexShop.

RosesBouquet
  • 569
  • 3
  • 13
  • Did you compile with the -shell-escape flag? That is necessary for the package to work. – Amarakon Mar 26 '23 at 04:39
  • @Amarakon - Thanks for the question. In the TeXShop preferences > Engine > pdfTeX > Latex field I have the following command: pdflatex --file-line-error --synctex=1 --shell-escape, which I assume turns ON the -shell-escape flag ... n'est pas? Is there something else I need to do? – RosesBouquet Mar 26 '23 at 04:47
  • Yep, that should do it. – Amarakon Mar 26 '23 at 05:17
  • @Amarakon - Thank you! The whole -shell-escape flag issue took me a bit to research ... now I need to research a bit more to address the issue with pygmentize .... unless someone else has had the same issue, and a solution. Thanks for your comment! – RosesBouquet Mar 26 '23 at 05:47
  • I ran into the same problem using LuaLatex. The strange thing was the work around I discovered in trial-and-error: first compile with PDFLatex (be aware of the use of fontspec / fontenc differences between the two), which generated the required minted output. Then compile again with LuaLatex to get the final PDF. I am using TeXStudio/MikTeX (fully upgraded). Checking the pathways in both compilations revealed a strange issue: in LuaLatex the whole pathway was replaced with only one line pointing towards the MikTeX installation.... – alchemist Mar 26 '23 at 08:29
  • @alchemist - Thank you so much for your response. I should have mentioned that I Typeset to LaTeX using TexShop. I went through much the same rigamarole with pygmentize a few years back (even made notes in the code re the issue). Now with the new Mac, I'm back to square one. I've upgraded to MacTeX2023, so there are two variables at play. I'll likely have to stumble around for a bit before I stumble on a solution as I apparently did back then. All-in-all a small price to pay for the power of LaTeX ... hadn't thought about fontspec ... don't know if/how relevant ... will have to check that! – RosesBouquet Mar 26 '23 at 09:16
  • fontspec isn't relevant to the pygemtize issue, only you use it to manage fonts in LuaLatex. – alchemist Mar 26 '23 at 11:01
  • @alchemist - Thank you for the clarification ... saved me a bit of time ... still working on other issues at the moment, but thank you for clarifying and removing one item from my todo list! – RosesBouquet Mar 26 '23 at 11:09
  • are you sure you want --shell-ecape on in your default settings rather than enabled per document? Be very careful of running any tex code coped from elsewhere, eg this site. You are giving the author of that code full access to your machine. – David Carlisle Mar 26 '23 at 11:37
  • @David Carlisle - Thank you for the comment (always a special privilege), and NO, I do NOT want to give ANY author full access to my machine. Any references or thoughts to guide me toward enabling my settings to instead be per document would be appreciated ... A special thanks again! – RosesBouquet Mar 26 '23 at 12:35
  • I don't use texshop but I believe you can use its % !TeX magic comment feature at the top of the document to make such settings – David Carlisle Mar 26 '23 at 12:58
  • have you tried to launch a Terminal and type pygmentize -V to confirm it is correctly installed? – user691586 Mar 26 '23 at 13:30
  • have you tried https://tex.stackexchange.com/a/281188/293669 – user691586 Mar 26 '23 at 13:47
  • @DavidCarlisle I tried all sorts of % !TeX and never could get it to activate shell-escape. Unfortunately https://stackoverflow.com/a/28586661 advises people to add permanently --shell-escape to pdflatex invocation in TeXShop preferences. – user691586 Mar 26 '23 at 13:55
  • @RosesBouquet ln -s "$(which pygmentize)" /Library/TeX/texbin/pygmentize from https://tex.stackexchange.com/a/281188/293669 works for me (I don't need sudo due to my custom way of installing TeXLive on my mac). But I still have no solution how to tell TeXShop to use --shell-escape only of one run. My advise: better to stop using TeXShop than to configure permanently with --shell-escape. – user691586 Mar 26 '23 at 14:05
  • @user691586 well personally I would not do that and if texshop doesn't have a built in comment i'd set up a separate menu option to choose that, just as you can presumbly choose between lualatex and pdflatex, or set it up to use arara which can confgure this from a comment or (what I actually do) just run such thing from the commandline and literally type pdflatex --shell-escape documentname – David Carlisle Mar 26 '23 at 14:06
  • @user691586 ooh it has a manual:-) https://pages.uoregon.edu/koch/texshop/TeXShopManual-2006.pdf TeXShop now provides a different protection. A preference item under the Engine tab is labeled “Shell Escape Warning”. This item is off when TeXShop is delivered. If the item is on and “shell-escape” is active, then the first time a file is typeset during a TexShop session, a warning dialog will appear allowing you to turn shell-escape off for that particular file. – David Carlisle Mar 26 '23 at 14:29
  • @DavidCarlisle oops there was a temporary black-out and I missed your comment while concentrating on posting my answer... – user691586 Mar 26 '23 at 14:30
  • @user691586 no I was hit by same so my comment actually posted after your answer – David Carlisle Mar 26 '23 at 14:32
  • @DavidCarlisle indeed if you both add --shell-escape in the default TeXShop pdflatex call and toggle on the "Shell Escape Warning" you will be warned about shell-escape. But the logic is moot. Much better if there was some toggle in the TeXShop window to turn on, exceptionally the shell escape. – user691586 Mar 26 '23 at 14:39
  • This has nothing to do with --shell-escape but rather with TeXShop being able to locate pygmentize. Open a Terminal and type ln -s ~/miniconda3/bin/pygmentize /usr/local/bin/pygmentize, replacing the first path with that appropriate for your setup, and hit return. You should then be able to process your document assuming you enable --shell-escape in any of the usual ways. I prefer to put % !TEX parameter = --shell-escape at the top of my file. – LaTeXereXeTaL Mar 26 '23 at 17:40
  • @user691586 - apologies for the delay in responding ... Re pygmentize -V the response I get is Pygments version 2.14.0, (c) 2006-2022 by Georg Brandl, Matthäus Chajdas and contributors. – RosesBouquet Apr 01 '23 at 16:38
  • @RosesBouquet ok this thus means pygmentize is there. But TeXShop will not find it if it is not also among the TeXLive binaries hence the ln -s "$(which pygmentize)" /Library/TeX/texbin/pygmentize business. cf my answer. Unfortunately it seems, at least for TeXShop of 5 or 6 years ago that you need to permanently add --shell-escape but you have possibilty to toggle "warn if shell escape" (or whatever is wording) and you can deactivate for documents not needing it, on first compilation. – user691586 Apr 01 '23 at 16:44
  • @user691586 - OK, I see the Omit Shell Escape message ... but if I select OK (to keep Shell Escape) ... something is not working ... I'll need some time to sort out ... Thank you for your assistance. – RosesBouquet Apr 01 '23 at 17:32
  • @DavidCarlisle - Any thoughts, comments or experience with the minted alternative? (https://tex.stackexchange.com/questions/351454/how-to-you-properly-specify-an-alternative-to-the-pygmentize-external-command-fo – RosesBouquet Apr 01 '23 at 17:54
  • @RosesBouquet It works for me if I have done (once, in a Terminal) ln -s "$(which pygmentize)" /Library/TeX/texbin/pygmentize, then in TeXShop Preferences>Engine (I assume in English) in the pdflatex invocation I add --shell-escape, and also toggle Shell escape warn (I see it in my locale language) but only because I want to have opportunity to deactivate shell-escape. Then I launch compilation, a pop-up appears asking if I really want to use shell-escape, I click OK and it works. – user691586 Apr 01 '23 at 18:03
  • @user691586 - OK, I selected pdflatexc under Macros>Claus Gerhardt Macros, but I needed to run the script twice to obtain the complete output. (A bit strange?) Question: Does the pdflatexc script set --shell-escape ON for just the immediate project, or for ALL projects. Thank you for this ... I will need to test the pdflatexc script on my full project b4 accepting your answer ... Thank you for all your research!! – RosesBouquet Apr 01 '23 at 18:04
  • pdflatexc is simply pdflatex --shell-escape. I.e. it only uses --shell-escape once, when called. It does not have any left-over effects. However personally I would not use it because I need to see the console output of LaTeX run for quick analysis in case of errors or warnings, and this window is not shown by TeXShop when one uses it. – user691586 Apr 01 '23 at 18:06
  • @user691586 - Interesting how the pdflatexc script console output appears blank ... until suddenly the finished PDF appears ... as you pointed out, would be nice to actually see the output of LaTeX run ... a small price to pay ... n'est pas? Thank you for confirming that pdflatexc only uses --shell-escape once ... any thoughts as to why I needed to run the pdflatexc twice to get the full PDF output? Thanks again for all your research!! – RosesBouquet Apr 01 '23 at 18:11
  • @user691586 - FWIIW, I ran sudo ln -s "$(which pygmentize)" /Library/TeX/texbin/pygmentize, then in TeXShop Preferences>Engine in the pdflatex invocation I added --shell-escape, and also toggled the Shell escape warning ON ... Thank you again for all your research!! – RosesBouquet Apr 01 '23 at 18:16
  • @user691586 - which pygmentize works! – RosesBouquet Apr 01 '23 at 18:22
  • @user691586 - Duplicate runs fixed ... my error ... Thanks again! – RosesBouquet Apr 01 '23 at 18:30
  • @DavidCarlisle - Re your are you sure you want --shell-ecape on in your default settings rather than enabled per document?, where may I research what --shell-escape really means ... and You are giving the author of that code full access to your machine. ... that is certainly NOT something I wish to do ... Thanks again for ALL your comments and assistance! – RosesBouquet Apr 01 '23 at 19:22
  • @RosesBouquet it allows a tex document that I send you, or you copy from some website to run \write18{arbitrary commands} so anything you can do on the command line could happen, All your files could be deleted, your ssh private keys could be emailed to me, or the tex file could process normally and a pdf gets made. – David Carlisle Apr 01 '23 at 19:44
  • the same is true if you copy a shell script or executable program, but they are "obviously risky" but normally running latex on a document isn't risky at all. – David Carlisle Apr 01 '23 at 19:47
  • @David Carlisle - As one of the champions of LaTeX and TeX in general I take notice of your messages. I did just enough research (e.g. not much, but enough) of the --shell-escape issue. Recent documents (which I cannot locate at the moment) call for avoiding the use of --shell-escape in MacTeX 2023. I've realized that bypassing the many protections built into TeX and LaTeX was a risky endeavor, but the nail in the coffin was my realization that my project ran just fine w/o the Minted package, which was the reason why I was attempting to implement the --shell-escape feature all along. – RosesBouquet Apr 02 '23 at 02:32
  • @David Carlisle - I will leave --shell-escape in my TeXShop for now, while typesetting w/o --shell-escape, with the intent to delete it from my TeXShop setup once I've had enough experience with my projects running w/o the --shell-escape function. Thank you David Carlisle for pointing this out from the get-go when I originally posted on SE ... your points about having complete access to my system bothered me for the better part of a week ... with the clincher being that your ssh private keys could be emailed to me. 'nuf said. Thank you!! – RosesBouquet Apr 02 '23 at 02:38
  • @David Carlisle - for some reason, my LaTeX project fails to create any glossaries w/o minted and --shell-escape. I've tried setting the minted option to draft=true, but the glossaries still fail unless I include --shell-escape. Seems I've been running with minted and --shell-escape for so long that I've forgotten how to create the glossaries w/o them. I've tried searching for combinations of minted, --shell-escape and glossaries but have found nothing relevant to the issue. What am I missing? – RosesBouquet Apr 05 '23 at 08:20
  • What does minted and --shell-escape have to do with glossaries? – RosesBouquet Apr 05 '23 at 08:25
  • minted is completely unrelated. shell-escape could be related if you generate your glosary via a non standard command that you call via write18 – David Carlisle Apr 05 '23 at 09:43
  • @David Carlisle - Re: minted is completely unrelated. - Just what I thought ... Not using write18 that I know of ... I've never heard of write18 b4 your mentioning it ... Best I can tell there is nothing out of the ordinary with my glossaries that I'm using ... but let me research this a bit more and advise as to what I can see ... It all seems a bit odd ... In the meantime, I've removed all mention of --shell-escape from my projects ... Many thanks for the advice and feedback! – RosesBouquet Apr 05 '23 at 10:20

3 Answers3

2

Eureka (I wish this would have been easier, e.g. from this TeXShop page).

Caveat: I tested this with a TeXShop 3.89 which is nowadays an old version.

To let TeXShop use --shell-escape for only one specific document you can:

  • instead of hitting "Compile" (or whatever is English word), go to Macros>Claus Gerhardt Macros and then choose pdflatexc. It launches the compilation using --shell-escape flag. (I discovered that by digging into ~/Library/TeXShop/bin/).

I tried many % !TeX variants such as % !TEX TS-program="pdflatex --shell-escape" but this fails, and perhaps there is a parameter TS-program-options but I stopped my search after above workaround.

But first you also need that TeXShop finds pygmentize.

An answer is given at https://tex.stackexchange.com/a/281188/293669 which worked for me.

On my installation (which is a direct TeXLive install) I do not need the sudo so simply

ln -s "$(which pygmentize)" /Library/TeX/texbin/pygmentize

in Terminal.

Perhaps execute first which pygmentize and pygmentize -V to confirm it is correctly installed, prior to symlink it to the directory where TeXShop finds TeX binaries. The above should apply on MacTeX based installations. For direct TeXLive installations on (old) Macs, replace /Library/TeX/texbin/pygmentize by something such as /usr/local/texlive/2023/bin/x86_64-darwinlegacy/pygmentize.

user691586
  • 1,988
1

The pygmentize issue can be addressed by installing pygments with pip2.

sudo pip2 install pygments

This method works on my cases.

0

I have encountered the same issue. I realised that pdflatex relies on Unix/Linux command line utility called which to confirm, that pygmentize is available. I didn't have it installed on my system and LaTeX compilation aborted with the same error you mentioned above:

You must have `pygmentize' installed to use this package.

In my case installing which resolved the problem. Be attentive and do not repeat my mistake.

mabalenk
  • 131