6

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.

15
  • 5
    All I see in the above code is `7 V??#? <empty line> ?j. Please be more specific which characters you need. May 15, 2011 at 11:14
  • 7
    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. May 15, 2011 at 11:21
  • 2
    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, 2011 at 11:31
  • 6
    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, 2011 at 16:54
  • 2
    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. May 15, 2011 at 21:21

2 Answers 2

15

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:

output of hexdump included in LaTeX


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.

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

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .