I want to compile some latex documents programmatically. But one error is spoiling my whole pipeline that works in Windows.
How to reproduce:
texlive on Ubuntu 18.04 where MMA 11.3 is already installed.
sudo apt-get install texlive-xetex which xelatex
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"]
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]
ls -a in place of
xelatex everything will work fine and we will see the shell output as we see in an ordinary terminal.
- I have tried copying the
/usr/local/Wolfram/Mathematica/11.3/SystemFiles/Libraries/Linux-x86-64but that brings some symbol error but the
'ZLIB_1.2.9' not founderror vanishes.
- I tried installing arara (install arara :
sudo apt install texlive-extra-utils) to replace ghe usage of
xelatexcommand in my program with
arara. Same problem came back when calling
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
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" ProcessEnvironment-><|"libz.so.1"->"/usr/lib64/libz.so.1"|>]
<|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
ProcessEnvironment-> <|"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 ?
RunProcess[$SystemShell, All, "ldd /usr/bin/xelatex", ProcessEnvironment -> <|"libz.so.1" -> "/usr/lib64/libz.so.1"|>]help ? $\endgroup$
ExternalEvaluate? I have added
ExternalEvaluateexample code for both Node and Python. Also I failed to run
araravia RunProcess using this trick. But managed to get
xelatexworking. Thx a lot!! $\endgroup$