Parsing a latex file in Perl -
apologies basic question!
i want read in latex file (so text basically) , output (say) theorems, in format
\begin{theorem} lines of latex \end{theorem}
i kind of figured perl right language this!
of course, know basic programming in c++ , java, , virtually no perl.
nonetheless can read in text file, , process line line.
it seems basic way is:
($string =~ /pattern/)
i started getting confused reading control codes ?,*+,$, etc.
any simple references or links me started?
(i put on here , not tex site, useful reading text files, , not latex!)
if you're on unix-y machine (this includes macs), task small should reach sed
first:
$ sed -ne '/^\\begin{theorem}$/,/^\\end{theorem}$/p' doc.tex
if you're on windows, though, don't sed
bundled os, , perl rather easier install aiui, here's equivalent:
> perl -ne 'print if /^\\begin\{theorem\}$/.../^\\end\{theorem\}$/;' doc.tex
you may notice distinct resemblance between these 2 commands. that's not accident; perl took ideas many of older unix text-munging utilities, sed
included.
Comments
Post a Comment