Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphics inclusion fails (for some drivers) in \endlinechar-1 context #286

Closed
jfbu opened this issue Feb 23, 2020 · 8 comments
Closed

Graphics inclusion fails (for some drivers) in \endlinechar-1 context #286

jfbu opened this issue Feb 23, 2020 · 8 comments

Comments

@jfbu
Copy link

jfbu commented Feb 23, 2020

Minimal example showing the bug

% compile with latex (+dvips+ps2pdf)
% similar example can be done with platex (+dvipdfmx) with a png image
\RequirePackage{latexbug}
\documentclass{article}
\usepackage{graphicx}
\begin{document}
{\endlinechar-1
\includegraphics{example-image.eps}}
\end{document}

The graphics inclusion code wants to do \catcode\endlinechar 5 and this breaks if \endlinechar has been set to -1.

! Bad character code (-1).
\Gread@generic@aux ...`\	10 \catcode \endlinechar 
                                                  5 \@makeother \:\@makeothe...
l.8 \includegraphics{example-image.eps}
                                       }
? X

In real life, the issue arose with platex + dvipdfmx (and dvipdfmx class option) and inclusion of a png file. The reason for the \endlinechar -1 is that this was embedded into some \scantokens and we wanted to avoid the space token this process induces. More precisely for some reason (having to do with using \href in some context with active characters needing deactivation) the \includegraphics was incorporated into the \everyeof toks (to freeze its catcodes and not have them submitted to \scantokens).

For this real life context, fix can be obtained by starting the \everyeof{} contents by \endlinechar13 .

Log file (required) and possibly PDF file

endlinechar.log

@davidcarlisle
Copy link
Member

davidcarlisle commented Feb 23, 2020

Thanks for the report, the issue is due to this change I guess

% \changes{v0.5e}{1994/1l/02}
%     {Fix the catcodes of \cs{endlinechar} and ctrl-D}

I think best thing to do would be to make sure \endlinechar is locally set to 13 in the "read" macros \Gread@generic@aux in graphics.sty and \Gread@@pdf in dvipdfmx.def, luatex.def etc.

@jfbu
Copy link
Author

jfbu commented Feb 23, 2020

% \changes{v0.5e}{1994/1l/02}

I am a slow tester, but give me a few decades and I can sometimes find things.

@FrankMittelbach
Copy link
Member

FrankMittelbach commented Feb 23, 2020 via email

@jfbu
Copy link
Author

jfbu commented Feb 23, 2020

@FrankMittelbach sadly only in 1994 could I have spotted that, nowadays that would require me to set my screen fonts to size \Huge. 😢 😉

@FrankMittelbach FrankMittelbach added this to Pool (unscheduled issues) in upcoming LaTeX2e releases via automation Mar 19, 2020
@FrankMittelbach FrankMittelbach moved this from Pool (unscheduled issues) to To do in upcoming LaTeX2e releases Mar 19, 2020
@stale
Copy link

stale bot commented Apr 24, 2020

This issue has been automatically marked as stale because it has not had recent activity.

@stale stale bot added the stale label Apr 24, 2020
@davidcarlisle
Copy link
Member

Despite my comment above, I think now dvipdfmx \Gread@pdf all use the core \Gread@generic@aux so it is enough to add

  \endlinechar13 %NEW

just before the catcode setting, so equivalent to the following (using [dvipdfmx] but also variants with dvips with latex, and with xetex).


\documentclass{article}
\usepackage[dvipdfmx]{graphicx}
\makeatletter
\def\Gread@generic@aux#1#2{%
  \begingroup
  \@tempcnta\z@
  \loop\ifnum\@tempcnta<\@xxxii
     \catcode\@tempcnta14 %
     \advance\@tempcnta\@ne
  \repeat
  \catcode`\^^?14 %
  \let\do\@makeother
  \dospecials
  \catcode`\ 10 %
  \catcode`\^^I10 %
  \endlinechar13 %NEW
  \catcode\endlinechar5 %
  \@makeother\:%
  \@makeother\-%
  \immediate\openin\@inputcheck\quote@name{#1} %
  #2{#1}%
  \ifGin@bbox
    \expandafter\xdef\csname #1 bbox\Gread@attr@hash\endcsname{\@gtempa}%
  \else
    \@latex@error
      {Cannot determine size of graphic in #1 (no BoundingBox)}%
      \@ehc
    \gdef\@gtempa{0 0 72 72 }%
  \fi
  \endgroup
}
\makeatother

\begin{document}
{\endlinechar-1
\includegraphics{example-image.eps}}
\end{document}

davidcarlisle added a commit that referenced this issue Aug 13, 2020
@davidcarlisle davidcarlisle added fixed in dev Fixed in development branch, not in stable release and removed stale labels Aug 13, 2020
@FrankMittelbach FrankMittelbach moved this from To do to Done in dev in upcoming LaTeX2e releases Aug 13, 2020
@FrankMittelbach
Copy link
Member

Plan to write a short entry for doc/ltnews32 ?

@davidcarlisle
Copy link
Member

davidcarlisle commented Aug 13, 2020 via email

upcoming LaTeX2e releases automation moved this from Done in dev to Done Sep 9, 2020
@FrankMittelbach FrankMittelbach removed the fixed in dev Fixed in development branch, not in stable release label Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

3 participants