\pdffilesize and spaces

Bruno Le Floch blflatex at gmail.com
Sun Oct 20 09:48:47 CEST 2019


On 10/20/19 1:56 AM, Reinhard Kotucha wrote:
> On 2019-10-18 at 15:26:24 -0600, Karl Berry wrote:
>
>  > I think there is no way to use \pdffilesize etc. on arbitrary
>  > filenames. Maybe they can be made to work with one space, but 2+
>  > consecutive spaces in the input will get transmuted into one by
>  > TeX's scanner before the primitive over sees it, if I understand
>  > correctly. Catcode 9 characters will likewise disappear, etc., etc.
>
> I can at least confirm that pdftex primitives like \pdfximage
> circumvent TeX's scanner and allow an arbitrary number of consecutive
> spaces in filenames.

Could you clarify what you mean?  Given the implementation in
pdftex.web, it's pretty clear that tokenization (including ignoring
consecutive spaces) still happens before \pdfximage receives its argument.

$ touch abc\ \ def
$ pdftex '\pdfximage{abc  def}'
<snip>
!pdfTeX error: pdftex (file abc def): cannot find image file
<snip>

$ touch ghi\ jkl
$ pdftex '\pdfximage{ghi  jkl}'
<snip>
!pdfTeX error: pdftex (file ./ghi jkl): reading image file failed
<snip>

It's easy to get spaces using the macro \space since everything is
expanded.  For \input, \openin etc you simply need to surround the whole
construction with quotes.

> The argument must be surrounded by braces.
> This is different from TeX, which assumes that a filename ends with a
> space.  I don't know whether all catcodes are considered but macros
> are expanded:
>
>   \pdfximage {\dir/\file}
>
> If catcode 9 makes particular characters inaccessible, pdftex
> primitives should be called from a macro which restores the original
> catcodes.  Admittedly, I've never seen anything in the TeX world which
> makes use of catcode 9.

\def\MakePercentIgnore{\catcode`\%9\relax}
in doc.sty and most other classes/packages to document code.

> IMO the fact that pdftex primitives do not collapse an arbitrary
> number of spaces into one is a great step forward.  It's much more
> difficult to deal with \input, \openin, and \openout.

Expansion is a little different for sure between the Knuth TeX
primitives and the pdfTeX ones, but the main difference in capability is
filenames with quotes.

Bruno


More information about the tex-live mailing list