Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples fail on recompile using Overleaf #49

Open
codydunne opened this issue Jul 23, 2024 · 6 comments
Open

Examples fail on recompile using Overleaf #49

codydunne opened this issue Jul 23, 2024 · 6 comments

Comments

@codydunne
Copy link

Using Overleaf, I can get robust-externalize working upon initial compile but not when recompiling. Below I've included the relevant code, and here is a link to a MWE Overleaf Project.

To replicate the issue, recompile from scratch then recompile.

Upon recompile, you get this error:

Package Listings Error: File `
robustExternalize/robExt-C37F2F351CEAA0FD233909DE4F3D0106-code.txt(.tex)
' not found.

Under Other logs and files, there is an

robustExternalize/robExt-C37F2F351CEAA0FD233909DE4F3D0106-code.pdf

file though...

\usepackage{robust-externalize}

% Needed to be added to get `python print code and result` working similar to docs.
\usepackage[most]{tcolorbox}

% Needed to be added to get syntax highlighting to work... Why?
% Without it, these errors show up:
%   Package Listings Error: Couldn't load requested style.
%       The following styles weren't loadable: ,mypython$
%   Package Listings Error: style mypython undefined.
\lstdefinestyle{mypython}{
  language=Python,
  basicstyle=\ttfamily,
  keywordstyle=\color{blue},
  commentstyle=\color{green},
  stringstyle=\color{red},
  showstringspaces=false
}

\begin{document}

% Example from the docs that fails on recompile
\begin{CacheMeCode}{python print code and result, set title={The for loop}}
    for name in ["Alice", "Bob"]:
        print(f"Hello {name}")
\end{CacheMeCode}

Separately, as you see in the code here, I had to add some additional bits in order to get the example to show up anything like in the docs upon the first recompile from scratch. Why?

@tobiasBora
Copy link
Contributor

tobiasBora commented Jul 24, 2024

Thanks a lot for the detailed report, that is indeed a weird bug. I need to check if I can reproduce without overleaf when I get back to a laptop, but my guess is that overleaf cleans automatically all cached .txt files… Because right after the first compilation, the cached file is present with few other temporary files, but after the second compilation they get removed, while it shouldn't. I'd try to check with overleaf support to see if we can disable this behavior. A super simple but very stupid workaround is to add \immediate\write18{rm -rf robustExternalize} in your preamble… but this cleans completely the cache everytime you recompile. So robust-externalize would not cache anything, but you can still execute python code as usual. But I'll try to find a better solution.

@tobiasBora
Copy link
Contributor

Separately, as you see in the code here, I had to add some additional bits in order to get the example to show up anything like in the docs upon the first recompile from scratch. Why?

This is because you need to load:

\usepackage{pythonhighlight}
\usepackage[most]{tcolorbox}

as documented (maybe I should move this in the example directly). The clarity of the error message and a recent non-backward-compatible change made by pythonhighlight is discussed in #33

@tobiasBora
Copy link
Contributor

tobiasBora commented Jul 25, 2024

Ok, so a workaround is simply to change the robust-externalize.sty file, replacing all occurences of -code.txt into -code.pdf (.tex are also removed) and -print.txt into -print.pdf. You can also copy/paste the example here https://www.overleaf.com/read/zqnnyktgspsv#722252 (but I won't update it). I'm a bit relunctant to push this upstream since this seems more like a bug that overleaf should solve here. But I should certainly at least document this.

@codydunne
Copy link
Author

codydunne commented Jul 25, 2024

Thanks @tobiasBora!

Overleaf caching

I took your approach of changing all occurrences of -code.txt into -code.pdf and -print.txt into -print.pdf. It worked for the initial examples, but I had trouble with some others. See https://www.overleaf.com/read/rwkgzkghnwtq#744f8d.

In particular, latex with \writeRobExt and python with write_to_out failed. The former says the file is missing, the latter says the associated control sequence is undefined.

Formatting issue
Based on #33 and your code, I got the formatting to work w/o errors like so:

\usepackage{pythonhighlight}
\usepackage[most]{tcolorbox}
\robExtSetPlaceholder{__ROBEXT_PYTHON_LSTINPUT_STYLE__}{frame=single, breakindent=.5\textwidth, frame=single, breaklines=true, style=pythonhighlight-style}

The key is replacing mypython with pythonhighlight-style.

@tobiasBora
Copy link
Contributor

In particular, latex with \writeRobExt and python with `write_to_out failed. The former says the file is missing, the latter says the associated control sequence is undefined.

Yeah, this make sense, seems like overleaf also clears the .tex files that are used to store the temporary values… so I guess one can rename also the -out.tex into -out.pdf for instance here

f_out_write = open("__ROBEXT_OUTPUT_PREFIX__-out.tex", "w")
Hopefully latex won't be disturbed by \input{foo.pdf}, but I have no computer to test right now… This suggests even more that overleaf should fix this bug on their end…

Formatting issue

Oh, pythonhighlight already pushed their code to CTAN… arg. So I'll need to quickly deploy a backward compatible fix. I think I found an elegant solution that I need to implement when I've some time.

@codydunne
Copy link
Author

one can rename also the -out.tex into -out.pdf

That worked! I had to replace it in 5 places, at least for my examples at https://www.overleaf.com/read/rwkgzkghnwtq#744f8d. Thank you for your work on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants