2

When I am using \includegraphics with the draft option

\includegraphics[draft]{long-image-name}

the image name is shown instead of the image. Unfortunately it appears on one line without lines breaks, so that it extends to the beyond the border and becomes unreadable. Is it possible to fix this?

1
  • That's \texttt, most likely, this doesn't break
    – user31729
    May 30, 2016 at 20:52

1 Answer 1

2

A horrible hack. But, hey! It works!

\documentclass{article}
\usepackage[draft]{graphicx}
\usepackage{xpatch}

\makeatletter
\patchcmd{\Gin@setfile}
 {\edef\@tempa{#3}\rlap{ \ttfamily\expandafter\strip@prefix\meaning\@tempa}}
 {\breitling@draftfilename{#3}}
 {}{\ddt}
\ExplSyntaxOn
\tl_new:N \l_breitling_filename_tl
\NewDocumentCommand{\breitling@draftfilename}{m}
 {
  \tl_set:Nx \l_breitling_filename_tl { #1 }
  \rlap{~\parbox{.9\Gin@req@width}{\small\ttfamily\raggedright
    \tl_map_inline:Nn \l_breitling_filename_tl { ##1 \hspace{0pt} }
  }}
 }
\ExplSyntaxOff
\makeatother

\begin{document}
\includegraphics[width=.7\textwidth]{long-file-name-about-ducks-that-is-meant-to-be-very-very-long}
\end{document}

Small height or width and a very long name might make the file name overlap the text above and below the rectangle.

enter image description here

1
  • Wow, what a hack! Thank you! I wish a solution would be implemented in \includegraphics because this is really an extreme hack and obfuscating tex files. Nevertheless I think it is important because without it the draft option is useless. May 31, 2016 at 9:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .