Implement basic column info parsing

* For each letter l c or r that is found in the
  column spec the respective mtable alignment
  information is passed
* if the align information is given externally
  the info will still be ignored

Bug: T376838
Change-Id: I3113f933502df2109b066959e4d001736dbae6e6
This commit is contained in:
physikerwelt 2024-10-13 00:54:33 +02:00
parent 9321d6ffc7
commit 602043027d
No known key found for this signature in database
GPG key ID: FCC793EFFA5FB13C
2 changed files with 28 additions and 1 deletions

View file

@ -525,11 +525,28 @@ class BaseParsing {
$mtr = new MMLmtr();
$mtd = new MMLmtd();
$tableArgs = [ "columnspacing" => "1em", "rowspacing" => "4pt", 'rowlines' => '' ];
$columnInfo = trim( $node->getColumnSpecs()->render(), "{} \n\r\t\v\x00" );
if ( $align ) {
$tableArgs['columnalign'] = $align;
} elseif ( $columnInfo ) {
$align = '';
foreach ( str_split( $columnInfo ) as $chr ) {
switch ( $chr ) {
case 'r':
$align .= 'right ';
break;
case 'l':
$align .= 'left ';
break;
case 'c':
$align .= 'center ';
break;
}
}
$tableArgs['columnalign'] = $align;
}
$mencloseArgs = [ 'notation' => '' ];
$columnInfo = $node->getColumnSpecs()->render();
$lineNumber = 0;
foreach ( $node as $row ) {
$resInner .= $mtr->getStart();
@ -576,6 +593,7 @@ class BaseParsing {
// it seems this is creted when left and right is solely coming from columninfo
$tableArgs = array_merge( $tableArgs, [ "columnlines" => "solid" ] );
}
}
$mtable = new MMLmtable( "", $tableArgs );
if ( $cases || ( $open != null && $close != null ) ) {

View file

@ -165,4 +165,13 @@ class BaseParsingTest extends TestCase {
$this->assertStringContainsString( 'top bottom', $result );
}
public function testColumnSpecs() {
$matrix = ( new TexVC() )->parse( '\\begin{array}{lcr}
z & = & a \\\\
f(x,y,z) & = & x + y + z
\\end{array}' )[0];
$result = BaseParsing::matrix( $matrix, [], null, 'matrix', '002A' );
$this->assertStringContainsString( 'left center right ', $result );
}
}