how to extract LaTeX macro arguments?

Discussion in 'Perl' started by ivo welch, Dec 23, 2003.

  1. ivo welch

    ivo welch Guest

    I know regex can't do this, so may I ask what the recommended
    procedure is for extracting a bracketed TeX argument, which itself can
    contain other bracketed TeX arguments?

    $string = " text \sometexmacro{arg1}{this is a second {\bf arg}
    argument} more text";

    and file.pm has a sub that makes it easy to describe all the arguments
    to sometexmacro


    \sometexmacro
    arg1: 'arg1'
    arg2: 'this is a second {\bf arg} argument'

    if it were even smarter, it could also handle TeX comments and
    escapes, such as

    file.tex: \sometexmacro{arg1}{this is a second %}
    {\bf arg} argument, which handles \} correctly }

    Life would be heaven if regex's could do this, because I could then
    automatically replace the second argument with what I want it to be.
    Alas, they cannot. will they be able to do this in perl6?
    ivo welch, Dec 23, 2003
    #1
    1. Advertising

  2. ivo welch wrote:
    > I know regex can't do this,


    Do you? Please show us the code that made you jump at that incorrect
    conclusion. Preferrably a small program that people can run.

    > so may I ask what the recommended procedure is for extracting a
    > bracketed TeX argument, which itself can contain other bracketed
    > TeX arguments?


    I'd say that a Perl regular expression would be fine.

    <random code fragments snipped>

    > Life would be heaven if regex's could do this,


    Then life _is_ heaven! Isn't that wonderful? :)

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Dec 23, 2003
    #2
    1. Advertising

  3. ivo welch

    ivo welch Guest

    how about an example (if this is possible) then?
    ivo welch, Dec 25, 2003
    #3
  4. ivo welch wrote:
    > how about an example (if this is possible) then?


    Nope. I think people should give it a serious try to solve their
    problems themselves before asking for help in this and similar groups,
    and you have in no way indicated that you have tried yourself. On the
    contrary, considering the way you asked, I'd bet that you are just
    trying to have other people do the job for you.

    You know, this is not a "we write your code for free" service. It's a
    Usenet group for discussing the Perl programming language. Maybe I
    should add: This group is defunct, and replaced by comp.lang.perl.misc.

    If I was wrong above, and if you want to ask for help there, I do
    recommend that you reconsider your posting style.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Dec 25, 2003
    #4
  5. ivo welch

    ivo welch Guest

    Thanks for the hint. I had looked at the perlfaq6,

    Can I use Perl regular expressions to match balanced text?

    Although Perl regular expressions are more powerful than
    "mathematical" regular expressions, because they feature conveniences
    like backreferences (\1 and its ilk), they still aren't powerful
    enough -- with the possible exception of bizarre and experimental
    features in the development-track releases of Perl. You still need to
    use non-regex techniques to parse balanced text, such as the text
    enclosed between matching parentheses or braces, for example.


    and I had tried to play with the feature, but I could not figure it
    out. I think short one-liner examples fall well within the "please
    help" category and not just into the "do the programming for me"
    category.

    regards, /iaw


    Gunnar Hjalmarsson <> wrote in message news:<xuJGb.43658$>...
    > ivo welch wrote:
    > > how about an example (if this is possible) then?

    >
    > Nope. I think people should give it a serious try to solve their
    > problems themselves before asking for help in this and similar groups,
    > and you have in no way indicated that you have tried yourself. On the
    > contrary, considering the way you asked, I'd bet that you are just
    > trying to have other people do the job for you.
    >
    > You know, this is not a "we write your code for free" service. It's a
    > Usenet group for discussing the Perl programming language. Maybe I
    > should add: This group is defunct, and replaced by comp.lang.perl.misc.
    >
    > If I was wrong above, and if you want to ask for help there, I do
    > recommend that you reconsider your posting style.
    ivo welch, Dec 26, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dead RAM
    Replies:
    20
    Views:
    1,087
    John Harrison
    Jul 14, 2004
  2. D Senthil Kumar

    macro name from macro?

    D Senthil Kumar, Sep 20, 2003, in forum: C Programming
    Replies:
    1
    Views:
    559
    Jack Klein
    Sep 21, 2003
  3. sounak

    to get macro name from macro value

    sounak, Nov 22, 2005, in forum: C Programming
    Replies:
    17
    Views:
    483
    Mark McIntyre
    Nov 22, 2005
  4. Patrick Kowalzick
    Replies:
    5
    Views:
    456
    Patrick Kowalzick
    Mar 14, 2006
  5. Mike Manilone

    macro inside macro

    Mike Manilone, Oct 3, 2011, in forum: C Programming
    Replies:
    8
    Views:
    438
    Mike Manilone
    Oct 6, 2011
Loading...

Share This Page