latex2e icon indicating copy to clipboard operation
latex2e copied to clipboard

Command '\listfiles' breaks up filename with a comma

Open paultjevdh opened this issue 5 months ago • 11 comments

Brief outline of the bug

The purpose of \listfiles is to generate a list of the files (filenames) used by the current document and write this list to the log file. When a file has a comma in its filename, the file is processed correctly by LaTeX, but in the list of files in the log file, this name is broken at the comma. In addition, the first part of the name is assigned a .tex file-extension.

This breaks further automatic processing of this list by for example bundledoc.

Minimal example showing the bug

Enclosed is a set of two files: Comma_MWE.zip. Comma_MWE.zip Expected output in the log file is

File List article.cls 2025/01/22 v1.4n Standard LaTeX document class size10.clo 2025/01/22 v1.4n Standard LaTeX file (size option) l3backend-dvips.def 2025-10-09 L3 backend support: dvips File_with_,_comma_in_the_name.txt

Actual output is:

File List article.cls 2025/01/22 v1.4n Standard LaTeX document class size10.clo 2025/01/22 v1.4n Standard LaTeX file (size option) l3backend-dvips.def 2025-10-09 L3 backend support: dvips File_with_.tex _comma_in_the_name.txt

Log file (required) and possibly PDF file

Listfile_comma_MWE.log

Best regards, Paul

paultjevdh avatar Nov 26 '25 15:11 paultjevdh

My immediate thought is simply to brace all of the file list entries:

\def\@addtofilelist#1{\xdef\@filelist{\@filelist,{#1}}}%

josephwright avatar Nov 26 '25 16:11 josephwright

I'm calling this an enhancement as classically you'd simply not have files with commas in the name ...

josephwright avatar Nov 27 '25 08:11 josephwright

I strongly disagree. On windows (pre NTFS) you may be right, but on unix I don't think the comma has ever been special, just a little unusual. I got the problematic file from a unix system where the operator followed standard (unix) procedures. Acknowledging that valid characters are treated different is a really bugfix, not an enhancement.

paultjevdh avatar Nov 27 '25 08:11 paultjevdh

@paultjevdh You are thinking of quite a limited range of file systems :-) I'm bearing in mind things like Joliet/ISO 9660, where commas were definitely not allowed in filenames. Remember 2e was released in 1994 ....

josephwright avatar Nov 27 '25 09:11 josephwright

You've got a point there, but I remember having to install linux as your best chance of running latex at all in those days. In my mind, historically LaTeX on unix/linux is the baseline. The fact that commas haven't occurred on many file-systems for a long time is not a very good excuse to disallow them at the application level, presumably including unix/linux. I don't know though, when or on what platform this command was added. The author was probably 'thinking of quite a limited range of file systems :-)' back then.

paultjevdh avatar Nov 27 '25 10:11 paultjevdh

@paultjevdh \listfiles is primarily about 'system' LaTeX files, which more or less means ones on CTAN, and they have enforced filename restrictions for a long time

josephwright avatar Nov 27 '25 10:11 josephwright

Hmm, well when users/user-files get involved things tend to get messy. Let's agree to disagree.

paultjevdh avatar Nov 27 '25 10:11 paultjevdh

@paultjevdh well as you may have seen https://github.com/latex3/latex2e/pull/1922 adjusts this as you suggest.

There is still the general question of how far latex should go to support such files, for example while it is true that a,b.sty is a perfectly valid filename, it causes problems in any inteface taking a comma separated list of names. \usepackage{a,b} for example.

I don't think it's unreasonable to simply say such files are not supported rather than inplementing some quoting mechanism.

You can also have files with names starting with white space that are similary unsupported <space>a.sty is a legal filename but latex will not include it if you go \usepackage{ a} A more drastic example is filenames involving " the underlying web2c tex file operations provide no way to access a file with " in its name as " is just used for quoting spaces. " "a.sty for example is a filename starting with a space, not a filename starting with ".

davidcarlisle avatar Nov 27 '25 11:11 davidcarlisle

I'm totally fine with having to include these exceptional files between double quotes, or in curly braces \usepackage{"a","b"} or \usepackage{{a},{b}} (this similar to current behaviour of graphicspath: \graphicspath{{subdir1/}{subdir2/}{subdir3/}...{subdirn/}}, but without the comma).

I would have to think about a file name with double quotes in it, but probably that would work in LaTeX by escaping with backslash: '\"'? Then \listfiles should also catch this. Cannot do that on windows though: Image ...so there is no issue at my end.

PS I find your example surprising. I would have expected to write " a.sty" rather than " "a.sty .

paultjevdh avatar Nov 27 '25 11:11 paultjevdh

I would have to think about a file name with double quotes in it, but probably that would work in LaTeX by escaping with backslash: '"'?

No - as @davidcarlisle says, this is not supported by web2c at all - you cannot use " in filenames called from TeX processes as a result. Quote marks can only be used to escape spaces - and the kernel goes to efforts to ensure that this is enforced.

josephwright avatar Nov 27 '25 12:11 josephwright

@paultjevdh

PS I find your example surprising. I would have expected to write " a.sty" rather than " "a.sty .

You can write either of those or " a.s"ty or similar, spaces between pairs of " are kept then all " (including a remaining one if there are an odd number) are removed to form the resulting filename. LaTeX has no control over this at all.

davidcarlisle avatar Nov 27 '25 13:11 davidcarlisle