Nixpkgs: TeXLive pygmentex package has a Python 2 script that does not work

Created on 8 Nov 2015  Â·  15Comments  Â·  Source: NixOS/nixpkgs

I have installed the TeXLive pygmentex package on my system, but its binary script pygmentex.py fails to run because:

  • its directory is not found in $PATH
  • it does not have an explicitly dependency on python2
  • it does not have an explicitly dependency on pygments
  • the pygments module for Python 2 cannot be found.

Please fix this issues so that the script can be run.

(Maybe @vcunat can take a look at this.)

bug python

All 15 comments

cc @vcunat

Well, the first two bullets would be fixed very simply by

diff --git a/pkgs/tools/typesetting/tex/texlive-new/combine.nix b/pkgs/tools/typesetting/tex/texlive-new/combine.nix
index e69c6ec..c47659b 100644
--- a/pkgs/tools/typesetting/tex/texlive-new/combine.nix
+++ b/pkgs/tools/typesetting/tex/texlive-new/combine.nix
@@ -21,7 +21,7 @@ let
     # extra interpreters needed for shebangs, based on 2015 schemes "medium" and "tetex"
     # (omitted tk needed in pname == "epspdf", bin/epspdftk)
     pkgNeedsPython = pkg: pkg.tlType == "run" && lib.elem pkg.pname
-      [ "de-macro" "pythontex" "dviasm" "texliveonfly" ];
+      [ "de-macro" "pythontex" "dviasm" "texliveonfly" "pygmentex" ];
     pkgNeedsRuby = pkg: pkg.tlType == "run" && pkg.pname == "match-parens";
     extraInputs =
       lib.optional (lib.any pkgNeedsPython splitBin.wrong) python

but I don't yet have framework to add external python dependencies to the scripts.

Nothing new here?

A similar problem happens with pythontex:

$ pythontex
Traceback (most recent call last):
  File "/nix/store/clvqqknjxa0ynwn9ps2b6kc1kin75qyw-texlive-pythontex-0.13/scripts/pythontex/pythontex.py", line 50, in <module>
    import pythontex2 as pythontex
  File "/nix/store/clvqqknjxa0ynwn9ps2b6kc1kin75qyw-texlive-pythontex-0.13/scripts/pythontex/pythontex2.py", line 61, in <module>
    from pygments.styles import get_all_styles
ImportError: No module named pygments.styles

cc @vcunat

Maybe while a good solution is not engineered, a package for pygmentex without the TeX stuff can be added to nixpkgs. It would contain the binary with support for the needed Python dependencies.

What do you think?

There aren't any true binaries, are there? It's just python scripts IIRC. But still, what you propose is probably the easiest way to resolve this somehow.

It is just a Python script that depends on the Pygments module.

My attempt at it:

diff --git a/pkgs/tools/typesetting/pygmentex/default.nix b/pkgs/tools/typesetting/pygmentex/default.nix
new file mode 100644
index 0000000..32ad097
--- /dev/null
+++ b/pkgs/tools/typesetting/pygmentex/default.nix
@@ -0,0 +1,45 @@
+{ stdenv, fetchzip, python2Packages }:
+
+python2Packages.buildPythonApplication rec {
+  name = "pygmentex-${version}";
+  version = "0.8";
+
+  src = fetchzip {
+      url = "http://mirrors.ctan.org/macros/latex/contrib/pygmentex.zip";
+      sha256 = "1nm19pvhlv51mv2sdankndhw64ys9r7ch6szzd6i4jz8zr86kn9v";
+  };
+
+  pythonPath = [ python2Packages.pygments python2Packages.chardet ];
+
+  buildPhase = ":";
+  
+  doCheck = false;
+  
+  installPhase = ''
+  
+    mkdir -p $out/bin
+    cp -a pygmentex.py $out/bin
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://www.ctan.org/pkg/pygmentex;
+    description = "Auxiliary tool for typesetting code listings in LaTeX documents using Pygments";
+    longDescription = ''
+      PygmenTeX is a Python-based LaTeX package that can be used for
+      typesetting code listings in a LaTeX document using Pygments.
+
+      Pygments is a generic syntax highlighter for general use in all kinds of
+      software such as forum systems, wikis or other applications that need to
+      prettify source code.
+
+      This package installs just the script needed to process code listings
+      snippets extracted from the a LaTeX document by the pygmentex LaTeX
+      package. In order to use it effectivelly the texlive package pygmentex
+      also has to be installed. This can be done by adding pygmentex to
+      texlive.combine.
+    '';
+    license = licenses.lppl13;
+    maintainers = with maintainers; [ romildo ];
+    platforms = platforms.unix;
+  };
+}
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index f38ee99..8a4e27f 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -3002,6 +3002,8 @@ let

   pydb = callPackage ../development/tools/pydb { };

+  pygmentex = callPackage ../tools/typesetting/pygmentex { };
+
   pystringtemplate = callPackage ../development/python-modules/stringtemplate { };

   pythonDBus = dbus_python;

So pygmentex works as expected now?

It works! It can be tested by downloading the example document from the distribution on CTAN, unzipping the downloaded files, removing the Python script and the LaTeX style class, and than compiling demo.tex:

$ pdflatex demo
$ pygmentex.py demo.snippets
$ pdflatex demo
$ pdflatex demo

The result is demo.pdf, with many examples of code listings typeset by Pygments.

OK, then I think we can close this.

Sorry for necromancing this (should I have opened a new issue instead?), but it doesn't "just work" @romildo – or needs further documentation on how to use it:

The pygmentex created by building the pygmentex texlive package can not find the pygments module.

nix-shell -E "with import <nixpkgs> {}; (pkgs.texlive.combine { inherit (pkgs.texlive) scheme-small pygmentex; })" gives us such an environment, just try running the pygmentex command from there -> ImportError: No module named pygments

The pkgs.pygmentex package though provides a pygmentex.py executable which works just fine and finds the needed pygments python module.

So how to combine these both packages?
In particular I ran into this when trying to use the minted texlive package, as that seems to directly invoke the pygmentex executable during build.

Issue appears on release-18.09

I encountered the same issue, the latex package minted seems to be working fine tough (and can be used as a replacement)

@schmittlauch I have in environment.systemPackages both pkgs.texlive.combine with pygmentex (which provides the style file pygmentex.sty and a non-functional pygmentex Python script, because of missing Python dependencies) and pkgs.pygmentex (which provides the pygmentex.py script). This setup works for me.

I still do not know a way of allowing Python module dependencies for Python scripts installed through pkgs.texlive.combine.

This is to be fixed in #75730

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  Â·  3Comments

rzetterberg picture rzetterberg  Â·  3Comments

teto picture teto  Â·  3Comments

sid-kap picture sid-kap  Â·  3Comments

domenkozar picture domenkozar  Â·  3Comments