4

Consider the following files main.tex and xyz.tex:

% main.tex
\documentclass{article}
\begin{document}
\newcommand\abc{XYZ.tex}
\input{\MakeLowercase{\abc}}
\end{document}

% xyz.tex (all lowercase letters) Hey, it works!

LaTeXing main.tex works under Windows (would even work without trying to lowercase the filename, as filenames are case-insensitive), while under Linux, it gives the error

! LaTeX Error: File `MakeLowercase {XYZ.tex}' not found.

Question: Why does it work under Windows, even though \MakeLowercase is not expandable? Shouldn't we expect identical behavior across OSes? What would it take to treat macros the same in both cases?

(I know how to achieve the desired effect of lowercasing the filename, by using e.g. \explower from the post Expandably change letter case and use inside \csname, without a package.)

gernot
  • 49,614

2 Answers2

7

We can see that LaTeX macros are changed from year to year. But TeX primitives keep unchanged. You can solve your problem by TeX primitive \lowercase:

\lowercase \expandafter{\expandafter\input \expandafter{\abc}}

If we have \def\abc{XYX.tex} then the command above is transformed to

\input {xyz.tex}

Win systems use case insensitive access to the file names(?), so it works without \lowercase too.

wipet
  • 74,238
4

Here's what happens on my machine (with a case-sensitive, sort of, file system).

With TL 2022 it seems to work, but I wouldn't rely on it.

TeX Live 2022

! LaTeX Error: File `xyz.tex' not found.

TeX Live 2021

! LaTeX Error: File `MakeLowercase {XYZ.tex}' not found.

TeX Live 2020

Hangs

TeX Live 2019

! Missing endcsname inserted.
<to be read again>
                   protect
l.4 \input{\MakeLowercase{\abc}}

TeX Live 2018 and earlier

! Illegal parameter number in definition of \@filef@und.
<to be read again>

l.4 \input{\MakeLowercase{\abc}}


With a recent LaTeX:

\documentclass{article}

\ExplSyntaxOn

\NewDocumentCommand{\lowercaseinput}{m} { \file_input:e { \str_lowercase:e { #1 } } } \cs_generate_variant:Nn \file_input:n { e } \cs_generate_variant:Nn \str_lowercase:n { e }

\ExplSyntaxOff

\begin{document}

\newcommand\abc{XYZ.tex}

\lowercaseinput{\abc}

\renewcommand\abc{XÝŽ.tex}

\lowercaseinput{\abc}

\end{document}

Note that this should also work with (most) UTF-8 characters. The console will show

! LaTeX Error: File 'xyz.tex' not found.

! LaTeX Error: File 'xýž.tex' not found.

egreg
  • 1,121,712