TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a package to render binary files as hex in LaTeX. We've searched for it, but couldn't find any.

The package should provide some kind of command:


With file.ext a "binary" file (in this case the header of a .png file, but the content is here of course irrelevant).

Resulting in something like:

| 89 50 4E 47 0D 0A 1A 0A 00 00 00 0D 49 48 44 52 |
| 00 00 00 10 00 00 00 10 08 06 00 00 00 1F F3 FF |
share|improve this question
You should elaborate... – Jubobs Aug 24 '14 at 3:30
Updated with an example. Better? – Willem Van Onsem Aug 24 '14 at 3:42
Which OS are you using as I feel this is a job that is better suited outside of TeX and then the hex content can be rendered. – Peter Grill Aug 24 '14 at 4:19
Linux (Ubuntu 14.04) – Willem Van Onsem Aug 24 '14 at 5:44
up vote 16 down vote accepted

Here is a version that works in MacOs (and should work on most Unix machines):

enter image description here


  • You can replace the hexdump with different shell command. This method will show the output of that.
  • This requires the -shell-escape option to allow for executing shell commands.



    % #1 = temp file name       
    % #2 = input file name 
    \immediate\write18{hexdump -C #2 > ./#1}%


The image
in hex looks like:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.