diff --git a/lib/LaTeXML/Common/XML.pm b/lib/LaTeXML/Common/XML.pm index 9af6f3ea9..bc46c6af3 100644 --- a/lib/LaTeXML/Common/XML.pm +++ b/lib/LaTeXML/Common/XML.pm @@ -75,7 +75,7 @@ our @EXPORT = ( decodeFromUTF8 ), @XML::LibXML::EXPORT, # Possibly (later) export these utility functions - qw(&element_nodes &text_in_node &new_node &element_next &element_prev + qw(&element_nodes &content_nodes &text_in_node &new_node &element_next &element_prev &append_nodes &clear_node &maybe_clone &valid_attributes ©_attributes &rename_attribute &remove_attr &get_attr &isTextNode &isElementNode &isChild &isDescendant &isDescendantOrSelf @@ -89,10 +89,18 @@ our $XML_NS = 'http://www.w3.org/XML/1998/namespace'; # [CONSTANT] #====================================================================== # XML Utilities + +# Return all child elements of $node sub element_nodes { my ($node) = @_; return ($node ? grep { $_->nodeType == XML_ELEMENT_NODE } $node->childNodes : ()); } +# return all content (element and text) nodes of $node +sub content_nodes { + my ($node) = @_; + return ($node ? grep { my $t = $_->nodeType; $t == XML_ELEMENT_NODE || $t == XML_TEXT_NODE } + $node->childNodes : ()); } + sub text_in_node { my ($node) = @_; return ($node ? join("\n", map { $_->data } grep { $_->nodeType == XML_TEXT_NODE } $node->childNodes) : ''); } diff --git a/lib/LaTeXML/Engine/LaTeX.pool.ltxml b/lib/LaTeXML/Engine/LaTeX.pool.ltxml index ee10feccf..f153a8696 100644 --- a/lib/LaTeXML/Engine/LaTeX.pool.ltxml +++ b/lib/LaTeXML/Engine/LaTeX.pool.ltxml @@ -1383,8 +1383,9 @@ sub applyAligningContext { if (my $container = LookupValue('ALIGNING_NODE')) { my ($node, $previous) = @$container; my @children = $node->childNodes; - while (my $skip = shift(@children)) { - last if !$previous || $previous->isSameNode($skip); } + if ($previous) { + while (my $skip = shift(@children)) { + last if $previous->isSameNode($skip); } } while (my $child = shift(@children)) { setAlignOrClass($document, $child, $align, $class) if $child->nodeType == XML_ELEMENT_NODE; } } return; } diff --git a/lib/LaTeXML/Engine/TeX_Box.pool.ltxml b/lib/LaTeXML/Engine/TeX_Box.pool.ltxml index 579719e57..c275e992f 100644 --- a/lib/LaTeXML/Engine/TeX_Box.pool.ltxml +++ b/lib/LaTeXML/Engine/TeX_Box.pool.ltxml @@ -368,7 +368,7 @@ sub insertBlock { my $inline = $is_svg || $document->canContain($context_tag, '#PCDATA'); my $container = $document->openElement('ltx:_CaptureBlock_', '_vertical_mode_' => 1, %blockattr); $document->absorb($contents); - my @nodes = $container->childNodes; + my @nodes = content_nodes($container); my @node_tags = map { $document->getNodeQName($_); } @nodes; my $nnodes = scalar(@nodes); $document->closeToNode($container, 1); diff --git a/t/alignment/colortbls.xml b/t/alignment/colortbls.xml index f193f2371..d0a8740d8 100644 --- a/t/alignment/colortbls.xml +++ b/t/alignment/colortbls.xml @@ -95,10 +95,10 @@ p{3cm}}"?> -

P-column

+

P-column

-

and another one

+

and another one

@@ -117,10 +117,10 @@ p{3cm}}"?>
-

Some long text in the first column

+

Some long text in the first column

-

bbb

+

bbb

@@ -130,10 +130,10 @@ p{3cm}}"?>
-

aaa

+

aaa

-

and some long text in the second column

+

and some long text in the second column

@@ -152,10 +152,10 @@ p{3cm}}"?>
-

aaa

+

aaa

-

bbb

+

bbb

@@ -165,11 +165,11 @@ p{3cm}}"?>
-

Note that the coloured rules in all columns stretch to accomodate +

Note that the coloured rules in all columns stretch to accomodate large entries in one column.

-

bbb

+

bbb

@@ -179,10 +179,10 @@ large entries in one column.

-

aaa

+

aaa

-

bbb

+

bbb

@@ -192,10 +192,10 @@ large entries in one column.

-

aaa

+

aaa

-

Depending on your driver you may get unsightly gaps or lines +

Depending on your driver you may get unsightly gaps or lines where the ‘screens’ used to produce different shapes interact badly. You may want to cause adjacent panels of the same colour by specifying a larger overhang @@ -209,10 +209,10 @@ or by adding some negative space (in a ”“noalign” between rows.

-

aaa

+

aaa

-

bbb

+

bbb

diff --git a/t/complex/figure_dual_caption.xml b/t/complex/figure_dual_caption.xml index bed735d2d..61b006977 100644 --- a/t/complex/figure_dual_caption.xml +++ b/t/complex/figure_dual_caption.xml @@ -12,12 +12,12 @@ Figure 2
- + 1Left figure. Figure 1Left figure.
- + 2Right figure. Figure 2Right figure.
@@ -29,7 +29,7 @@ Table 2
- +
a @@ -47,7 +47,7 @@ Table 1Left table.
- +
1 diff --git a/t/complex/figure_mixed_content.xml b/t/complex/figure_mixed_content.xml index e07d9cc1d..c218e82f6 100644 --- a/t/complex/figure_mixed_content.xml +++ b/t/complex/figure_mixed_content.xml @@ -101,7 +101,7 @@
- + Algorithm 1 1 diff --git a/t/structure/figure_grids.xml b/t/structure/figure_grids.xml index 1dad3702a..fc2956877 100644 --- a/t/structure/figure_grids.xml +++ b/t/structure/figure_grids.xml @@ -8,20 +8,20 @@
- +
- +
- + @@ -30,7 +30,7 @@
- + @@ -45,7 +45,7 @@
- + @@ -68,7 +68,7 @@
- + @@ -81,7 +81,7 @@
- + @@ -96,7 +96,7 @@
- + @@ -129,7 +129,7 @@
- + @@ -174,7 +174,7 @@
-
+
(a) 1(a) @@ -196,7 +196,7 @@
-
+
(a) 2(a) @@ -219,7 +219,7 @@
-
+
(a) 3(a) @@ -260,7 +260,7 @@
-
+
(a) 4(a) @@ -347,7 +347,7 @@
-
+
(a) 5(a) @@ -498,7 +498,7 @@
-
+
(a) 6(a) @@ -575,7 +575,7 @@
-
+
(a) 7(a) @@ -654,7 +654,7 @@
-
+
(a) 8(a) @@ -887,7 +887,7 @@
-
+
(a) 9(a) @@ -1220,387 +1220,387 @@
- - + + - +
- - + + - +
- - + + - + - + - +
- - + + - + - + - + - + - + - + - + - +
- - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +
- - + + - + - + - + - + - + - + - +
- - + + - + - + - + - + - + - + - +
- - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +
- - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +