Matching \if (possibly nested) and \fi from tex file 
Author Message
 Matching \if (possibly nested) and \fi from tex file

Hi, I'm trying to remove the lines in a tex file contained between

\ifx\....

\fi

The problem is that there might be nested \ifx (or \if) declarations
inside the first \ifx declaration (thus I can't use the method to
remove C comments)

I'm able to match (and delete) the lines if the nesting is like

\if  
\if ... \fi  
\fi

But not if the nesting is like

\if  
\if ... \fi  
\if ... \fi
\fi

Unfortunately I don't see how answer 4.23 of the FAQ might apply to
my case: deleting everything inside matching \if \fi statements.

If you can enlighten me, it would be greatly appreciated.

Thanks

Phil

--
________________________________________________



Sun, 14 Sep 1997 03:23:58 GMT  
 Matching \if (possibly nested) and \fi from tex file

I was able to answer my own question. I guess I should have waited before
posting it ;)

In case someone needs it (it works under perl 5.0000000). The problem
was to match possibly nesting pairs of \if  and \fi  and delete everything
inside the matching pair. I guess it could be adjusted to do other things too.
I wander if this should be added to the FAQ...

sub do_cmd_if {

    local($n) = 1 ;
    while($n>=1) {          
        if($line =~ s/.*?(\\if|\\fi)//s) { # s switch is used to match multi-line
            if($1 eq "\\fi") {      
                $n-- ;
            }
            else {
                $n++ ;
            }    
        }
    }
    $line ;

Quote:
}

--
________________________________________________



Sun, 14 Sep 1997 04:25:24 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. ANNOUNCE: Font::TFM, TeX::DVI, TeX::Hyphen, all 0.03

2. perl (tex)info files

3. Converting formatted text files to TeX

4. Matching block of nested brace pairs

5. FAQ: How do I find matching/nesting anything?

6. FAQ: How do I find matching/nesting anything?

7. FAQ: How do I find matching/nesting anything?

8. FAQ: How do I find matching/nesting anything?

9. FAQ: How do I find matching/nesting anything?

10. FAQ: How do I find matching/nesting anything?

11. regex to match nested paranthesis

12. Nested RegEx Matches

 

 
Powered by phpBB® Forum Software