Texmacs_home_path with texmacs-portable in windows on a usb stick

Hello, I use portable texmacs on windows on a usb key because I change computers regularly in my establishment.
Then ,I read this article.

I want to store my my-init-texmacs file and my personal packages on my key.

I would therefore like to have my TeXmacs_path_home on my usb key.

I created a folder called “share” with the subfolders (bin,docs,font,langs,misc,etc…)
Since I don’t want to use the my-init-texmacs file when starting texmacs (if I change computers it’s not there anymore), I place the following scheme command directly at the end
of the init-texmacs.scm file.

(setenv “TEXMACS_HOME_PATH” (string-append (getenv “TEXMACS_PATH”) “\share”)))

When restarting texmacs, texmacs opens to the welcome file and when I do this:

developer then open my-init-texmacs, I see that the file is well recognized in its location G:/TeXmacs-p/partage/progs

So it worked but the scheme commands (keyboard shortcuts…) of my my-init-texmacs.scm are not accessible in texmacs.

So I tried to load my-init-texmacs.scm file as a module. For this, I wrote at the end of my init-texmacs.scm:

(load (string-append (getenv “TEXMACS_PATH”) “\share\progs\my-init-texmacs.scm”)))

I have used this command before on ubuntu. It works well under ubuntu but it does not work under windows (is it a path problem?)

I would also like to be able to put my “packages” files in my share\packages folder. I tried but that doesn’t work either.

Thanks for any help you may have.

The reason why it does not work might be because backslashes need to be escaped.
Pls. try “\\share\\progs\\my-init-texmacs.scm”.

My suggestion appears inconsistent with your statement that

 (setenv “TEXMACS_HOME_PATH” (string-append (getenv “TEXMACS_PATH”) “\share”)))

works and I did not analyze that, but pls. try nevertheless.

This said, keep in mind that testing your commands in a Scheme session helps you in debugging. I tried your

(string-append (getenv "TEXMACS_PATH") "\share\progs\my-init-texmacs.scm")

and I got

#<unknown port>:1:43: illegal character in escape sequence: #\s

Good morning,
I did escape the slashes.
It is by pasting the code that the slashes have disappeared.
I am testing well in scheme sessions.
Here is what it gives:

The error message says that at line 20 of your my-init-texmacs there is an “unexpected “)””. Would you be able to post that line?

I found my mistake and now I can load the my-init-texmacs file from my “share” folder.
I thought I could use this command by putting it at the end of the init-texmacs file but it doesn’t work.
In fact, I have to go through a session scheme and it’s not convenient.
I would like to launch this “new” my-init-texmacs when starting texmacs…
and if possible, I would also like to launch the “preferences.scm” file otherwise when I restart on another computer with my usb key the my-init-texmacs and preferences.scm files are not recognized.

Your description looks interesting but I did not understand it :slight_smile:
If you give me a bit of time I will try myself and tell you what happens.
I also would be interested in knowing what is the mistake you found: was it in line 20 of my-init-texmacs?

My error was simply an error in forgetting parentheses with a standard function to test the command.
I’m sure that having a texmacs -portable that works on a usb key and that is completely independent of the computer would be interesting. This might lead some math teachers around me to try it.
I managed to make it work with a python-portable on the same usb-key…
The python plugin then works fine
I also think we could connect it to a Miktex-portable.
I will do other tests but I am not an expert…
Thus, we would have everything in the USB key.

I think using a my-init-texmacs at a custom location must work. The end of init-texmacs.scm does not seem the right place where to load my-init-texmacs. Setting the environment variable TEXMACS_HOME_PATH before launching TeXmacs (reference Texmacs_home_path) maybe is not possible or convenient on Windows.

I did not yet figure out how TeXmacs finds and reads my-init-texmacs.
Let us see what someone else says.

The “right” way would be to set the environment variable “TEXMACS_HOME_PATH” before you run TeXmacs, not after, because then it is too late. Windows do not make it easy, but one way should be to create a “.BAT” file and there set the variable and call TeXmacs. See for example : https://superuser.com/questions/424001/launch-windows-program-with-custom-environment-variable

The other suggestion is stop using Windows…

“TEXMACS_HOME_PATH”?

Yes, sorry. I will correct it.
Btw, if you just want to change TEXMACS_PATH TeXmacs accepts it as an argument in the command invocation with the option -p .... But there is no flag to set TEXMACS_HOME_PATH.

A more sophisticated way to do this is install a Linux in your usb disk. Then you have not only TeXmacs, but a whole grab-n-go operating system :slight_smile:

THANKS.
I already have bootable usb keys with xubuntu. I installed texmacs and all the plugins work as well as on a standard installation.
If I persist in wanting to use a portable version of texmacs on windows, it is because in my establishment the network managers have prevented the computers from booting using a USB key.
it’s my problem.

