Assuming I want to grep
all packages used in a tex file:
$ grep usepackage my.tex
will do, with (as far as I can see) one exception: If a package gets loaded with that many options that the author of the file decided to insert line breaks, as in
\usepackage[option1,
option2,
option3]{thepackage}
Would there be a way to tell grep to continue parsing the file until it hits the }
?
Ideally I would only get the thepackage
as output, so that I could possibly iterate over it, such as:
$ for i in `locate `my grep command`.sty`
do
grep \\\\newcommand{\\\\createstrouble} $i
done
in order to quickly find a package in which a command \createstrouble
is defined?
EDIT: One further complication: I have a \usepackage
command as follows:
\usepackage[pdftitle={My Title},
pdfauthor={My Author}]{hyperref}
EDIT: I understood that this approach doesn't work for my purpose, which was to find out conflicting packages. Primarily so, because a package loaded by \usepackage{something}
pulls in more packages through RequirePackage
which one will not have on ones radar. Better to work with the logfile, possibly using \listfiles
in ones preamble, producing a list of files loaded, and grepping through ones texmf
directory for the actual command name used by different packages.
You can do multiline matches in regular grep using a combination of the
-P
(PCRE mode) and-z
flags e.g.or with
pcregrep
The
(?s)
modifier allows.
to match newlines.To get just the package name, you could try either
or
Testing the plain grep expression on a TeX manuscript of my own I get the following package list:
It's not simple to write a TeX parser. Therefore the following solution can only be try.
Using
awk
twice anduniq
Example