# Getting ducks in example images

This question led to a new package:
duckuments

There are lots of cool example pictures in LaTeX. As far as I'm aware there aren't any good example duck images ;-(

Having ducks in the example images is, of course, essential for increasing the duckness of MWEs all over Tex.SE!

Thus I'd like to know: how do I get the duck to be in the center of an example image?

\documentclass[border=5pt]{standalone}
\usepackage{tikzducks}
\usepackage{graphicx}

\begin{document}
\includegraphics{example-image-a}
\tikz\randuck;
\end{document}


might produce:

There is, however, a problem with putting the duck next to the picture: it looks like a more permanent duck, not there for an example but there for all time. While every good duckument does feature a duck or a dozen, making the reader able to distinguish permanent and example ducks seems essential!

However, currently

\documentclass[border=5pt]{standalone}
\usepackage{tikzducks}
\usepackage{graphicx}

\begin{document}
\includegraphics{example-image-duck} %or with randuck
\tikz\randuck;
\end{document}


produces, with an error message (saying there is no file for the wanted example image):

Here there is no gray border telling the reader not to expect the duck in the final version of the duckument.

Is there any way I can get the two commands:

\includegraphics{example-image-duck}
\includegraphics{example-image-randuck}


To make an image like the one in the first example, but with a duck in the place of the a?

# Edit

It would be really cool, but it's probably not going to happen, to have the full tikzducks capabilities:

\includegraphics{example-image-duck[options]}


would thus act like options.

Also Torbjørn T. Posted the command:

\newcommand\ExampleDuck{ \begin{tikzpicture} \node [inner sep=0] {\includegraphics{example-image}}; \begin{scope}[shift={(-1,-1)}] \randuck \end{scope} \end{tikzpicture}}


that just needs an empty example image to be perfect. Now the only big hurdle is feeding includegraphics the result of the command \ExampleDuck if example-image-randuck is being loaded.

• this calls for our resident duck expert @PauloCereda ;) Mar 12, 2018 at 12:20
• Seems to be difficult, as \includegraphics expects ready-made pdf/png/ps files (like those in the mwe package). Mar 12, 2018 at 12:26
• ignoring the random one, you can make \includegraphics{example-image-duck} work simply by uploading example-image-duck.{eps,png} to ctan. Mar 12, 2018 at 12:32
• maybe add a feature request at bitbucket.org/martin_scharrer/mwe ? Mar 12, 2018 at 12:51
• @AlexG graphicx is a duck free zone:-) Mar 12, 2018 at 13:16

## 2 Answers

Write a document example-duck:

\documentclass[tikz,multi]{standalone}
\usepackage{tikzducks}
\begin{document}
\foreach\x in {1,2,...,100}
{\tikz\randuck;}
\end{document}


and compile it.

Then you can use it like this:

\documentclass{article}
\usepackage{xfp,graphicx}
\newcommand\getduck{\fpeval{randint(1,100)}}

\begin{document}

\includegraphics[page=\getduck]{example-duck}

\includegraphics[page=\getduck]{example-duck}

\includegraphics[page=\getduck]{example-duck}

\end{document}


or

## Edit

as requested in the comments here a more refined example-duck (the pointy head of the witch needs a rather large background):

\documentclass[tikz,multi]{standalone}
\usepackage{tikzducks}
\begin{document}
\foreach\x in {1,2,...,100}
{\begin{tikzpicture}
\draw[fill=gray!50!white](-0.8,-0.8)rectangle(3,3);
\draw[gray] (-0.8,-0.8)--(3,3)
(3,-0.8)--(-0.8,3)
(-0.8,1.1)--++(3.8,0)
(1.1,-0.8)--++(0,3.8)
;
\randuck;
\node [anchor=center,rounded corners,draw=darkgray,opacity=0.5,fill=lightgray,rotate=30,font=\sffamily] at (1.1,1.1) {example duck};
\end{tikzpicture}}
\end{document}


• But these ducks look like nice permanent ducks. How will my editor know that they will not be in my final duckument? I sure do need my gray boxes ;-) Mar 12, 2018 at 13:02
• Really nice answer. I do realize that I could join it with the comment by @TorbjørnT. To get the gray box ;-) Mar 12, 2018 at 13:03
• Hm. Do you want also a watermark "example-duck" over the duck? Mar 12, 2018 at 13:06
• I had not thought of that. but that would be equally nice to having the example background. Mar 12, 2018 at 13:06
• @ThorbjørnE.K.Christensen Maybe it would be better to have getduck etc in a separate package. I don't think it is worth loading the tikzducks package in every document where one wants to insert some dummy image. tikz, which is automatically loaded by the ducks is a very heavy package, which needs a lot of time to load and has a lot of potential to cause problems with other packages. Adding the the example-duck.pdf to the package sounds fine, I just don't have any experience if CTAN would like that? Mar 12, 2018 at 13:54

The following could be used:

\documentclass[]{article}

\usepackage{tikzducks}
\usepackage{adjustbox}

\newcommand\exampleDuck[1][]
{%
\adjustbox{#1}{%
\begin{tikzpicture}
\draw[black,fill=gray!50,thick] (0,0) rectangle (6,4);
\draw[gray] (0,0) -- (6,4);
\draw[gray] (0,4) -- (6,0);
\draw[gray] (3,0) -- (3,4);
\draw[gray] (0,2) -- (6,2);
\node at (3,2) {\tikz\randuck;};
\end{tikzpicture}
}%
}

\begin{document}
\exampleDuck[width=2cm]

\exampleDuck[height=5cm]

\exampleDuck
\end{document}


With this package you can also use the following (also on github):

\documentclass[]{article}

\usepackage{graphicx}
\usepackage{duckuments}

\begin{document}
\noindent
\includegraphics[width=.5\textwidth]{example-image-duck}% takes a random page from the pdf
\includegraphics[width=.5\textwidth]{example-image-a}% still working

\blindduck% print one paragraph of text

\duckument% print a small duckument

\end{document}


Result:

• Thanks for your answer (I feel that the other answer is more inline with my question, hence why it's accepted). I must give you the maddest of all the props for writing a package that gives filler duck text. I feel like one should write a package containing a duck roman, just to try rivaling the lipsum package ;-) Mar 13, 2018 at 11:31
• @ThorbjørnE.K.Christensen That's the idea of the package (in addition to patching \includegraphics to work with example-image-duck). But this morning between 1am and 2am I was just to tired to write something better than the above. Feel free to commit to the package :) Mar 13, 2018 at 11:36
• I might do that at some point ;-) It's a really cool idea to have a total duckification of all example parts of all duckuments. all hail the king duck ;-) Mar 13, 2018 at 11:38
• @ThorbjørnE.K.Christensen the package also contains enumerate, itemize and description duckifications (nested and unnested). Next on the to-do-list is turning it into a *.dtx, small duckumentation and uploading on CTAN. Mar 13, 2018 at 11:43
• @ThorbjørnE.K.Christensen uploaded it to CTAN :) Mar 13, 2018 at 18:55