sage-shell-mode icon indicating copy to clipboard operation
sage-shell-mode copied to clipboard

File path with spaces

Open j-oldroyd opened this issue 1 year ago • 0 comments

I tried using the SageTeX functionality of this package on a TeX file that I had saved in Google Drive. When I tried to do so, it appeared that Sage was unable to find the correct file since the file path was being split on the first space in the filename. After a bit of digging, it seems like the issue lies in the definition of the sage-shell-sagetex:tex-master-maybe function. In my config file I added the advice

(advice-add 'sage-shell-sagetex:tex-master-maybe
                 :filter-return #'shell-quote-argument)

and this seemed to fix the line break issue I mentioned above.

At this point, it seemed that the correct filename was being fed to Sage, but using shell-quote-argument introduced escape slashes before the spaces in the filename that now caused issues in the function sage_tex_load in emacs_sage_shell.py. In particular, the .expanduser() method no longer worked on the input. I've modified this function to remove the escape slashes introduced by shell-quote-argument as follows:

def sage_tex_load(f: Path) -> None:
    f = f.split('\\')
    f = ''.join(f)
    f = Path(f)
    d = f.expanduser().parent
    with current_dir(d):
        ip.ev(f'load("{f}")')

So far this seems to be working, but I don't know if this will cause problems down the road or if there's a better way to handle filenames with spaces in them.

Thanks for writing a very nice package. I've gotten some good use out of it already, and I look forward to using it more in my LaTeX workflow.

j-oldroyd avatar Nov 03 '24 05:11 j-oldroyd