Is there any way to grep a pdf document (originally written in LaTeX) for the math "2^n" as in 2 to the power of n? I have pdfgrep but I don't know how you would use that to grep for math.
You can use e.g.
mutool clean -d from the
mupdf package to decompress the streams in a PDF file, then you can look at it (or
grep it directly).
Unfortunately, text in PDF files is rendered by placing glyphs (or sequences of glyphs) at pre-calculated coordinates. So both
$$2^n$$ will consist of two glyphs for
n in different positions, and this is really difficult to match with a regular expression.
I suggest you decompress your pdf document and have a look at how the text rendering actually looks like.