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?

  • That's \texttt, most likely, this doesn't break – user31729 May 30 '16 at 20:52
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

| improve this answer | |
  • 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. – Frank Breitling May 31 '16 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.