I want to compile some latex documents programmatically. But one error is spoiling my whole pipeline that works in Windows.

How to reproduce:

Install texlive on Ubuntu 18.04 where MMA 11.3 is already installed.

sudo apt-get install texlive-xetex
which xelatex


Now the xelatexcommand works fine on terminal. But when one tries to run it from MMA it fails with a library incompatibility issue.

We can see mathematica forcing dependency.

RunProcess[$SystemShell, All, "ldd /usr/bin/xelatex"]

The StandardOutput of RunProcess shows the error. Pastebin of the whole output.

/usr/bin/xelatex: /usr/local/Wolfram/Mathematica/11.3/SystemFiles/Libraries/Linux-x86-64/libz.so.1: version `ZLIB_1.2.9' not found (required by /usr/lib/x86_64-linux-gnu/libpng16.so.16) linux-vdso.so.1 (0x00007fffc36b7000)

Similar question here: 18653

Same error comes when I tried using Python/Node via ExternalEvaluate. Here iare the specific examples.


session = StartExternalSession[<|"System" -> "NodeJS",
"SessionProlog" -> "const execSync = require('child_process').execSync;"|>];
ExternalEvaluate[session,"code = execSync('xelatex');"]["data"]
// ByteArray // ByteArrayToString


session = StartExternalSession[<|"System" -> "Python", "Version" -> "3.6", 
"SessionProlog" -> "from subprocess import PIPE, run"|>];
fac = "command = ['ls','-a']
result = run(command, stdout=PIPE, stderr=PIPE,universal_newlines=True)
  print(result.returncode, result.stdout, result.stderr)";
ExternalEvaluate[session, fac]

Try pwd or ls -a in place of xelatex everything will work fine and we will see the shell output as we see in an ordinary terminal.

  1. I have tried copying the libz.so.1 from /lib/x86_64-linux-gnu to /usr/local/Wolfram/Mathematica/11.3/SystemFiles/Libraries/Linux-x86-64 but that brings some symbol error but the 'ZLIB_1.2.9' not found error vanishes.
  2. I tried installing arara (install arara : sudo apt install texlive-extra-utils) to replace ghe usage of xelatex command in my program with arara. Same problem came back when calling arara from RunProcess, though Ubuntu terminal worked fine.

Without this piece of latex automation I can't port my code in Ubuntu 18.04 (one of the most popular Linux dist). It will be interesting to know if this above nightmare happens also on Ubuntu 16.04.


Based on the great comment xelatex could be brought to work.

RunProcess[$SystemShell, All, "/usr/bin/xelatex "<>texFile<>".tex 
exit", ProcessEnvironment -> <|"libz.so.1" -> "/usr/lib64/libz.so.1"|>]

General solution/rule of thumb?

How to solve those above StartExternalSession and ExternalEvaluate?

Also some other commands that work on terminal fails for example the latex automation tool arara. When trying arara in the following it gives another error.

RunProcess[$SystemShell,All,"arara "<>texFile<>".tex"

<|ExitCode->1,StandardOutput->,StandardError->lstat(./kpsewhich) failed ... ./kpsewhich: No such file or directory kpsewhich: ../../../texk/kpathsea/progname.c:316: remove_dots: Assertion `ret' failed. Error: Unable to access jarfile |>

I could solve the above error by using

<|"libz.so.1"->"/usr/lib64/libz.so.1","PATH" -> Environment["PATH"]|>

What is the general method to handle this kind of issues and how to fix the StartExternalSession, is there any analog of ProcessEnvironment there ?

  • $\begingroup$ Does RunProcess[$SystemShell, All, "ldd /usr/bin/xelatex", ProcessEnvironment -> <|"libz.so.1" -> "/usr/lib64/libz.so.1"|>] help ? $\endgroup$ Jun 9, 2018 at 11:39
  • $\begingroup$ @b.gatessucks nice it does help in the above command. Can you make this an answer please. Also any idea how the same process environment trick can be done for r ExternalEvaluate? I have added ExternalEvaluate example code for both Node and Python. Also I failed to run arara via RunProcess using this trick. But managed to get xelatex working. Thx a lot!! $\endgroup$ Jun 9, 2018 at 13:26
  • $\begingroup$ Let's see if there are more comprehensive answers. $\endgroup$ Jun 9, 2018 at 13:41


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.