34

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:

enter image description here

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):

enter image description here

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.

CarLaTeX
  • 62,716

2 Answers2

28

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}

enter image description here or enter image description here

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}

enter image description here

Ulrike Fischer
  • 327,261
19

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}

enter image description here

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: enter image description here

Skillmon
  • 60,462
  • 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 ;-) – Thorbjørn E. K. Christensen Mar 13 '18 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 :) – Skillmon Mar 13 '18 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 ;-) – Thorbjørn E. K. Christensen Mar 13 '18 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. – Skillmon Mar 13 '18 at 11:43
  • And writing a hundred paragraphs more on the duck story, so all text needs can be fufilled by ducks and ducks alone ;-) – Thorbjørn E. K. Christensen Mar 13 '18 at 11:52
  • 2
    @ThorbjørnE.K.Christensen uploaded it to CTAN :) – Skillmon Mar 13 '18 at 18:55
  • The story of the blind duck is great -- so many nice details! – samcarter_is_at_topanswers.xyz Mar 13 '18 at 22:00
  • @samcarter thank you very much. You might contribute. If we really want to dethrone lipsum we have to write a whole duck epos. – Skillmon Mar 13 '18 at 22:31
  • I have teary eyes. I don't even know why exactly. Such are the emotions over the blind duck beginning of an epos! – thymaro Mar 15 '18 at 07:27
  • @Ignasi great to see it spread! I have just one problem with the early usage of it. It is not contained in TeXLive atm (but already in MikTeX). Therefore one needs to install it manually if he doesn't use the latest MikTeX -- just to reproduce something on TeX.SX. Still great! – Skillmon Mar 15 '18 at 12:04
  • Is there any possibility get first duck, second duck etc. like example-image-a – Khaaba Apr 22 '18 at 07:38
  • is it possible to have the duck images as portraits, too? it would make more sense to have them, e.g. for CVs or biographies. – naphaneal Jul 03 '18 at 21:32
  • @Khaaba you can use the page key of graphicx, e.g., \includegraphics[page=1]{example-image-duck}. And if you actually load duckuments together with graphicx (order doesn't matter), you'll get a random duck each time. – Skillmon Jan 18 '20 at 22:19
  • @naphaneal example-image-duck-portrait is included (since quite some time now, just forgot to notify you it seems). – Skillmon Jan 18 '20 at 22:20