1

I was looking for something like:

 filecontents *.sty | cat - main.tex > newmain.tex

It should be easy to write a script that iterating over its arguments, would wrap each in a filecontents environment. I wonder if there is a standard such tool.

Here is a simple script that will do the job:

#!/bin/sh -f
for f in $* ;  do
  echo \\\\begin{filecontents}{$f} 
  cat $f 
  echo \\\\end{filecontents}
done

If there are no such standard tool, what would you like to see in one?

Clément
  • 5,591
Yossi Gil
  • 15,951

1 Answers1

2

Here is a slightly improved script:

#!/bin/bash -f
function bundle {
  echo "\\begin{filecontents*}{$1} % Begin: '$1' $2"
  cat $1 
  echo "\\end{filecontents*}       % End: '$1' $2"
}

me=`basename "$0"`
case $# in 
  0) 
    echo "Usage: $me file(s)" 
    ;;
  1) 
    bundle $1
    ;;
  *) 
    i=1
    echo "% BEGIN: bundle $# files ($*) `date`"
    for f in $*;  do
      bundle $f "\#$i/$#: `date`"
      [ $i -ge $# ] || echo 
      let i=$i+1
    done
    echo "% END: bundle $# files ($*) `date`"
    ;;
esac

Improvements include:

  • Generating more detailed LaTeX comments, including date, file count, etc.
  • Use filecontents* environment

Should anyone be interested in variations, let me know. Perhaps one day I will make this into a more standardized tool.Even if not, it would be nice to serve what people really need.

Yossi Gil
  • 15,951