Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow 'parseArgs' and 'numOptArgs' in environments #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading