MATLAB: Errors executing pdflatex or latex2pdf commands using system() function

latexsystemunix

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.

Best Answer

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
Related Question