Skip to content

Commit fc81b18

Browse files
committed
Allow 'parseArgs' and 'numOptArgs' in environments
Close xemlock#13
1 parent 7bbd8a1 commit fc81b18

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

library/PhpLatex/Parser.php

+17-1
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ protected function _createEnviron($name, $mode, $environ = null) // {{{
318318
assert(($mode & ($mode - 1)) === 0); // mode must be a power of 2
319319

320320
$math = false;
321+
$optArgs = array();
321322
$args = array();
322323

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

346+
$parseArgs = isset($spec['parseArgs']) ? $spec['parseArgs'] : true;
347+
348+
$numOptArgs = isset($spec['numOptArgs']) ? intval($spec['numOptArgs']) : 0;
349+
while (count($optArgs) < $numOptArgs) {
350+
if (false !== ($arg = $this->_parseOptArg($mode, $environ, $parseArgs))) {
351+
$optArgs[] = $arg;
352+
} else {
353+
break;
354+
}
355+
}
356+
345357
// parse args, will be placed as environs first children, with
346358
// no spaces between them, btw: \begin{tabular}c is a perfectly
347359
// correct specification for a single-column table.
348360
$nargs = isset($spec['numArgs']) ? intval($spec['numArgs']) : 0;
349361
while (count($args) < $nargs) {
350-
if (false === ($arg = $this->_parseArg($mode, $environ))) {
362+
if (false === ($arg = $this->_parseArg($mode, $environ, $parseArgs))) {
351363
$arg = $this->_createNode(self::TYPE_GROUP, $mode);
352364
}
353365
$arg->setProp('arg', true);
@@ -364,6 +376,10 @@ protected function _createEnviron($name, $mode, $environ = null) // {{{
364376
$node->math = $math;
365377
}
366378

379+
foreach ($optArgs as $arg) {
380+
$node->appendChild($arg);
381+
}
382+
367383
foreach ($args as $arg) {
368384
$node->appendChild($arg);
369385
}

0 commit comments

Comments
 (0)