Hi,
a Brazilian friend was trying my ConTeXt scoop package and we saw a
failure. The details below which I collected with an AI help, so take that
into consideration (real username having a Portuguese character is replaced
with another one which should trigger the same problem)...
Jiri
---%>---
`aux_utf8_getownpath` uses the ANSI `GetModuleFileName`, so ConTeXt LMTX
fails on install paths with non-ASCII characters ("startup error : no
format file given, quitting")
## Environment
- **OS:** Windows 10/11
- **ConTeXt LMTX** (luametatex), recent rolling release (reproduced with
the `context-win64.zip` bootstrap dated 2026.09.10)
- **Install path (any path under a non-ASCII user profile), e.g.:**
```
C:\Users\José\scoop\apps\context\2026.09.10
```
The trigger is the non-ASCII character `é` (U+00E9) in the username. Any
non-ASCII character in the install path should reproduce it.
## Summary
On Windows, when ConTeXt LMTX is installed into a directory whose path
contains a
non-ASCII character (e.g. the user profile `C:\Users\José\...`),
`mtxrun.exe` aborts immediately with:
```
startup error : no format file given, quitting
```
even though `mtxrun.lua` is present in the same directory as the binary and
the
archive is a clean, correct extraction. The same bootstrap works fine when
the
install path is pure ASCII.
## Steps to reproduce
1. Download the bootstrap archive:
```
https://lmtx.pragma-ade.com/install-lmtx/context-win64.zip
```
2. Extract it into a directory whose path contains a non-ASCII character,
e.g.
```
C:\Users\José\ctx\
```
(so the binary ends up at `C:\Users\José\ctx\bin\mtxrun.exe`).
3. Run any mtxrun command, e.g.:
```
C:\Users\José\ctx\bin\mtxrun.exe --version
```
or run `install.bat`.
### Observed result
```
startup error : no format file given, quitting
```
(exit code 1). The same command works when the tree is extracted to an
ASCII path
(e.g. `C:\ctx\`).
## Root cause
The engine locates itself and its Lua runner in `tex_engine_initialize()`
(`source/lua/lmtenginelib.c`) via `aux_utf8_getownpath()` and
`enginelib_splitnames()`. Before parsing any command-line arguments,
`enginelib_parse_options()` checks whether `<owndir>/mtxrun.lmt` or
`<owndir>/mtxrun.lua` is readable; if not, no format is found and the engine
aborts with "no format file given".
The directory comes from `aux_utf8_getownpath()` in
`source/utilities/auxfile.c` (Windows branch):
```c
char *aux_utf8_getownpath(const char *file)
{
if (file) {
char *path = NULL;
char buffer[MAX_PATH];
GetModuleFileName(NULL, buffer, sizeof(buffer));
path = lmt_memory_strdup(buffer);
...
}
return lmt_memory_strdup(".");
}
```
`GetModuleFileName` resolves to the **ANSI** variant (`GetModuleFileNameA`)
here,
so the returned path is encoded in the system's ANSI code page (e.g.
Windows-1252),
not UTF-8. The rest of the codebase, however, treats these path strings as
UTF-8:
- `argv` is produced as UTF-8 via `aux_utf8_setargv()`
(`CommandLineToArgvW` + `aux_utf8_from_wide()`),
- `aux_utf8_to_wide()` converts with `MultiByteToWideChar(CP_UTF8, ...)`,
- `aux_utf8_from_wide()` converts with `WideCharToMultiByte(CP_UTF8, ...)`,
- `aux_is_readable()` and `aux_utf8_fopen()` go through
`aux_utf8_to_wide()`.
With a non-ASCII character in the path, `GetModuleFileNameA` emits a
code-page
byte (e.g. `0xE9` for `é` in Windows-1252) that is later misinterpreted as
UTF-8.
The path is corrupted, the `mtxrun.lua` existence check fails, and the
engine
aborts with "no format file given".
## Proposed fix
Use the wide API and convert through the existing UTF-8 helper so the
encoding is
consistent with the rest of the codebase:
```c
char *aux_utf8_getownpath(const char *file)
{
if (file) {
wchar_t buffer[MAX_PATH];
DWORD length = GetModuleFileNameW(NULL, buffer, MAX_PATH);
if (length > 0 && length < MAX_PATH) {
char *path = aux_utf8_from_wide(buffer);
if (path && strlen(path) > 0) {
for (size_t i = 0; i < strlen(path); i++) {
if (path[i] == '\\') {
path[i] = '/';
}
}
return path;
}
}
}
return lmt_memory_strdup(".");
}
```
`aux_utf8_from_wide()` is already defined in the same file, so no new
includes or
helpers are required. A hardened version that also handles paths longer than
`MAX_PATH` can grow the buffer in a loop, but the minimal change above
resolves the
encoding bug.
## Notes
- This affects both a manual install (`install.bat`) and third-party
packaging
(e.g. the Scoop manifest for ConTeXt LMTX), because the failure happens
in the
engine's self-location regardless of how it was launched.
- Workaround until fixed: install ConTeXt LMTX into a pure-ASCII path, or
enable
"Beta: Use Unicode UTF-8 for worldwide language support" so the ANSI code
page
is UTF-8.
---%<---
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the
Wiki!
maillist : [email protected] /
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________