I currently have a set of default LaTeX packages I use frequently formatted as follows:
package1
[options]package2
[options]package3
package4
...
I would like to be able to convert this to standard LaTeX notation of \usepackage[options]{package} or \usepackage{package} depending on whether the package has additional options. I have successfully created a sed/regex command to convert the lines with options, but it misses the packages without options.
echo "[option]package" | sed 's/.*\(\[[^]]*\]\)\(.*\)/\\usepackage\1{\2}/'
>> \usepackage[option]{package}
When this is run on a line with just a package, it fails (as I would expect).
echo "package" | sed 's/.*\(\[[^]]*\]\)\(.*\)/\\usepackage\1{\2}/'
>> package
Is this a regex problem and if so, how should I approach it?