This is not officially supported, but you can made it to work...
-
first, see the
test.texfile below (because of an annoying GitHub gist "bug", all files following a large raw file are shown as "cannot display file this big...", thus the "a-" prefix) -
download
sympy.zipattached below in the gist, and upload it to your overleaf.If you don't trust downloading random files from random sources, you can make the file yourself -- otherwise just ignore this section. This file was prepared by
# <install python2.7 somehow> python2 -m ensurepip --upgrade --user cd /tmp/ virtualenv -p /bin/python2.7 zzt # create a Python 2.7 virtual environment cd zzt . bin/activate pip2 install sympy # install sympy and mpmath pip2 install matplotlib # matplotlib backend for sympy for plotting mkdir /tmp/new; cd /tmp/new # change to some new empty directory cp -r /tmp/zzt/lib/python2.7/site-packages/* . rm -r pip setuptools pkg_resources wheel # a weird hack to allow importing mpl_toolkits touch mpl_toolkits/__init__.py # minimizing the resulting file find . -name __pycache__ -exec rm -r {} \; find . -name '*.pyc' -exec rm -r {} \; find . -name 'tests' -exec rm -r {} \; # then create sympy.zip in /tmp/ rm /tmp/sympy.zip #zip -r /tmp/sympy.zip * 7z a -tzip -mx=9 /tmp/sympy.zip * # generates smaller zip file, needed if close to 50MB limit of overleaf
(by the way Overleaf properly sandbox the environment, so even if there's malicious code it won't be able to do anything such as delete your TeX file or leak it to the Internet)
-
copy the initial lines of
test.texto your file\usepackage{shellesc} \ShellEscape{unzip sympy.zip </dev/null >/dev/null 2>&1} % </dev/null, it will only attempt to unzip once then ignore in following attempts \ShellEscape{ PYTHONPATH=$(kpsewhich -var-value TEXMFDIST)/scripts/sympytexpackage/ python2 \jobname.sympy >tmpoutput.txt 2>&1 #$} \usepackage{sympytex}
We need
unzipinstead of just add the zip file toPYTHONPATHto allow importing.sofile fornumpy. -
add the
.latexmkrcfile to your project -
In Overleaf, at the moment if you select "TeX Live version" to be "2022" then it will show the error message
python2: command not found, which I'm not sure why. Just use version 2021 as a workaround. -
then you can use sympytex as usual.
If you want to plot remember to select
AGGbackend (see the test file below), otherwise it will break because tkinter is not installed.
Furthermore, it cannot detect changes, so the first compilation after "Recompile from scratch" will not work...?
Hi, I've tried the script and couldn't figure out how to get past the error saying 'python2 not found', because i'm not sure how virtual environments work. Is there any chance you could make an overleaf example and share it? Thanks