Skip to content

Commit

Permalink
Update \imagetest to reflect changes in graphicx package
Browse files Browse the repository at this point in the history
Based on the excellent answer of Axel Krypton (https://tex.stackexchange.com/a/567990/221054).
  • Loading branch information
LinqLover committed Mar 17, 2021
1 parent ca00158 commit 27496e4
Showing 1 changed file with 66 additions and 41 deletions.
107 changes: 66 additions & 41 deletions robustize-figures.tex
Original file line number Diff line number Diff line change
@@ -1,48 +1,73 @@
\let\StandardIncludeGraphics\includegraphics

%==========================================
% CREDITS: https://tex.stackexchange.com/questions/99070/check-for-a-valid-file-before-using-includegraphics/99099#99099
% CREDITS: https://tex.stackexchange.com/a/567990/221054
\makeatletter
\newif\ifgraphicexist

\catcode`\*=11
\newcommand\imagetest[1]{%
\begingroup
\global\graphicexisttrue
\let\input@path\Ginput@path
\filename@parse{#1}%
\ifx\filename@ext\relax
\@for\Gin@temp:=\Gin@extensions\do{%
\ifx\Gin@ext\relax
\Gin@getbase\Gin@temp
\fi}%
\else
\Gin@getbase{\Gin@sepdefault\filename@ext}%
\ifx\Gin@ext\relax
\global\graphicexistfalse
\def\Gin@base{\filename@area\filename@base}%
\edef\Gin@ext{\Gin@sepdefault\filename@ext}%
\fi
\fi
\ifx\Gin@ext\relax
\global\graphicexistfalse
\else
\@ifundefined{Gin@rule@\Gin@ext}%
{\global\graphicexistfalse}%
{}%
\fi
\ifx\Gin@ext\relax
\gdef\imageextension{unknown}%
\else
\xdef\imageextension{\Gin@ext}%
\fi
\endgroup
\ifgraphicexist
\expandafter \@firstoftwo
\else
\expandafter \@secondoftwo
\fi
}
\begingroup
\global\graphicexisttrue
\ifx\detokenize\@undefined\else
\edef\Gin@extensions{\detokenize\expandafter{\Gin@extensions}}%
\fi
\let\input@path\Ginput@path
\expandafter\filename@parse\expandafter{#1}%
\ifx\filename@ext\Gin@gzext
\expandafter\filename@parse\expandafter{\filename@base}%
\ifx\filename@ext\relax
\let\filename@ext\Gin@gzext
\else
\edef\Gin@ext{\Gin@ext\Gin@sepdefault\Gin@gzext}%
\fi
\fi
\ifx\filename@ext\relax
\@for\Gin@temp:=\Gin@extensions\do{%
\ifx\Gin@ext\relax
\Gin@getbase\Gin@temp
\fi}%
\else
\Gin@getbase{\Gin@sepdefault\filename@ext}%
\ifx\Gin@ext\relax
\global\graphicexistfalse
\let\Gin@savedbase\filename@base
\let\Gin@savedext\filename@ext
\edef\filename@base{\filename@base\Gin@sepdefault\filename@ext}%
\let\filename@ext\relax
\@for\Gin@temp:=\Gin@extensions\do{%
\ifx\Gin@ext\relax
\Gin@getbase\Gin@temp
\fi}%
\ifx\Gin@ext\relax
\let\filename@base\Gin@savedbase
\let\filename@ext\Gin@savedext
\fi
\fi
\ifx\Gin@ext\relax
\global\graphicexistfalse
\def\Gin@base{\filename@area\filename@base}%
\edef\Gin@ext{\Gin@sepdefault\filename@ext}%
\fi
\fi
\ifx\Gin@ext\relax
\global\graphicexistfalse
\else
\@ifundefined{Gin@rule@\Gin@ext}%
{\global\graphicexistfalse}%
{}%
\fi
\ifx\Gin@ext\relax
\gdef\imageextension{unknown}%
\else
\xdef\imageextension{\Gin@ext}%
\fi
\endgroup
\ifgraphicexist
\expandafter \@firstoftwo
\else
\expandafter \@secondoftwo
\fi
}
\catcode`\*=12
\makeatother
%==========================================
Expand All @@ -62,11 +87,11 @@
\centering
Missing figure

\texttt{#2}
\texttt{#2}

\medskip
\medskip

\shrug
\shrug
\vspace*{\fill}
\end{minipage}}
}
Expand Down

3 comments on commit 27496e4

@LinqLover
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the command is still failing when \includepdf is used somewhere in the document. I have already sent a private message to @AxelKrypton, I hope we will be able to solve this problem soon, too.

@AxelKrypton
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I improved my code and updated my answer on TEX.SE, which hopefully fixes your problem as well, which seems to be caused here,

\includepdf{figures/cover-edition-53.pdf}

since \includepdf internally uses \includegraphics which you redefined.

@LinqLover
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yahoo, it works again!

image

Thanks a lot for your work, @AxelKrypton!

Please sign in to comment.