#!/bin/sh # # texpsinclude, see http://www.ma.utexas.edu/mp_arc/index-90.html ## ## Usage: texpsinclude > ## ## is the original .tex file (TeX, LATeX, AMSTeX, etc.) ## is a list of .ps files like: fig1.ps bar.ps fig2.ps ## will be the .tex file produced by texpsinclude ## ## To get more information, type: texpsinclude info ## or to see the TeX macros used: texpsinclude macros ## ########################################################################### #: Here's the problem that texpsinclude solves: #: #: You have a TeX file called foo.tex that you want to distribute as a #: single TeX file. The problem is that foo.tex needs two Postscript #: files, bar1.ps and bar2.ps, for embedded figures. You'd like a single #: TeX file which somehow includes bar1.ps and bar2.ps. When TeX #: processes foo.tex, TeX should extract bar1.ps and bar2.ps from #: foo.tex. #: #: Here's how to do what you want to do: #: #: texpsinclude foo.tex. bar1.ps bar2.ps > bigfoo.tex #: #: (In general: "texpsinclude > ".) #: If you enter this command, the result is a new file called bigfoo.tex. #: The file bigfoo.tex contains foo.tex, bar1.ps, and bar2.ps. #: If you give bigfoo.tex to a friend, she can make your document with: #: #: tex bigfoo.tex #: #: This command writes out bar1.ps and bar2.ps, and the command also #: TeX's foo.tex. #: #: Note: If *you* run tex on bigfoo.tex in the same directory, #: then TeX will write over your .ps files. #: Be careful when testing your bigfoo.tex. #: #: --Jamie Stephens, 16 Nov 94 #: #: #: Note': The need not necessarily contain PostScript code. #: texpsinclude can be used to include other types of ASCII files #: into a .tex file, such as source code for a computer program, etc. #: ########################################################################### #% % TeX macros for dumping included Postscript to files. #% % Adapted from Knuth's \answer macro in the TeXbook. #% % Jamie Stephens, jamies@math.utexas.edu, 28 Nov 94 #% #% \def\endofps{EndOfTheIncludedPostscriptMagicCookie} #% \chardef\other=12 #% \newwrite\psdumphandle #% \outer\def\psdump#1{\par\medbreak #% \immediate\openout\psdumphandle=#1 #% \copytoblankline} #% \def\copytoblankline{\begingroup\setupcopy\copypsline} #% \def\setupcopy{\def\do##1{\catcode`##1=\other}\dospecials #% \catcode`\\=\other \obeylines} #% {\obeylines \gdef\copypsline#1 #% {\def\next{#1}% #% \ifx\next\endofps\let\next=\endgroup % #% \else\immediate\write\psdumphandle{\next} \let\next=\copypsline\fi\next}} #% \outer\def\closepsdump{ #% \immediate\closeout\psdumphandle} #% #%%% EXAMPLE (remove the leading % signs to make it work): #%%% #%%%\psdump{example.ps}These three lines #%%%are going be dumped "as is" #%%%to the file example.ps #%%%EndOfTheIncludedPostscriptMagicCookie #%%%\closepsdump ########################################################################### if [ $# -eq 0 ]; then sed -n 's/^## //p' $0 >&2 exit 1 elif [ "$1" = "info" ]; then sed -n 's/^#: //p' $0 >&2 exit 0 elif [ "$1" = "macros" ]; then sed -n 's/^#%.//p' $0 >&2 exit 0 else for F in $@; do if [ ! -r "$F" ]; then echo "Could not find (or read) $F" >&2 exit 1 fi done fi TEXFILE="$1" shift cat <&2 echo "% Here is the PostScript for $FILE:" echo "\message{Writing file $FILE}" echo -n "\psdump{$FILE}" cat "$FILE" echo "EndOfTheIncludedPostscriptMagicCookie" echo echo "\closepsdump" echo done echo "Including $TEXFILE" >&2 if [ -n "$CUT" ]; then echo "% Finally, here is the rest of $TEXFILE:" echo -n "% " tail +$CUT "$TEXFILE" else echo "% Finally, here is $TEXFILE:" cat "$TEXFILE" fi