Skip to content

How to parse optional arguments of environments #13

@larsgw

Description

@larsgw

Description

How can I parse optional arguments of environments in PhpLatex? The following LaTeX:

\begin{tabular}[t]{c}
  table content
\end{tabular}

Gets parsed as follows:

object(App\Utility\Latex\Parser\Node) id:0 {
  protected _type => 'environ'
  protected _props => [
    'mode' => (int) 1,
    'value' => 'tabular',
  ]
  protected _children => [
    (int) 0 => object(PhpLatex_Node) id:1 {
      protected _type => 'group'
      protected _props => [
        'mode' => (int) 1,
        'arg' => true,
      ]
      protected _children => [
        (int) 0 => object(PhpLatex_Node) id:2 {
          protected _type => 'text'
          protected _props => [
            'mode' => (int) 1,
            'value' => '[',
          ]
          protected _children => [ ]
        },
      ]
    },
    (int) 1 => object(PhpLatex_Node) id:3 {
      protected _type => 'text'
      protected _props => [
        'mode' => (int) 1,
        'value' => 't]',
      ]
      protected _children => [ ]
    },
    (int) 2 => object(PhpLatex_Node) id:4 {
      protected _type => 'group'
      protected _props => [
        'mode' => (int) 1,
      ]
      protected _children => [
        (int) 0 => object(PhpLatex_Node) id:5 {
          protected _type => 'text'
          protected _props => [
            'mode' => (int) 1,
            'value' => 'c',
          ]
          protected _children => [ ]
        },
      ]
    },
    (int) 3 => object(PhpLatex_Node) id:6 {
      protected _type => 'text'
      protected _props => [
        'mode' => (int) 1,
        'value' => ' table content ',
      ]
      protected _children => [ ]
    },
  ]
}

Possible Solution

Would I need to do the following?

  1. Get the first child
  2. Check the 'arg' => true prop
  3. See it has a child of type text with value '['
  4. Check the following children until one contains a text node containing the character ']'
  5. Check following child nodes for whether they are also arguments

Is it not possible to parse these args in Parser::_parseArg?

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions