Ask Your Question
0

Cant get Sagetex(WSL2) to work with TexWorks(Win11).

asked 2025-10-03 02:36:20 +0200

l3gi0n gravatar image

I have installed texworks+texlive under windows 11, and sagemath under WSL2/Arch.

My project folder is at: C:\Users\zi\Desktop\sagetry\

I have created a SageTex entry under Edit -> Preferences -> typesetting -> processing tools:

Name: SageTex Program: wsl.exe Argument 1: /usr/bin/sage Argument 2: /mnt/c/Users/zi/Desktop/sagetry/$basename.sagetex.sage

Sagetex works this way but what if I wanted to create a new project folder somewhere else under windows 11 ? I should manually change the path in Argument 2 ? or is there a way for TexWorks to generate the path automatically?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2025-10-04 21:46:39 +0200

ortollj gravatar image

I ask Copilot your question:just by curiosity are you able to answer this difficult question below from https://ask.sagemath.org (me I'm not able, I do not even understand the question ! :

and this is the answer he gave me:

💡 Solution Use TeXworks’s built-in variable "$fullname" instead of "$basename":

"$fullname" gives the full path to the .tex file.

You can convert it to a WSL-compatible path using wslpath.

So update the SageTeX tool like this:

Program: wsl.exe
Argument 1: sage
Argument 2: $(wslpath "$fullname" | sed 's/.tex$/.sagetex.sage/')

This command:

Converts the full Windows path to WSL format using wslpath.

Replaces .tex with .sagetex.sage using sed.

wsl.exe /usr/bin/sage /mnt/c/Users/zi/Desktop/sagetry/$basename.sagetex.sage

This works because /mnt/c/... is how WSL2 accesses Windows files. But the path is hardcoded to one specific folder (sagetry). So if the user moves their .tex file to another folder, the SageTeX processor won’t find it unless they manually update the path.

edit flag offensive delete link more

Comments

I don't know if his answer will be useful to you.tell us if it help you or not.

ortollj gravatar imageortollj ( 2025-10-04 21:49:44 +0200 )edit

I tried:

(wslpath "fullname" | sed 's/.tex$/.sagetex.sage/')

(wslpath "$fullname" | sed 's/.tex$/.sagetex.sage/')

(wslpath "$directory" | sed 's/.tex$/.sagetex.sage/')

No such file or directory.

l3gi0n gravatar imagel3gi0n ( 2025-10-05 18:42:59 +0200 )edit

Copilot answer:

wslpath "fullname" | sed 's/.tex$/.sagetex.sage/'

This is meant to: Convert a Windows path (e.g., C:\Users\userName\Documents\mydoc.tex) into a WSL-compatible path (e.g., /mnt/c/Users/userName/Documents/mydoc.tex)

Replace the .tex extension with .sagetex.sage so Sage can process it.

⚠️ Why it fails If "fullname" is not defined or empty, wslpath returns nothing.

If the .tex file doesn’t exist at the given path, wslpath fails silently.

If the .sagetex.sage file hasn’t been generated yet (e.g., if pdflatex hasn’t been run), then Sage has nothing to process.

how to fix it: texfile="mydoc.tex" wslpath "$PWD/$texfile" | sed 's/.tex$/.sagetex.sage/'

Or, if you're inside a Makefile or script: sagefile=$(wslpath "$PWD/$texfile" | sed 's/.tex$/.sagetex.sage/')

ortollj gravatar imageortollj ( 2025-10-06 08:01:52 +0200 )edit

sage "$sagefile"

Make sure:

The .tex file exists.

You’ve run pdflatex at least once to generate the .sagetex.sage file.

You’re quoting paths properly to avoid issues with spaces.

why don't you ask Copilot by yourself ? not sure he can solve the problem but it would be interesting. If you succeed, please don't forget to share the solution.

ortollj gravatar imageortollj ( 2025-10-06 08:04:28 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2025-10-03 02:36:20 +0200

Seen: 80 times

Last updated: Oct 04