Playing around with this a little more, I think that this is a bug/timing issue in
sage.misc.latex.py (or in subprocess.run, or a mac oddity since it only started happening recently).
What seems to be happening is that the generated PDF file, output_file, is being deleted before the viewer is able to open it. Specifically, if I add time.sleep(2) before the tmp.cleanup then the viewer opens as expected.
def run_viewer():
run([viewer, output_file], capture_output=True)
time.sleep(1) ## adding this, together with import time, fixes the problem
tmp.cleanup()
(This around line 1957 of latex.py.) Certainly this explains my experience of the command working sometimes and failing at other times. On the other hand, it is a little strange because subprocess.run is supposed to wait for the process to finish. A shorter example that exhibits the problem, at least on the two macs that I have available, is
sage: view(crystals.LSPaths( RootSystem(['A',4]).weight_space().basis()[1] ) )
If people agree that this is a bug then I am happy to post a fix.
Andrew