Errors executing pdflatex or latex2pdf commands using system() function

13 views (last 30 days)
Hello,
After generating a tex file through Matlab, I want to compile the tex to PDF (still within Matlab). For this purpose I have the line below :
system( [ 'latex2pdf ', texPath ] ); % texPath is the full path to my tex file.
The actual command line works when I copy it to my terminal (bash on Ubuntu), but in Matlab it gives me the following error(s) :
xelatex: /usr/local/MATLAB/R2014a/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by xelatex)
xelatex: /usr/local/MATLAB/R2014a/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by xelatex)
xelatex: /usr/local/MATLAB/R2014a/sys/os/glnxa64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /usr/lib/x86_64-linux-gnu/libicuuc.so.55)
xelatex exited with errors:
failed to open /home/mas-2001746/tmp/study_2015_11_25_13.43.07.log for input
Trace begun at /usr/share/perl5/LaTeX/Driver.pm line 801
LaTeX::Driver::throw('LaTeX::Driver=HASH(0x1b3eba0)', 'xelatex exited with errors:^Jfailed to open /home/mas-2001746/tmp/study_2015_11_25_13.43.07.log for input') called at /usr/share/perl5/LaTeX/Driver.pm line 411
LaTeX::Driver::run_latex('LaTeX::Driver=HASH(0x1b3eba0)') called at /usr/share/perl5/LaTeX/Driver.pm line 273
LaTeX::Driver::run('LaTeX::Driver=HASH(0x1b3eba0)') called at /usr/share/perl5/LaTeX/Driver/FilterProgram.pm line 82
eval {...} at /usr/share/perl5/LaTeX/Driver/FilterProgram.pm line 78
LaTeX::Driver::FilterProgram::execute('LaTeX::Driver::FilterProgram', 'format', 'pdf') called at /usr/bin/latex2pdf line 33
I've read somewhere on this forum that the Matlab "environment" can be different than the shell's because my profile is not sourced (I don't really understand what that means to be frank), so I followed advice givien in the link below and added the following line to MATLABROOT/bin/matlab :
source $HOME/.profile
I then restarted Matlab, hoping to give it the same "environment" as my shell, but I still get the same error.
FYI, I also get errors using the command pdflatex :
pdflatex: /usr/local/MATLAB/R2014a/bin/glnxa64/libtiff.so.5: no version information available (required by /usr/lib/x86_64-linux-gnu/libpoppler.so.52)
pdflatex: /usr/local/MATLAB/R2014a/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /usr/lib/x86_64-linux-gnu/libpoppler.so.52)
However, other basic commands (ls, dir, ...) work fine.
Finally, I created a shell script that launched latex2pdf and called my script from Matlab, but got the same error.
I've spent hours on this super frustrating problem (such a small step away from my result it seems silly to give up and launch the command in a separate terminal), any help will be much appreciated !
Thanks,
Tepp
PS : sorry for the double post as I started a thread in Newsgroup before noticing that it was probably best to post in Answers (much better interface for formatting code, etc.). I will update both posts with crossreferences as soon as it becomes relevant.
  1 Comment
Stephen23
Stephen23 on 30 Nov 2015
tepp yogi's "Answer" moved here:
Perhaps, if no one is familiar with using latex2pdf or pdflatex from Matlab, someone can suggest to me an alternative solution ?
Thanks,
Tepp.

Sign in to comment.

Accepted Answer

Stepp Gyogi
Stepp Gyogi on 30 Nov 2015
Hello,
I finally got a workaround sort of working (don't like it but it's the best I've got to so far) : I created a script to launch Matlab.
Here's what it looks like :
#!/bin/sh
cd ~
LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libstdc++.so.6" matlab
If anyone has a better suggestion feel free to post :)
Thanks,
Tepp
  1 Comment
Stepp Gyogi
Stepp Gyogi on 30 Nov 2015
Actually, for this script to be launchable through Unity Launcher on ubuntu I adapted the script to the following so that the window would stay open after the command executes in terminal :
#!/bin/sh
cd ~
export LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libstdc++.so.6"
matlab -desktop &

Sign in to comment.

More Answers (2)

