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?

3
  • 3
    what answer are you looking for other than the answer already in the question? Commented May 5, 2016 at 9:26
  • One answer might be: Did not see one, but here are some of the things I would like to see in such a tool.
    – Yossi Gil
    Commented May 5, 2016 at 13:07
  • 1
    Stated in these terms, the question is “opinion based”.
    – egreg
    Commented May 5, 2016 at 13:23

1 Answer 1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .