8

Is there a way to make PythonTEX compile as of today in Overleaf V2 ?

\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage{pythontex}

\begin{document}
\begin{pyverbatim}
def calc_ellipticity(theta, delta):
    theta = np.deg2rad(theta)
    psi = np.arcsin(np.sin(2*theta) * np.sin(delta))/2
    return np.tan(psi)
\end{pyverbatim}
\end{document}

Compiling gives : ? PythonTEX ?

yo'
  • 51,322
  • 1
    If this is the correct use of pythontex, then this question may be more appropriate for Overleaf support instead of here. On the other hand, Overleaf usually has a few people that watch TeX.SE, so I wouldn't be surprised if they show up. – Teepeemm Mar 24 '20 at 22:08
  • 3
    I’m voting to close this question because this is an Overleaf specific question and is best asked to their support team who are quick to respond. That some from the overleaf support also read TeX-LaTeX StackExchange and also answer such questions, does not mean, that such questions fall within the scope of TeX-LaTeX Stack Exchange as define in the help center. – cabohah Jun 02 '23 at 13:42
  • I respectfully disagree. This question has been resolved and helps people. Considering overleaf is the most mainstream and biggest online latex compiler, I wouldnt say it is 100% out of scope of tex-latex, even though I get your point. If closing does not remove the post, then I'm okay to close it. I think this information, even of not within 100% its scope, should remain here. – PyThagoras Jun 03 '23 at 14:06

2 Answers2

9

(Tom from Overleaf support here.)

Unforunately, the pythontex package is not currently supported on Overleaf v2. This is because of a change to the security model in Overleaf v2 (as opposed to v1).

See also https://www.overleaf.com/learn/how-to/Overleaf_v2_FAQ

yo'
  • 51,322
  • 1
    Oh no, that's disapointing. :( Is there any package that can format python code easily other listings? – PyThagoras Mar 25 '20 at 14:38
  • For formatting code, you can try listings: https://ctan.org/pkg/listings – yo' Mar 25 '20 at 16:31
  • Did this ever change / will it ever change? – N. Virgo Aug 07 '22 at 04:02
  • 1
    @N.Virgo (also to the answerer) I notice that shell-escape is enabled, so it should be possible to implement something that works. But let me see. – user202729 Aug 07 '22 at 16:20
  • It would be better if overleaf explains more accurately what the security model is. – user202729 Aug 07 '22 at 16:34
  • Apparently the issue is with multiprocessing.SemLock or something... Searching around there's https://stackoverflow.com/questions/34005930/multiprocessing-semlock-is-not-implemented-when-running-on-aws-lambda#34032458. It's possible to implement PythonTeX without multiprocessing module though... – user202729 Aug 07 '22 at 16:52
  • Update, apparently it's not allowed to create a fifo on overleaf as well, seems difficult... – user202729 Aug 07 '22 at 17:27
  • Okay seems unnamed pipe like this https://superuser.com/questions/184307/bash-create-anonymous-fifo#633185 works. I guess I can try – user202729 Aug 07 '22 at 17:44
  • ( @N.Virgo might also be interested) I fiddle with overleaf a bit and figure out a way to get sympytex to work, although it's python2 only and you need to manually upload sympy to it -- https://gist.github.com/user202729/34c1243cf3f612332dad60760054c3ed (answer does not really fit anywhere on the site I think) -- although reading around a bit there's an option of switching to CoCalc -- not sure if it can be depython'ed though. – user202729 Aug 08 '22 at 01:55
  • @user202729 does the solution work also for PythonTeX? (I'm unsure how sympytex and PythonTeX relate to each other, other than sympy being a Python package.) – N. Virgo Aug 09 '22 at 12:47
  • @N.Virgo hacking a bit more I got https://gist.github.com/user202729/09bb8290abff129c3698f494c2f53ffd . Need a different trick though – user202729 Aug 09 '22 at 13:28
1

Pythontex and SageTex are both supported by the security model of CoCalc, so you might try it instead. https://cocalc.com/features/latex-editor

(I work on CoCalc, which is an alternative to Overleaf.)