On 05/27/2007 12:30 AM, Russell L. Harris wrote:
On 2007-05-26, Russell L. Harris <[EMAIL PROTECTED]> wrote:
I need to extract footnotes from a very long LaTeX document.  I would
like to start with a copy of the document, then delete from the copy
all text which is not a footnote.
[...]

Next, I decided to try to write a Perl script, and that's the point at
which I presently find myself.

The Text::Balanced module is perfect for this. Here's how I might do it using that module:

    use strict;
    use warnings;
    use Text::Balanced qw(extract_bracketed);
    use Data::Dumper;

    my $text = q(
      Some text.
    \footnote{My \bold{nice} footnote is here.}
      More text is here.
    \footnote{Second footnote \italic{\bold{i}tem}.}
      Final text.
    );
    $text =~ s/^ {4}//mg; # probably superfluous

    # Start working on the text.

    my @footnotes;
    my $extracted;
    while ($text =~ s/.*?(\\footnote)//s) {
        ($extracted, $text) = extract_bracketed($text, '{}');
        push @footnotes, $1 . $extracted;
    }

    print Dumper([EMAIL PROTECTED]);

I know my Latex probably sucks because it's been years since I've had to do it, but I hope this helps.


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to