[texhax] [IC/Admin] Putting image *data* inside a TeX/LaTeX file?

Tom Schneider toms at ncifcrf.gov
Tue Apr 7 21:54:21 CEST 2009


Jorge:

> >         Normally I would provide the user with two files, the
> >         "report.sty" and
> >         a "logo.eps" file. However, life would be simpler for users if
> >         they
> >         had only one file to download.
> >         
> >         So, is there a way to include the image pixel data (or the
> >         contents of
> >         the "logo.eps" file) in the "report.sty" file itself? Say,
> >         within a
> >         largish "\special" command?

Normally I would just make a directory and zip that up.  But there is
an interesting feature of LaTeX described on page 77 of Lamport's
book.  Before the \documentclass command you can put these things:

\begin{filecontents}{name.tex}
contents of file
\end{filecontents}

The file name.tex gets written out!

I tried it:

\begin{filecontents}{name.tex}
contents of file
\end{filecontents}
\documentclass[12pt]{article}
\begin{document}
Test of filecontents 
\input{name.tex}
\end{document}

LaTeX says:

LaTeX Warning: Writing file `./name.tex'.

8-O it worked!! 8^D

This is the file written:

%% LaTeX2e file `name.tex'
%% generated by the `filecontents' environment
%% from source `paper' on 2009/04/07.
%%
contents of file

This really appeared in the LaTeX output!

The second time it says:

LaTeX Warning: File `name.tex' already exists on the system.
               Not generating it from this source.

I was then able to create an eps from the LaTeX source and read it in.
to create a graphic.  Unfortunately the file created has to be in the
current directory, if I write to /tmp/filename it tries to put it in
./tmp/filename.

So there is a residue left wherever one runs the LaTeX.

I've attached the example.  I have not tried to put it in a style
file.

Tom

  Dr. Thomas D. Schneider
  National Institutes of Health
  National Cancer Institute
  Center for Cancer Research Nanobiology Program
  Molecular Information Theory Group
  Frederick, Maryland  21702-1201
  toms at ncifcrf.gov
  permanent email: toms at alum.mit.edu
  http://www.ccrnp.ncifcrf.gov/~toms/
-------------- next part --------------
\begin{filecontents}{tree.eps}
%!PS-Adobe-2.0 EPSF-2.0
%%Title: Fractal Arrow
%%Creator: Tom Schneider
%%BoundingBox:  60 290 540 670
%%DocumentFonts:
%%EndComments
%%EndProlog

% from the Blue Book, page 74
% variables and procedures
/depth 0 def
/maxdepth 12 def
/down {/depth depth 1 add def} def
/up {/depth depth 1 sub def} def

/DoLine % print a vertical line
{0 144 rlineto currentpoint
 stroke translate 0 0 moveto} def

/FractArrow
{gsave .6 .6 scale   % reduce scale
 20 setlinewidth     % set line width
 down DoLine         % print line
 depth maxdepth le   % depth < max depth?
  {  60 rotate FractArrow
   -120 rotate FractArrow} if
up grestore } def

300 300 moveto
2 2 scale
FractArrow
stroke

%%Trailer
%%Pages: 1
\end{filecontents}
\documentclass[12pt]{article}
\usepackage{graphics}
\usepackage{color}
\begin{document}
2009 Apr 07

Test of creating and reading tree.eps graphic.
See LaTeX, A Document Preparation System, by
Leslie Lamport, page 77.
\begin{center}
{\scalebox{0.50}{\includegraphics*{tree.eps}}}
\end{center}

\begin{verbatim}
  Dr. Thomas D. Schneider
  National Institutes of Health
  National Cancer Institute
  Center for Cancer Research Nanobiology Program
  Molecular Information Theory Group
  Frederick, Maryland  21702-1201
  schneidt at mail.nih.gov
  permanent email: toms at alum.mit.edu
  http://www.ccrnp.ncifcrf.gov/~toms/
\end{verbatim}

\end{document}


More information about the texhax mailing list