# Include binary data

How do I include binary data (e.g. the contents of a binary file) in a LaTeX generated PDF-document? If I just copy and paste them into a verbatim environment it results in garbage.

-

## migrated from meta.tex.stackexchange.comMay 15 '11 at 11:03

This question came from our discussion, support, and feature requests site for users of TeX, LaTeX, ConTeXt, and related typesetting systems.

All I see in the above code is 7 V??#? <empty line> ?j. Please be more specific which characters you need. – Martin Scharrer May 15 '11 at 11:14
Also, urgency remarks like "please reply as soon as possible" will not get you answers sooner, and may ironically make people less likely to answer you. Everyone here's a volunteer and all answers are generously provided for free, but nobody's on your schedule. – Matthew Leingang May 15 '11 at 11:21
It might be helpful if you let us know what those characters are, i.e. where they come from. Did you open a binary file in a text editor and copy/paste the characters? – Jake May 15 '11 at 11:31
I completely reformulated the question to match what I think is intended. Because the intended question (and @Andrey's answer) are quite valuable. (To understand the comments above, please look at the edit history.) – Caramdir May 15 '11 at 16:54
I reopened the question (with two reopen votes already pending) because it is now reasonable phrased after @Caramdir's edit and has a suitable accepted answer with a good number of up-votes (ATM 7). People who down-voted this answer should now also reconsider to remove their vote from the edited question. Six down-votes seem to be a little much anyway. – Martin Scharrer May 15 '11 at 21:21

Normally people use a utility such as hexdump to view the content of binary files. It could be used to pre-format data for LaTeX, too:

\documentclass{article}

\usepackage{verbatim}

\begin{document}

\scriptsize              % Just so that it fits in line
\verbatiminput{dump.txt} % Generated with "hexdump -C" on Linux

\end{document}


The result:

EDIT: It turns out there's a LaTeX package hexdump. But it more or less does the same thing as above, the most notable addition being floating dumps with captions.

-
"floating dumps with captions" ... the mental image that that phrase creates will stay with me for a looong time. – Loop Space May 16 '11 at 8:29
@Andrew: I'm glad I'm not the only one. – TH. May 16 '11 at 9:57

You can use the attachfile package. Abstract:

This package defines an \attachfile` command that lets you attach arbitrary files to a pdf document. These files are embedded right in the pdf file, so they get transmitted along with it. The package also gives you control over the corresponding icon's properties and various other associated metadata.

-