Skip to content

Commit

Permalink
Allow 'parseArgs' and 'numOptArgs' in environments
Browse files Browse the repository at this point in the history
Close #13
  • Loading branch information
larsgw committed Dec 7, 2024
1 parent 7bbd8a1 commit fc81b18
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion library/PhpLatex/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ protected function _createEnviron($name, $mode, $environ = null) // {{{
assert(($mode & ($mode - 1)) === 0); // mode must be a power of 2

$math = false;
$optArgs = array();
$args = array();

if (isset($this->_environs[$name])) {
Expand All @@ -342,12 +343,23 @@ protected function _createEnviron($name, $mode, $environ = null) // {{{
// or displaymath), if so, prepare math node instead of environ node
$math = isset($spec['math']) && $spec['math'];

$parseArgs = isset($spec['parseArgs']) ? $spec['parseArgs'] : true;

$numOptArgs = isset($spec['numOptArgs']) ? intval($spec['numOptArgs']) : 0;
while (count($optArgs) < $numOptArgs) {
if (false !== ($arg = $this->_parseOptArg($mode, $environ, $parseArgs))) {
$optArgs[] = $arg;
} else {
break;
}
}

// parse args, will be placed as environs first children, with
// no spaces between them, btw: \begin{tabular}c is a perfectly
// correct specification for a single-column table.
$nargs = isset($spec['numArgs']) ? intval($spec['numArgs']) : 0;
while (count($args) < $nargs) {
if (false === ($arg = $this->_parseArg($mode, $environ))) {
if (false === ($arg = $this->_parseArg($mode, $environ, $parseArgs))) {
$arg = $this->_createNode(self::TYPE_GROUP, $mode);
}
$arg->setProp('arg', true);
Expand All @@ -364,6 +376,10 @@ protected function _createEnviron($name, $mode, $environ = null) // {{{
$node->math = $math;
}

foreach ($optArgs as $arg) {
$node->appendChild($arg);
}

foreach ($args as $arg) {
$node->appendChild($arg);
}
Expand Down

0 comments on commit fc81b18

Please sign in to comment.