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

trim whitespace in loading LaTeX classes and packages #2430

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
27 changes: 13 additions & 14 deletions lib/LaTeXML/Engine/LaTeX.pool.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ DefConstructor('\documentclass OptionalSemiverbatim SkipSpaces Semiverbatim []',
beforeDigest => sub { onlyPreamble('\documentclass'); },
afterDigest => sub {
my ($stomach, $whatsit) = @_;
my $options = $whatsit->getArg(1);
my $options = [TrimmedCommaList($whatsit->getArg(1))];
my $class = ToString($whatsit->getArg(2));
$class =~ s/\s+//g;
LoadClass($class,
options => [($options ? split(/\s*,\s*/, ToString($options)) : ())],
options => $options,
after => Tokens(T_CS('\AtBeginDocument'), T_CS('\warn@unusedclassoptions')));
return; });

Expand All @@ -78,10 +78,9 @@ DefConstructor('\documentstyle OptionalSemiverbatim SkipSpaces Semiverbatim []',
onlyPreamble('\documentstyle'); },
afterDigest => sub {
my ($stomach, $whatsit) = @_;
my $class = ToString($whatsit->getArg(2));
my $options = [TrimmedCommaList($whatsit->getArg(1))];
my $class = ToString($whatsit->getArg(2));
$class =~ s/\s+//g;
my $options = $whatsit->getArg(1);
$options = [($options ? split(/\s*,\s*/, ToString($options)) : ())];
# Watch out; In principle, compatibility mode wants a .sty, not a .cls!!!
# But, we'd prefer .cls, since we'll have better bindings.
# And in fact, nobody's likely to write a binding for a .sty that wants to be a class anyway.
Expand Down Expand Up @@ -872,9 +871,8 @@ DefConstructor('\usepackage OptionalSemiverbatim Semiverbatim []',
"<?latexml package='#2' ?#1(options='#1')?>",
beforeDigest => sub { onlyPreamble('\usepackage'); },
afterDigest => sub { my ($stomach, $whatsit) = @_;
my $options = $whatsit->getArg(1);
my $options = [TrimmedCommaList($whatsit->getArg(1))];
my $packages = $whatsit->getArg(2);
$options = [($options ? split(/\s*,\s*/, (ToString($options))) : ())];
for my $pkg (split(',', ToString($packages))) {
$pkg =~ s/\s+//g;
next if !$pkg || $pkg =~ /^%/;
Expand All @@ -885,9 +883,8 @@ DefConstructor('\RequirePackage OptionalSemiverbatim Semiverbatim []',
"<?latexml package='#2' ?#1(options='#1')?>",
beforeDigest => sub { onlyPreamble('\RequirePackage'); },
afterDigest => sub { my ($stomach, $whatsit) = @_;
my $options = $whatsit->getArg(1);
my $options = [TrimmedCommaList($whatsit->getArg(1))];
my $packages = $whatsit->getArg(2);
$options = [($options ? split(/\s*,\s*/, (ToString($options))) : ())];
for my $pkg (split(',', ToString($packages))) {
$pkg =~ s/\s+//g;
next if !$pkg || $pkg =~ /^%/;
Expand All @@ -898,10 +895,9 @@ DefConstructor('\LoadClass OptionalSemiverbatim Semiverbatim []',
"<?latexml class='#2' ?#1(options='#1')?>",
beforeDigest => sub { onlyPreamble('\LoadClass'); },
afterDigest => sub { my ($stomach, $whatsit) = @_;
my $options = $whatsit->getArg(1);
my $options = [TrimmedCommaList($whatsit->getArg(1))];
my $class = ToString($whatsit->getArg(2));
$class =~ s/\s+//g;
$options = [($options ? split(/\s*,\s*/, (ToString($options))) : ())];
LoadClass($class, options => $options);
return; });

Expand Down Expand Up @@ -952,13 +948,15 @@ DefPrimitive('\PassOptionsToPackage{}{}', sub {
my ($stomach, $options, $name) = @_;
$name = ToString($name);
$name =~ s/\s+//g;
PassOptions($name, 'sty', split(/\s*,\s*/, ToString(Expand($options)))); });
$options = [TrimmedCommaList(Expand($options))];
PassOptions($name, 'sty', $options); });

DefPrimitive('\PassOptionsToClass{}{}', sub {
my ($stomach, $options, $name) = @_;
$name = ToString($name);
$name =~ s/\s+//g;
PassOptions($name, 'cls', split(/\s*,\s*/, ToString(Expand($options)))); });
$options = [TrimmedCommaList(Expand($options))];
PassOptions($name, 'cls', $options); });

DefConstructor('\RequirePackageWithOptions Semiverbatim []',
"<?latexml package='#1'?>",
Expand Down Expand Up @@ -1001,7 +999,8 @@ DefPrimitiveI('\@unknownoptionerror', undef, sub {

DefPrimitive('\ExecuteOptions{}', sub {
my ($gullet, $options) = @_;
ExecuteOptions(split(/\s*,\s*/, ToString(Expand($options)))); });
my @options = TrimmedCommaList(Expand($options));
ExecuteOptions(@options) if @options; });

DefPrimitive('\ProcessOptions OptionalMatch:*', sub {
my ($stomach, $star) = @_;
Expand Down
9 changes: 8 additions & 1 deletion lib/LaTeXML/Package.pm
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ our @EXPORT = (qw(&DefAutoload &DefExpandable

# Random low-level token or string operations.
qw(&CleanID &CleanLabel &CleanIndexKey &CleanClassName &CleanBibKey &NormalizeBibKey &CleanURL
&ComposeURL
&ComposeURL &TrimmedCommaList
&roman &Roman),
# Math & font state.
qw(&MergeFont),
Expand Down Expand Up @@ -555,6 +555,13 @@ sub ComposeURL {
$url,
($fragid ? '#' . CleanID($fragid) : ''))); }

sub TrimmedCommaList {
my ($text) = @_;
$text = ToString($text);
$text =~ s/^\s+//;
$text =~ s/\s+$//;
return split(/\s*,\s*/, $text); }

#======================================================================
# Defining new Control-sequence Parameter types.
#======================================================================
Expand Down
Loading