Skip to content

Commit

Permalink
Fixup \centering, \raggedright,... so they only start centering after…
Browse files Browse the repository at this point in the history
… the current node
  • Loading branch information
brucemiller committed Dec 21, 2023
1 parent 2735791 commit 6cac9de
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions lib/LaTeXML/Package/LaTeX.pool.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -1364,42 +1364,41 @@ DefEnvironment('{flushright}', sub {

# These add an operation to be carried out on the current node & following siblings, when the current group ends.
# These operators will add alignment (class) attributes to each "line" in the current block.
#DefPrimitiveI('\centering', undef, sub { UnshiftValue(beforeAfterGroup=>T_CS('\@add@centering')); });
# NOTE: THere's a problem here. The current method seems to work right for these operators
# appearing within the typical environments. HOWEVER, it doesn't work for a simple \bgroup or \begingroup!!!
# (they don't create a node! or even a whatsit!)
DefConstructorI('\centering', undef,
sub { AssignValue(ALIGNING_NODE => $_[0]->getElement); return; },
sub setupAligningContext {
my ($document) = @_;
my $node = $document->getElement;
AssignValue(ALIGNING_NODE => [$node, $node->lastChild]);
return; }

sub applyAligningContext {
my ($document, $align, $class) = @_;
if (my $container = LookupValue('ALIGNING_NODE')) {
my ($node, $previous) = @$container;
my @children = $node->childNodes($node);
while (my $skip = shift(@children)) {
last if !$previous || $previous->isSameNode($skip); }
while (my $child = shift(@children)) {
setAlignOrClass($document, $child, $align, $class); } }
return; }

DefConstructorI('\centering', undef, \&setupAligningContext,
beforeDigest => sub { UnshiftValue(beforeAfterGroup => T_CS('\@add@centering')); });
DefConstructorI('\raggedright', undef,
sub { AssignValue(ALIGNING_NODE => $_[0]->getElement); return; },
DefConstructorI('\raggedright', undef, \&setupAligningContext,
beforeDigest => sub { UnshiftValue(beforeAfterGroup => T_CS('\@add@raggedright')); });
DefConstructorI('\raggedleft', undef,
sub { AssignValue(ALIGNING_NODE => $_[0]->getElement); return; },
DefConstructorI('\raggedleft', undef, \&setupAligningContext,
beforeDigest => sub { UnshiftValue(beforeAfterGroup => T_CS('\@add@raggedleft')); });

DefConstructorI('\@add@centering', undef,
sub { if (my $node = LookupValue('ALIGNING_NODE')) {
map { setAlignOrClass($_[0], $_, 'center', 'ltx_centering') }
$_[0]->getChildElements($node); } });
sub { applyAligningContext($_[0], 'center', 'ltx_centering'); });
# Note that \raggedright is essentially align left
DefConstructorI('\@add@raggedright', undef,
sub { if (my $node = LookupValue('ALIGNING_NODE')) {
map { setAlignOrClass($_[0], $_, undef, 'ltx_align_left') }
$_[0]->getChildElements($node); } });
sub { applyAligningContext($_[0], undef, 'ltx_align_left'); });
DefConstructorI('\@add@raggedleft', undef,
sub { if (my $node = LookupValue('ALIGNING_NODE')) {
map { setAlignOrClass($_[0], $_, undef, 'ltx_align_right') }
$_[0]->getChildElements($node); } });

sub { applyAligningContext($_[0], undef, 'ltx_align_right'); });
DefConstructorI('\@add@flushright', undef,
sub { if (my $node = LookupValue('ALIGNING_NODE')) {
map { setAlignOrClass($_[0], $_, 'right', 'ltx_align_right') }
$_[0]->getChildElements($node); } });
sub { applyAligningContext($_[0], 'right', 'ltx_align_right'); });
DefConstructorI('\@add@flushleft', undef,
sub { if (my $node = LookupValue('ALIGNING_NODE')) {
map { setAlignOrClass($_[0], $_, 'left', 'ltx_align_left') }
$_[0]->getChildElements($node); } });
sub { applyAligningContext($_[0], 'left', 'ltx_align_left'); });

#======================================================================-
# C.6.1 Quotations and Verse
Expand Down

0 comments on commit 6cac9de

Please sign in to comment.