Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

\lsthex{file.ext}

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 at 3:30
1  
Updated with an example. Better? –  CommuSoft Aug 24 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 at 4:19
    
Linux (Ubuntu 14.04) –  CommuSoft Aug 24 at 5:44

1 Answer 1

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

Notes:

  • 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.

Code:

\documentclass{article}
\usepackage{graphicx}
\usepackage{listings}

\newcommand{\ShowHexOutput}[2][\jobname.hex]{%
    % #1 = temp file name       
    % #2 = input file name 
    %
    \immediate\write18{hexdump -C #2 > ./#1}%
    \lstinputlisting{./#1}%
}%

\lstset{basicstyle=\tiny\ttfamily}


\begin{document}
The image
\includegraphics[width=0.5\linewidth]{../images/EiffelWide.jpg} 
in hex looks like:

\ShowHexOutput{../images/EiffelWide.jpg}
\end{document}
share|improve this answer

Your Answer

 
discard

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.