|
| 1 | +From d715def1f4ddd18336e5e49b54baf0efd9acfb94 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Deyan Ginev < [email protected]> |
| 3 | +Date: Sun, 21 Jul 2019 16:14:17 -0400 |
| 4 | +Subject: [PATCH] neurips binding and reliably preload main article |
| 5 | + dependencies for bibliography post-processing |
| 6 | + |
| 7 | +--- |
| 8 | + MANIFEST | 1 + |
| 9 | + lib/LaTeXML/Package/neurips.sty.ltxml | 34 +++++++++++++++++++++++++++ |
| 10 | + lib/LaTeXML/Post.pm | 22 +++++++++-------- |
| 11 | + lib/LaTeXML/Post/MakeBibliography.pm | 11 +++++---- |
| 12 | + 4 files changed, 53 insertions(+), 15 deletions(-) |
| 13 | + create mode 100644 lib/LaTeXML/Package/neurips.sty.ltxml |
| 14 | + |
| 15 | +diff --git a/MANIFEST b/MANIFEST |
| 16 | +index f944d07aa..69b5bdd51 100644 |
| 17 | +--- a/MANIFEST |
| 18 | ++++ b/MANIFEST |
| 19 | +@@ -548,6 +548,7 @@ lib/LaTeXML/Package/multido.sty.ltxml |
| 20 | + lib/LaTeXML/Package/multirow.sty.ltxml |
| 21 | + lib/LaTeXML/Package/nameref.sty.ltxml |
| 22 | + lib/LaTeXML/Package/natbib.sty.ltxml |
| 23 | ++lib/LaTeXML/Package/neurips.sty.ltxml |
| 24 | + lib/LaTeXML/Package/newcent.sty.ltxml |
| 25 | + lib/LaTeXML/Package/newfloat.sty.ltxml |
| 26 | + lib/LaTeXML/Package/newlfont.sty.ltxml |
| 27 | +diff --git a/lib/LaTeXML/Package/neurips.sty.ltxml b/lib/LaTeXML/Package/neurips.sty.ltxml |
| 28 | +new file mode 100644 |
| 29 | +index 000000000..b642e4dd3 |
| 30 | +--- /dev/null |
| 31 | ++++ b/lib/LaTeXML/Package/neurips.sty.ltxml |
| 32 | +@@ -0,0 +1,34 @@ |
| 33 | ++# -*- mode: Perl -*- |
| 34 | ++# /=====================================================================\ # |
| 35 | ++# | neurips_2019.sty | # |
| 36 | ++# | Implementation for LaTeXML | # |
| 37 | ++# |=====================================================================| # |
| 38 | ++# | Part of LaTeXML: | # |
| 39 | ++# | Public domain software, produced as part of work done by the | # |
| 40 | ++# | United States Government & not subject to copyright in the US. | # |
| 41 | ++# |---------------------------------------------------------------------| # |
| 42 | ++# | Bruce Miller <[email protected]> #_# | # |
| 43 | ++# | http://dlmf.nist.gov/LaTeXML/ (o o) | # |
| 44 | ++# \=========================================================ooo==U==ooo=/ # |
| 45 | ++package LaTeXML::Package::Pool; |
| 46 | ++use strict; |
| 47 | ++use warnings; |
| 48 | ++use LaTeXML::Package; |
| 49 | ++ |
| 50 | ++#====================================================================== |
| 51 | ++RequirePackage('natbib'); |
| 52 | ++RequirePackage('geometry'); |
| 53 | ++RequirePackage('lineno'); |
| 54 | ++# /--------------------------------------------------------------------\ |
| 55 | ++# | Drafted by texscan --stub neurips_2019.sty | |
| 56 | ++# \--------------------------------------------------------------------/ |
| 57 | ++DefMacro('\AND', Tokens()); |
| 58 | ++DefMacro('\And', Tokens()); |
| 59 | ++DefMacro('\bottomfraction', Tokens()); |
| 60 | ++DefMacro('\patchAmsMathEnvironmentForLineno', Tokens()); |
| 61 | ++DefMacro('\patchBothAmsMathEnvironmentsForLineno', Tokens()); |
| 62 | ++DefMacroI('\subsubsubsection', undef, '\@startsection{subsubsubsection}{4}{}{}{}{}', locked => 1); |
| 63 | ++DefMacro('\textfraction', Tokens()); |
| 64 | ++DefMacro('\topfraction', Tokens()); |
| 65 | ++#====================================================================== |
| 66 | ++1; |
| 67 | +diff --git a/lib/LaTeXML/Post.pm b/lib/LaTeXML/Post.pm |
| 68 | +index a1dc74c1c..ec12bf2a8 100644 |
| 69 | +--- a/lib/LaTeXML/Post.pm |
| 70 | ++++ b/lib/LaTeXML/Post.pm |
| 71 | +@@ -56,7 +56,7 @@ sub ProcessChain_internal { |
| 72 | + foreach my $doc (@docs) { |
| 73 | + local $LaTeXML::Post::DOCUMENT = $doc; |
| 74 | + if (my @nodes = grep { $_ } $processor->toProcess($doc)) { # If there are nodes to process |
| 75 | +- my $n = scalar(@nodes); |
| 76 | ++ my $n = scalar(@nodes); |
| 77 | + my $msg = join(' ', $processor->getName || '', |
| 78 | + $doc->siteRelativeDestination || '', |
| 79 | + ($n > 1 ? "$n to process" : 'processing')); |
| 80 | +@@ -198,7 +198,7 @@ sub generateResourcePathname { |
| 81 | + my $subdir = $$self{resource_directory} || ''; |
| 82 | + my $prefix = $$self{resource_prefix} || "x"; |
| 83 | + my $counter = join('_', "_max", $subdir, $prefix, "counter_"); |
| 84 | +- my $n = $doc->cacheLookup($counter) || 0; |
| 85 | ++ my $n = $doc->cacheLookup($counter) || 0; |
| 86 | + my $name = $prefix . ++$n; |
| 87 | + $doc->cacheStore($counter, $n); |
| 88 | + return pathname_make(dir => $subdir, name => $name, type => $type); } |
| 89 | +@@ -218,11 +218,12 @@ sub find_documentclass_and_packages { |
| 90 | + $classoptions = $$entry{options} || 'onecolumn'; |
| 91 | + $oldstyle = $$entry{oldstyle}; } |
| 92 | + elsif ($$entry{package}) { |
| 93 | +- push(@packages, [$$entry{package}, $$entry{options} || '']); } |
| 94 | +- } |
| 95 | ++ push(@packages, [$$entry{package} . ".sty", $$entry{options} || '']); } } |
| 96 | + if (!$class) { |
| 97 | + Warn('expected', 'class', undef, "No document class found; using article"); |
| 98 | + $class = 'article'; } |
| 99 | ++ if ($class !~ /\.cls$/) { |
| 100 | ++ $class = $class . ".cls"; } |
| 101 | + return ([$class, $classoptions, $oldstyle], @packages); } |
| 102 | + |
| 103 | + #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 104 | +@@ -336,7 +337,7 @@ sub processNode { |
| 105 | + # XMath will be removed (LATER!), but mark its ids as reusable. |
| 106 | + $doc->preremoveNodes($xmath); |
| 107 | + if ($$self{parallel}) { |
| 108 | +- my $primary = $self->convertNode($doc, $xmath); |
| 109 | ++ my $primary = $self->convertNode($doc, $xmath); |
| 110 | + my @secondaries = (); |
| 111 | + foreach my $proc (@{ $$self{secondary_processors} }) { |
| 112 | + local $LaTeXML::Post::MATHPROCESSOR = $proc; |
| 113 | +@@ -425,7 +426,7 @@ sub convertXMTextContent { |
| 114 | + my $tag = $doc->getQName($node); |
| 115 | + if ($tag eq 'ltx:XMath') { |
| 116 | + my $conversion = $self->convertNode($doc, $node); |
| 117 | +- my $xml = $$conversion{xml}; |
| 118 | ++ my $xml = $$conversion{xml}; |
| 119 | + # And if no xml ???? |
| 120 | + push(@result, $self->outerWrapper($doc, $node, $xml)); } |
| 121 | + else { |
| 122 | +@@ -516,7 +517,7 @@ sub associateNode { |
| 123 | + $document->generateNodeID($sourcenode, '', 1); } # but the ID is reusable |
| 124 | + if (my $sourceid = $sourcenode->getAttribute('fragid')) { # If source has ID |
| 125 | + my $nodeid = $currentnode->getAttribute('fragid') || $sourceid; |
| 126 | +- my $id = $document->uniquifyID($nodeid, $self->IDSuffix); |
| 127 | ++ my $id = $document->uniquifyID($nodeid, $self->IDSuffix); |
| 128 | + if ($isarray) { |
| 129 | + $$node[1]{'xml:id'} = $id; } |
| 130 | + else { |
| 131 | +@@ -775,7 +776,7 @@ sub setDocument_internal { |
| 132 | + my ($tag, $attributes, @children) = @$root; |
| 133 | + my ($prefix, $localname) = $tag =~ /^(.*):(.*)$/; |
| 134 | + my $nsuri = $$self{namespaces}{$prefix}; |
| 135 | +- my $node = $$self{document}->createElementNS($nsuri, $localname); |
| 136 | ++ my $node = $$self{document}->createElementNS($nsuri, $localname); |
| 137 | + $$self{document}->setDocumentElement($node); |
| 138 | + map { $$attributes{$_} && $node->setAttribute($_ => $$attributes{$_}) } keys %$attributes |
| 139 | + if $attributes; |
| 140 | +@@ -927,7 +928,7 @@ sub idcheck { |
| 141 | + my %missing = (); |
| 142 | + foreach my $node ($self->findnodes("//*[\@xml:id]")) { |
| 143 | + my $id = $node->getAttribute('xml:id'); |
| 144 | +- $dups{$id} = 1 if $idcache{$id}; |
| 145 | ++ $dups{$id} = 1 if $idcache{$id}; |
| 146 | + $idcache{$id} = 1; } |
| 147 | + foreach my $id (keys %{ $$self{idcache} }) { |
| 148 | + $missing{$id} = 1 unless $idcache{$id}; } |
| 149 | +@@ -1181,13 +1182,14 @@ sub prependNodes { |
| 150 | + sub cloneNode { |
| 151 | + my ($self, $node, $idsuffix, %options) = @_; |
| 152 | + return $node unless ref $node; |
| 153 | ++ return $node if ref $node eq 'ARRAY'; # Should we deep clone if we get an array? Just return for now |
| 154 | + my $copy = $node->cloneNode(1); |
| 155 | + my $nocache = $options{nocache}; |
| 156 | + #### $idsuffix = '' unless defined $idsuffix; |
| 157 | + # Find all id's defined in the copy and change the id. |
| 158 | + my %idmap = (); |
| 159 | + foreach my $n ($self->findnodes('descendant-or-self::*[@xml:id]', $copy)) { |
| 160 | +- my $id = $n->getAttribute('xml:id'); |
| 161 | ++ my $id = $n->getAttribute('xml:id'); |
| 162 | + my $newid = $self->uniquifyID($id, $idsuffix); |
| 163 | + $idmap{$id} = $newid; |
| 164 | + $self->recordID($newid => $n) unless $nocache; |
| 165 | +diff --git a/lib/LaTeXML/Post/MakeBibliography.pm b/lib/LaTeXML/Post/MakeBibliography.pm |
| 166 | +index 37c70b92e..6bf6d96fc 100644 |
| 167 | +--- a/lib/LaTeXML/Post/MakeBibliography.pm |
| 168 | ++++ b/lib/LaTeXML/Post/MakeBibliography.pm |
| 169 | +@@ -162,13 +162,14 @@ sub convertBibliography { |
| 170 | + my ($self, $doc, $bib) = @_; |
| 171 | + require LaTeXML; |
| 172 | + require LaTeXML::Common::Config; |
| 173 | +- my @packages = |
| 174 | +- my @preload = (); |
| 175 | +- # Might want/need to preload more (all?) packages, but at least do inputenc! |
| 176 | ++ my @preload = (); # custom macros often used in e.g. howpublished field |
| 177 | ++ # need to preload all packages used by the main article |
| 178 | + foreach my $po ($self->find_documentclass_and_packages($doc)) { |
| 179 | + my ($pkg, $options) = @$po; |
| 180 | +- if ($pkg eq 'inputenc') { |
| 181 | +- push(@preload, "[$options]$pkg"); } } |
| 182 | ++ if ($options) { |
| 183 | ++ push(@preload, "[$options]$pkg"); } |
| 184 | ++ else { |
| 185 | ++ push(@preload, "$pkg"); } } |
| 186 | + NoteProgress(" [Converting bibliography $bib ..."); |
| 187 | + my $bib_config = LaTeXML::Common::Config->new( |
| 188 | + cache_key => 'BibTeX', |
0 commit comments