On Sat, Jul 04, 2026 at 07:00:28AM +0000, Werner LEMBERG wrote:
> I couldn't find anywhere in the documentation that `@include` does not
> accept file names containing spaces.  AFAICS, since `@include` needs a
> line of its own, such a limitation is not necessary.  Compare this to
> LaTeX's `\input{...}` command, which also accepts file names with
> spaces.

My recommendation is just to avoid spaces in Texinfo file names.  We
could add this to the manual.

I notice that using double quotes around the file names works, but
not with texi2any.  So if you did

@include "test file.texi"

- that would not work with texi2any, but works in TeX due to the double
quotes being passed through to the underlying \input primitive.

Results may vary depending on TeX engine.  I tested with pdfTeX
3.141592653-2.6-1.40.25 (TeX Live 2023/Debian).

The Info manual for web2c states:

    TeX, Metafont, and MetaPost source programs can all read other source
    files with the '\input' (TeX) and 'input' (MF and MP) primitives:
         \input NAME % in TeX
    
       The file NAME can always be terminated with whitespace; for Metafont
    and MetaPost, the statement terminator ';' also works.  (LaTeX and other
    macro packages provide other interfaces to '\input' that allow different
    notation; here we are concerned only with the primitive operation.)
    
       As (allowed) extensions to standard TeX, Web2c also supports
    specifying the filename in double quotes ('"some name"') and in braces
    ('{some name}'), which is convenient for filenames containing spaces or
    other special characters, as described in the sections below.
    
       In all cases, space tokens are ignored after the filename is read.
    
       Also, double quote ('"') characters are ignored within the filename;
    there is no way to read files whose names contain a '"'.
    
       However, for maximal portability of your document across systems, use
    only the characters 'a'-'z', '0'-'9', and at most one '.'.  Do not use
    anything but simple filenames, since directory separators vary among
    systems; instead, add the necessary directories to the appropriate
    search path.

(node '(web2c)\input filenames').

So if we added double quotes (or curly braces) around the file name in
texinfo.tex all the time, this may not be 100% reliable as it is not a
standard feature of TeX.

I've made an attempt at wrapping braces around the file name only if it
has a space.  I've implemented this in a way that it should be easy to
remove if it turns out to cause problems.

This will not work if the file name has two spaces or more in a row,
however.

diff --git a/ChangeLog b/ChangeLog
index 566d61c4ee..872f3d46a2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2026-07-04  Gavin Smith <[email protected]>
+
+       * doc/texinfo.tex (\include): Check if the file name includes a
+       space character, and if it does, wrap the file name in { } before
+       running \input.
+       
+       Report from Werner Lemberg.
+
 2026-07-04  Gavin Smith <[email protected]>
 
        CONVERTER_FORMAT_DATA
diff --git a/doc/texinfo.tex b/doc/texinfo.tex
index dff4f6fe28..167abecb7a 100644
--- a/doc/texinfo.tex
+++ b/doc/texinfo.tex
@@ -3,7 +3,7 @@
 % Load plain if necessary, i.e., if running under initex.
 \expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi
 %
-\def\texinfoversion{2026-06-14.21}
+\def\texinfoversion{2026-07-04.10}
 %
 % Copyright 1985, 1986, 1988, 1990-2026 Free Software Foundation, Inc.
 %
@@ -765,22 +765,24 @@ where each line of input produces a line of output.}
 
 % @include FILE -- \input text of FILE.
 %
-\def\include{\parseargusing\filenamecatcodes\includezzz}
+\def\include{\tracingmacros=1\parseargusing\filenamecatcodes\includezzz}
 \def\includezzz#1{%
   \pushthisfilestack
   \def\thisfile{#1}%
+  \includecheckspace\thisfile
   {%
     \makevalueexpandable  % we want to expand any @value in FILE.
     \turnoffactive        % and allow special characters in the expansion
     \indexnofonts         % Allow `@@' and other weird things in file names.
     \wlog{texinfo.tex: doing @include of #1^^J}%
-    \edef\temp{\noexpand\input #1 }%
+    \edef\temp{\noexpand\input \thisfile }%
     %
     % This trickery is to read FILE outside of a group, in case it makes
     % definitions, etc.
     \expandafter
   }\temp
   \popthisfilestack
+  \def\thisfile{#1}% for @thisfile command
 }
 \def\filenamecatcodes{%
   \catcode`\\=\other
@@ -796,6 +798,21 @@ where each line of input produces a line of output.}
   \catcode`\'=\other
 }
 
+% \includecheckspace\FILENAME - if there is a space in the expansion of
+% \FILENAME, wrap the expansion in braces
+\def\includecheckspace#1{%
+  \expandafter\includecheckspacezz\expandafter#1#1 \includecheckspacezz}
+
+\def\includecheckspacezz#1#2 #3\includecheckspacezz{%
+  \def\tmp{#3}%
+  \ifx\tmp\empty
+    % no space in the file name
+  \else
+    % there is a space in the file name
+    \edef#1{{#1}}%
+  \fi
+}
+
 \def\pushthisfilestack{%
   \expandafter\pushthisfilestackX\popthisfilestack\StackTerm
 }


Reply via email to