Walter Roberson
Walter Roberson on 29 Nov 2015
Remove that "source" that you added.
Go to a Terminal window (Terminal is in /Applications/Utilities). When you are there give the command
otool -L latex2pdf
and look to see which directory it finds libstdc++* in.
  3 Comments
Stepp Gyogi
Stepp Gyogi on 29 Nov 2015
PS : I've just tried the following "flavors" with regards to this other post of yours, to no avail :
>> system('export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu; ldd /usr/bin/pdflatex | cat | grep -i libstdc++')
/usr/bin/pdflatex: /usr/local/MATLAB/R2014a/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /usr/lib/x86_64-linux-gnu/libpoppler.so.52)
libstdc++.so.6 => /usr/local/MATLAB/R2014a/sys/os/glnxa64/libstdc++.so.6 (0x00007f12cf00b000)

ans =

0

>> system('setenv LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu; ldd /usr/bin/pdflatex | cat | grep -i libstdc++')
/bin/bash: setenv: command not found
/usr/bin/pdflatex: /usr/local/MATLAB/R2014a/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /usr/lib/x86_64-linux-gnu/libpoppler.so.52)
libstdc++.so.6 => /usr/local/MATLAB/R2014a/sys/os/glnxa64/libstdc++.so.6 (0x00007fa06f54d000)

ans =

0

>> system('set -x LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu; ldd /usr/bin/pdflatex | cat | grep -i libstdc++')
+ cat
+ grep -i libstdc++
+ ldd /usr/bin/pdflatex
/usr/bin/pdflatex: /usr/local/MATLAB/R2014a/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /usr/lib/x86_64-linux-gnu/libpoppler.so.52)
libstdc++.so.6 => /usr/local/MATLAB/R2014a/sys/os/glnxa64/libstdc++.so.6 (0x00007f581040a000)

ans =

0

>> system('LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu ldd /usr/bin/pdflatex | cat | grep -i libstdc++')
/usr/bin/pdflatex: /usr/local/MATLAB/R2014a/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /usr/lib/x86_64-linux-gnu/libpoppler.so.52)
libstdc++.so.6 => /usr/local/MATLAB/R2014a/sys/os/glnxa64/libstdc++.so.6 (0x00007fd229ebd000)

ans =

0
I also tried modifying the matlab command by including the export before launch, that didn't work either.
gopimn
gopimn on 8 Jan 2016
Hello!
I was reading the post because i had the same problem. The workarround that i did was to rename the file sys/os/glnxa64/libstdc++.so.6 to sys/os/glnxa64/libstdc++.so.6.resp and make a symbolic link to the file of the host operating system:
user@host:/my/MATLABDIR/sys/os/glnxa64$ sudo mv libstdc++.so.6 libstdc++.so.6.res
user@host:/my/MATLABDIR/sys/os/glnxa64$ sudo ln -s /usr/lib/libstdc++.so.6
After that just do:
system('pdflatex test.tex')
And remember to erase the link and rollback the name of the file. It's not an elegant solution but at least it works.

Sign in to comment.


Jeremy Rogers
Jeremy Rogers on 11 Feb 2017
Edited: Walter Roberson on 12 Feb 2017
I just ran into this problem as well. I wanted a solution that does not require any changes to matlab startup and would work across linux machines without modifying anything outside of the script.
For the bash syntax on linux, the following works for me by adding the system library path to the environment just for the call to the pdflatex command:
system('LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/:LD_LIBRARY_PATH; export LD_LIBRARY_PATH; pdflatex filename.tex')
You may need to change the /usr/lib/x86_64-linux-gnu/ part to match your system, and you can determine the correct path using the ldd command posted above. Also, the matlab docs on setenv show how to set the path if your system uses sh instead of bash.
  1 Comment
Walter Roberson
Walter Roberson on 12 Feb 2017
Actually setenv is for csh rather than sh. But sh did not support the "export" command. Also you missed substituting in the current value.
The sh version should be:
system('LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/:$LD_LIBRARY_PATH export LD_LIBRARY_PATH; pdflatex filename.tex')
That will also work for ksh and bash, but for ksh and bash you can also use
system('export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/:$LD_LIBRARY_PATH; pdflatex filename.tex')

Sign in to comment.

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!