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.

Caramdir
  • 89,023
  • 26
  • 255
  • 291
user4852
  • 653
  • 5
    All I see in the above code is \7 V??#? ?j`. Please be more specific which characters you need. – Martin Scharrer May 15 '11 at 11:14
  • This question, How do I look up a (math) symbol? might be relevant. It's not necessarily math-specific. – Matthew Leingang May 15 '11 at 11:17
  • 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. – Matthew Leingang May 15 '11 at 11:21
  • @Martin scharrer whatever the symbol may be.. i want to display as it is... Is there any feature in latex for that? – user4852 May 15 '11 at 11:23
  • previously i used Verbatim buts it fails to display the mentioned line. – user4852 May 15 '11 at 11:25
  • @user4852: So, do you want to display binary content from a file? How people are going to read it? – Andrey Vihrov May 15 '11 at 11:26
  • @Matthew Leingang hey sorry.. i am new to this site. dont know the things.. thanks. – user4852 May 15 '11 at 11:26
  • @Andrey Vihrov yes.. – user4852 May 15 '11 at 11:27
  • @Andrey Vihrov i dont want to people to read it. i just wanna display it as it is. thats it. – user4852 May 15 '11 at 11:28
  • 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 '11 at 11:31
  • 1
    @user4852: This is a very traditional netiquette custom (not specific to this community), see http://www.catb.org/~esr/faqs/smart-questions.html#urgent And it's good advice in general. :-) – Matthew Leingang May 15 '11 at 11:44
  • 1
    @user4852: If these are indeed binary characters then there are no printable symbols for them, so you can't display them "as they are". Often they are displayed as e.g. <e8> (where e8 is the hexadecimal number of the byte). You would need to this conversion by yourself. – Martin Scharrer May 15 '11 at 11:49
  • @Martin Scharrer♦ @Matthew Leingangok. thank u – user4852 May 15 '11 at 14: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 '11 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. – Martin Scharrer May 15 '11 at 21:21

2 Answers2

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.

Andrey Vihrov
  • 22,325
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.

Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283