I recently switched to demo such that I could compile my .tex file without needing the actual image files. Now, instead of the image there is a black box. Is there anyway to get a black border such that when I am printing copies of this I don't waste precious black ink.
-
Your precious black ink, haha – Daniel Jun 06 '13 at 18:18
-
1@Daniel in these hard financial times, every penny counts – puk Jun 07 '13 at 21:01
4 Answers
\usepackage{graphicx}
\makeatletter
\AtBeginDocument{%
\def\Ginclude@graphics#1{%
\begingroup\fboxsep=-\fboxrule
\fbox{\rule{\@ifundefined{Gin@@ewidth}{150pt}{\Gin@@ewidth}}{0pt}%
\rule{0pt}{\@ifundefined{Gin@@eheight}{100pt}{\Gin@@eheight}}}\endgroup}}
\makeatother
- 1,121,712
-
11I wonder why
graphicsdoesn't do that automatically when the draft option is set. – Caramdir Oct 05 '11 at 23:01 -
1
-
@egreg Any way to wrap this in a macro so that I can call it when I want it? I changed
#1to##1when it is wrapped, but I run into trouble because my includegraphics path is a macro itself. So paths look like\maclibrary Images/pic.jpg(##1). It works, but not if I want to write the file path to the page e.g.\parbox{\@ifundefined{Gin@@ewidth}{150pt}{\Gin@@ewidth}}{##1}– Jonathan Komar May 03 '16 at 13:19 -
-
@egreg Nevermind. I think the problem is my macro expands to underscores! I am foolish for not recognizing that some images have underscores in the filenames! Lesson here that I should have learned a long time ago: file system naming conventions do not overlap with LaTeX character category code conventions! – Jonathan Komar May 03 '16 at 13:58
Since the demo option to graphicx makes all \includegraphics commands print a 150pt x 100pt rectangle and there's no way around that easily, you could just redefine the \includegraphics command:
\renewcommand{\includegraphics}[2][]{%
\setlength{\fboxsep}{-\fboxrule}% Remove frame separator/gap
\framebox{\rule{0pt}{100pt}\rule{150pt}{0pt}}% Framed box of 150pt x 100pt
}
Now you can remove the demo option from graphicx and use the document as is with the same \framebox-filled result. Since the command has the same format \includegraphics[..]{...}, no further modifications are needed; all arguments (both optional and mandatory) are discarded.
- 603,163
Here is another way (albeit slightly overkill with \tkiz for drawing the box, but you can adapt the other solutions for the box drawing if that is not desired -- I tend to think \tikz first for some reason :-). The only real enhancement here from the other solutions is to use \def\DemoOption{demo} when in demo mode and \def\DemoOption{} when not in demo mode. This could be improved by using a command line option to set \DemoOption.
Since the graphicx pacakge defines \def\Ginclude@graphics when in demo mode, we just need to redfine that after \begin{document}:
\def\DemoOption{demo}% Use this in demo mode
%\def\DemoOption{}% Use this when done want figures included
\RequirePackage[\DemoOption]{graphicx}
\documentclass{article}
\usepackage{tikz}
\usepackage{xstring}
\begin{document}
\makeatletter%
\IfStrEq{\DemoOption}{demo}{%
\renewcommand{\Ginclude@graphics}[1]{%
\tikz \draw (0,0) rectangle (150pt,100pt);%
}}{}%
\makeatother
\includegraphics{whatever}
\end{document}
- 223,288
You can use the package draftfigure to get the same result and modify the display of the switched off figure:
\documentclass{article}
\usepackage{graphicx}
\usepackage[allfiguresdraft]{draftfigure}
\begin{document}
\includegraphics[width=50pt]{example-image-a}
\includegraphics[draft=false,width=50pt]{example-image-b}
\setdf{content={This figure is switched off.}}
\includegraphics[width=50pt]{example-image-c}
\end{document}
- 3,015
- 1
- 16
- 37