I think it is still worth trying to help.
I tested the suggestion in @mgubi’s link (https://superuser.com/questions/424001/launch-windows-program-with-custom-environment-variable), and we are maybe close to getting it to work.
I have been able to run TeXmacs from the the command line (cmd.exe), but not from a batch file

The last version of the batch file I tried (includes attempts at diagnosing the failure) is

:: type "C:\Users\admin\Dati\Test\Test TeXmacs\launch_texmacs.bat"
@ECHO OFF
SETLOCAL
SET TEXMACS_HOME_PATH="C:\Users\admin\Dati\Test\Test TeXmacs home dir"
cd "C:\Program Files (x86)\TeXmacs\bin"
if exist "texmacs.exe" (echo texmacs exists)
if not exist "texmacs.exe" (echo texmacs does not exists)
start /b /wait "" "texmacs.exe" > "C:\Users\admin\Dati\Test\Test TeXmacs\launch_texmacs.txt" 2>&1
if not %errorlevel% == 0 exit /b
else echo %errorlevel%

and it fails with the output that I paste below (copying from launch_texmacs.txt). Perhaps someone knows what happens.

TeXmacs] std-warning, Couldn't concretize ? (concat, "C:, ? (concat, Users, ? (concat, admin, ? (concat, Dati, ? (concat, Test, Test TeXmacs home dir")))))

... many lines like this

TeXmacs] std-warning, Couldn't concretize "C:
TeXmacs] std-warning, Couldn't concretize ? (concat, "C:, Users)
TeXmacs] std-warning, Couldn't concretize ? (concat, "C:, ? (concat, Users, admin))
TeXmacs] std-warning, Couldn't concretize ? (concat, "C:, ? (concat, Users, ? (concat, admin, Dati)))

... many lines like this

TeXmacs] std-warning, Couldn't concretize ? (concat, "C:, ? (concat, Users, ? (concat, admin, ? (concat, Dati, ? (concat, Test, ? (concat, Test TeXmacs home dir", users))))))
TeXmacs] std-warning, Save error for C:\Program Files (x86)\TeXmacs\bin\"C:\Users\admin\Dati\Test\Test TeXmacs home dir"\system\boot_lock, Invalid argument
Welcome to TeXmacs 2.1.1
------------------------------------------------------------------------------
kpsewhich works with your TeX distribution
maketfm works with your TeX distribution
makepk works with your TeX distribution
texhash works with your TeX distribution
attempt install of inkscape extension 
 TeXmacs] std-warning, Save error for C:\Program Files (x86)\TeXmacs\bin\"C:\Users\admin\Dati\Test\Test TeXmacs home dir"\system\settings.scm, Invalid argument
TeXmacs] failed-error, ------------------------------------------------------------------------------
TeXmacs] failed-error, I could not save or reload the file
TeXmacs] failed-error, 
TeXmacs] failed-error, 	"C:\Users\admin\Dati\Test\Test TeXmacs home dir"\system\settings.scm
TeXmacs] failed-error, 
TeXmacs] failed-error, Please give me full access control over this file and
TeXmacs] failed-error, rerun 'TeXmacs'.
TeXmacs] failed-error, ------------------------------------------------------------------------------
Throwing unable to write settings
-------------------------------------------------
Error message:
  unable to write settings

System information:
  TeXmacs version  : 2.1.1
  Built by         : magix
  Building date    : Mon Dec 13 10:36:58 CET 2021
  Operating system : mingw32
  Vendor           : w64
  Processor        : @CONFIG_HOST_CPU@
  Crash date       : 

TeXmacs server not yet started
Backtrace of C++ stack not supported

-------------------------------------------------
terminate called after throwing an instance of 'string'

Seems that quoting in SET does not work as you are using it, see: https://ss64.com/nt/set.html try to remove quotes or put them differently.

As an aside, if your school (I assume that) administrator doesn’t fully ban boot from usb, you can open the case and disconnect their shipped disk. Then your usb becomes the first bootable medium.

Following up on @mgubi’s suggestion I got the batch file to work.

You could adapt the following batch file to your system

@ECHO OFF
SETLOCAL
SET "TEXMACS_HOME_PATH=E:\Varie\Test\Test TeXmacs\TeXmacs_custom_home"
cd "C:\Program Files (x86)\TeXmacs\bin"
rem start /b /wait "" "texmacs.exe" > "E:\Varie\Test\Test TeXmacs\15 - Windows\start_TeXmacs.bat\launch_texmacs.txt" 2>&1
start "" "texmacs.exe"

I have left the commented line (remove rem to uncomment)

rem start /b /wait "" "texmacs.exe" > "E:\Varie\Test\Test TeXmacs\15 - Windows\start_TeXmacs.bat\launch_texmacs.txt" 2>&1

because it may help with debugging in case debugging is needed (it has to be substituted to the line start "" "texmacs.exe" which in turn needs to be commented).

Once that you have the batch file, double click on it and TeXmacs should start with the home path that you set.

1 Like

Good morning,
thank you very much for the time spent.
Here is my file to start texmacs on my usb key.

@ECHO OFF
SETLOCAL
SET “TEXMACS_HOME_PATH=%~d0%~p0TeXmacs-p\partage”
cd “%~d0%~p0TeXmacs-p\bin”
start “” “texmacs.exe”

It works with a key labeled with any letter. It works very well!
I can now use my packages, my file my-init-texmacs.scm, my-preferences.scm etc… by changing computer…

2 Likes