Skip to content

Commit

Permalink
Changes to frontmatter (See Changes)
Browse files Browse the repository at this point in the history
  • Loading branch information
brucemiller committed Aug 4, 2006
1 parent c969003 commit cf00a4d
Show file tree
Hide file tree
Showing 34 changed files with 639 additions and 404 deletions.
11 changes: 11 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
0.5.x 2006-08-03
- Changes to how frontmatter is handled, and represented.
Frontmatter gets accumulated and added to <document>
when it is absorbed, whether or not there's a \maketitle.
<author> => <creator role='author'><personname>...
<affliation> => <contact role='affiliation'>... inside of <creator>
Similarly for <email>
This construct gives more flexibility for representing
editors, translators, reviewers, etc,
And also for various kinds of info about them (address, etc).

0.5.x 2006-07-24
- Fixed a sneaky bug in \def parameters, and gullet->readMatch
where TeX collapses multiple spaces! Thanks Ioan!
Expand Down
4 changes: 4 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ lib/LaTeXML/Token.pm
lib/LaTeXML/Util/Alignment.pm
lib/LaTeXML/Util/Color.pm
lib/LaTeXML/Util/Geometry.pm
lib/LaTeXML/Util/KeyVal.pm
lib/LaTeXML/Util/LibXML.pm
lib/LaTeXML/Util/Pathname.pm
lib/LaTeXML/Util/Transform.pm
Expand Down Expand Up @@ -297,6 +298,9 @@ t/parse/terms.tex
t/parse/terms.xml
t/post/simplemath-post.xml
t/post/simplemath.xml
t/structure/authors.dvi
t/structure/authors.tex
t/structure/authors.xml
t/structure/para.dvi
t/structure/para.tex
t/structure/para.xml
Expand Down
Binary file modified doc/LaTeXML.dvi
Binary file not shown.
150 changes: 89 additions & 61 deletions doc/LaTeXML.xml

Large diffs are not rendered by default.

67 changes: 42 additions & 25 deletions lib/LaTeXML/Package/DLMF.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ DefPrimitive('\thischapter{}', sub {
AssignValue(ChapterLabel=>"ch:$ch",'global');
DocType("ltx:chapter","-//NIST LaTeXML//LaTeXML DLMF Chapter",'DLMF.dtd',
'#default'=>"http://dlmf.nist.gov/LaTeXML");
Tag('ltx:chapter', afterOpen=>\&insertFrontMatter);
});

DefEnvironment('{document}',
Expand Down Expand Up @@ -107,38 +108,54 @@ DefMacro('\theenumiv', '\Alph{enumiv}');

# NOTE: Need to redo author & affiliation to handle multiple authors.
# Need to handle token lists ??
## DefPrimitive('\status{}', sub{ AssignValue(chapter_status=>$_[1]); });
##
## DefMacro('\@authorinfo','');
## # Let \author & \affiliation simply collect the constructors, in order.
## DefMacro('\author{}', '\xdef\@authorinfo{\@authorinfo\fmt@author{#1}}');
## DefMacro('\affiliation{}', '\xdef\@authorinfo{\@authorinfo\fmt@affiliation{#1}}');
##
## DefConstructor('\fmt@affiliation{}',"<ltx:affiliation>#1</ltx:affiliation>");
##
## DefConstructor('\email{}', "<ltx:email>#1</ltx:email>");
## DefConstructor('\addCopyright{}{}','');#"<ltx:copyright year='#1'>#2</ltx:copyright>");
##
## DefMacro('\@acknowledgements','');
## DefPrimitive('\acknowledgements{}', sub { DefMacro('\@acknowledgements',$_[1])});
## DefConstructor('\fmt@acknowledgements{}', "<ltx:acknowledgements>#1</ltx:acknowledgements>");

## Tag('ltx:gallery', autoClose=>1, autoOpen=>1);
## DefMacro('\@galleryitems','');
## DefMacro('\galleryitem Semiverbatim Semiverbatim',
## '\xdef\@galleryitems{\@galleryitems'
## .'\fmt@galleryitem{\ifx.#1.\else sb:\thechapter.#1\fi}{#2}}');

## DefConstructor('\fmt@galleryitem Semiverbatim Semiverbatim',
## "<ltx:galleryitem labelref='#1' graphic='#2'/>");
##
## DefMacro('\maketitle',
## '\fmt@title{\@title}\@authorinfo'
## .'\fmt@date{\@date}'
## .'\fmt@acknowledgements{\@acknowledgements}'
## .'\@galleryitems');


DefPrimitive('\status{}', sub{ AssignValue(chapter_status=>$_[1]); });

DefMacro('\@authorinfo','');
# Let \author & \affiliation simply collect the constructors, in order.
DefMacro('\author{}', '\xdef\@authorinfo{\@authorinfo\fmt@author{#1}}');
DefMacro('\affiliation{}', '\xdef\@authorinfo{\@authorinfo\fmt@affiliation{#1}}');
DefConstructor('\@affiliation{}',"^ <ltx:contact role='affiliation'>#1</ltx:contact>");
DefMacro('\affiliation{}','\@add@to@frontmatter{ltx:creator}{\@affiliation{#1}}');

DefConstructor('\fmt@affiliation{}',"<ltx:affiliation>#1</ltx:affiliation>");
DefConstructor('\@email{}',"^ <ltx:contact role='email'>#1</ltx:contact>");
DefMacro('\email{}', '\@add@to@frontmatter{ltx:creator}{\@email{#1}}');

DefConstructor('\email{}', "<ltx:email>#1</ltx:email>");
DefConstructor('\addCopyright{}{}','');#"<ltx:copyright year='#1'>#2</ltx:copyright>");

DefMacro('\@acknowledgements','');
DefPrimitive('\acknowledgements{}', sub { DefMacro('\@acknowledgements',$_[1])});
DefConstructor('\fmt@acknowledgements{}', "<ltx:acknowledgements>#1</ltx:acknowledgements>");

Tag('ltx:gallery', autoClose=>1, autoOpen=>1);
DefMacro('\@galleryitems','');
DefMacro('\galleryitem Semiverbatim Semiverbatim',
'\xdef\@galleryitems{\@galleryitems'
.'\fmt@galleryitem{\ifx.#1.\else sb:\thechapter.#1\fi}{#2}}');
DefMacro('\acknowledgements{}', '\@add@frontmatter{ltx:acknowledgements}{#1}');

DefConstructor('\fmt@galleryitem Semiverbatim Semiverbatim',
DefConstructor('\@galleryitem Semiverbatim Semiverbatim',
"<ltx:galleryitem labelref='#1' graphic='#2'/>");


DefMacro('\maketitle',
'\fmt@title{\@title}\@authorinfo'
.'\fmt@date{\@date}'
.'\fmt@acknowledgements{\@acknowledgements}'
.'\@galleryitems');

DefMacro('\galleryitem Semiverbatim Semiverbatim',
'\@add@to@frontmatter{ltx:gallery}{\@galleryitem{\ifx.#1.\else sb:\thechapter.#1\fi}{#2}}');
#**********************************************************************
# More environments.
DefEnvironment('{figuregroup}', "<ltx:figuregroup>#body</ltx:figuregroup>");
Expand All @@ -160,7 +177,7 @@ DefConstructor('\onlyelectronic{}',"#1");
DefEnvironment('{sidebar}{}{}{}',
"<ltx:sidebar name='#1' label='#label' id='#id'>"
. "<ltx:title>#2</ltx:title>"
. "<ltx:author>#3</ltx:author>"
. "<ltx:creator role='author'><ltx:personname>#3</ltx:personname></ltx:creator>"
. "#body"
."</ltx:sidebar>",
beforeDigest=> sub {
Expand Down
2 changes: 1 addition & 1 deletion lib/LaTeXML/Package/DLMFmath.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
package LaTeXML::Package::Pool;
use strict;
use LaTeXML::Package;
use LaTeXML::Util::KeyVal;

#**********************************************************************
# Load special functions & other required packages.
RequirePackage('amssymb');
RequirePackage('keyval');

UnshiftValue(SEARCHPATHS=>"$ENV{HOME}/dlmf/styles/DLMFtex/");
RequirePackage('DLMFfcns');
Expand Down
50 changes: 31 additions & 19 deletions lib/LaTeXML/Package/LaTeX.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,15 @@ map(Tag("ltx:$_", autoClose=>1),

DefExpandable('\@startsection{}{}{}{}{}{} OptionalMatch:*', sub {
my($gullet,$type,$level,$ignore3,$ignore4,$ignore5,$ignore6,$flag)=@_;
my $ctr = LookupValue('counter_for_'.ToString($type)) || ToString($type);
if($flag){
refStepID(ToString($type));
refStepID($ctr);
(T_CS('\\@@section'),
T_BEGIN,$type->unlist,T_END,
T_OTHER('['),T_OTHER(']'),
T_OTHER('['),T_CS('\@currentID'),T_OTHER(']')); }
else {
refStepCounter(ToString($type));
refStepCounter($ctr);
(T_CS('\\@@section'),
T_BEGIN,$type->unlist,T_END,
T_OTHER('['),T_CS('\@currentlabel'),T_OTHER(']'),
Expand Down Expand Up @@ -338,28 +339,38 @@ DefRegister('\baselinestretch' => Dimension(0));
# C.5.4 The Title Page and Abstract
#======================================================================

DefMacro('\@title','');
DefMacro('\@author','');
DefMacro('\@date','\today');
DefPrimitive('\title{}', sub { DefMacro('\@title',$_[1])});
DefPrimitive('\author{}', sub { DefMacro('\@author',$_[1])});
DefPrimitive('\date{}', sub { DefMacro('\@date',$_[1])});
DefConstructor('\thanks{}', "<ltx:thanks>#1</ltx:thanks>");
# See frontmatter support in TeX.ltxml
DefMacro('\title{}', '\@add@frontmatter{ltx:title}{#1}');
DefMacro('\date{}', '\@add@frontmatter{ltx:date}[role=creation]{#1}');

DefConstructor('\person@thanks{}', "^ <ltx:contact role='thanks'>#1</ltx:contact>");
DefConstructor('\@personname{}', "<ltx:personname>#1</ltx:personname>",
beforeDigest=>sub { Let('\thanks','\person@thanks'); },
bounded=>1);

# Hmm, this should ideally split authors into multiple author lists?
DefConstructor('\and', " and ");
sub andSplit {
my($cs,$tokens)=@_;
my @items = ();
my @toks=();
foreach my $t ($tokens->unlist){
if($t->equals(T_CS('\and'))){
push(@items,[@toks]); @toks=();}
else {
push(@toks,$t); }}
map( ($cs,T_BEGIN,@$_,T_END), @items,[@toks]); }

DefMacro('\@author{}', '\@add@frontmatter{ltx:creator}[role=author]{\@personname{#1}}');
DefExpandable('\author{}', sub { andSplit(T_CS('\@author'),$_[1]); });

DefPrimitive('\maketitle', undef); # Doesn't matter.

# Introduce secret control sequences to format the title, date, etc.
# These will be used by \maketitle when the time comes.
DefConstructor('\fmt@title{}', "<ltx:title>#1</ltx:title>");
DefConstructor('\fmt@author{}', "<ltx:author>#1</ltx:author>");
# Would be nice to put the ISO date as an attribute!
DefConstructor('\fmt@date{}', "<ltx:creationdate>#1</ltx:creationdate>");
# This needs to be a macro so that \@author, etal, get expanded.
DefMacro('\maketitle', '\fmt@title{\@title}\fmt@author{\@author}\fmt@date{\@date}');
DefConstructor('\thanks{}', "<ltx:note class='thanks'>#1</ltx:note>");

DefEnvironment('{abstract}','<ltx:abstract>#body</ltx:abstract>');
# Presumably you'll do whatever you need to specify author, etc ???
# Hmm, should this even redefine author, title, etc so that they
# are simply output?
DefEnvironment('{titlepage}','#body');

#**********************************************************************
Expand Down Expand Up @@ -1947,7 +1958,8 @@ DefMacro('\@ifnextchar Token {}{}', sub {
DefMacro('\@ifundefined{}{}{}',sub {
my($gullet,$name,$if,$else)=@_;
my $cs = T_CS('\\'.ToString($name));
(LookupMeaning($cs) ne $cs ? $if->unlist : $else->unlist); });
my $meaning = LookupMeaning($cs);
(!(defined $meaning) || ($meaning ne $cs) ? $if->unlist : $else->unlist); });

DefMacro('\IfFileExists{}{}{}', sub{
my($gullet,$file,$if,$else)=@_;
Expand Down
78 changes: 78 additions & 0 deletions lib/LaTeXML/Package/TeX.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use LaTeXML::Package;
use Unicode::Normalize;
use XML::LibXML;
use LaTeXML::Util::Alignment;
use LaTeXML::Util::KeyVal;
no warnings 'redefine';

RegisterNamespace(ltx=>"http://dlmf.nist.gov/LaTeXML");
Expand Down Expand Up @@ -1828,6 +1829,83 @@ DefMacro('\textindent{}','#1');
# Or add attribute to it? Or...
DefPrimitive('\narrower',undef);

#----------------------------------------------------------------------
# General support for Front Matter.
# Not (yet) used by TeX (finish plain?)
# But provides support for LaTeX (and other formats?) for handling frontmatter.
#
# The idea is to accumulate any frontmatter material (title, author,...)
# rather than directly drop it into the digested stream.
# When we begin constructing the document, all accumulated material is output.
# See LaTeX.ltxml for usage.

# Note: could be circumstances where you'd want modular frontmatter?
# (ie. frontmatter for each sectional unit)
AssignValue(frontmatter=>{},'global');

# Add a new frontmatter item that will be enclosed in <$tag %attr>...</$tag>
# The content is the result of digesting $tokens.
# \@add@frontmatter{tag}[attributes]{content}
DefPrimitive('\@add@frontmatter {} OptionalKeyVals {}', sub {
my($stomach,$tag,$keys,$tokens)=@_;
$tag = ToString($tag);
my $attr = ($keys ? {$keys->beDigested($stomach)->getHash} : undef);

my $frontmatter = LookupValue('frontmatter');
my $inpreamble = LookupValue('inPreamble');
AssignValue(inPreamble=>0);
my $datum = Digest($tokens);
AssignValue(inPreamble=>$inpreamble);
push(@{$$frontmatter{$tag}},[$tag,$attr,$datum]);
return; });

# Append a piece of data to an existing frontmatter item that is contained in <$tag>
# If $label is given, look for an item which has label=>$label,
# otherwise, just append to the last item in $tag.

# \@add@to@frontmatter{tag}[label]{content}
DefPrimitive('\@add@to@frontmatter {} [] {}', sub {
my($stomach,$tag,$label,$tokens)=@_;
$tag = ToString($tag);
$label = ToString($label) if $label;
my $frontmatter = LookupValue('frontmatter');

my $inpreamble = LookupValue('inPreamble');
AssignValue(inPreamble=>0);
my $datum = Digest($tokens);
AssignValue(inPreamble=>$inpreamble);

if($label){
my $entry;
foreach my $item (@{$$frontmatter{$tag} || []}){
my($itag,$iattr,@stuff)=@$item;
if($label eq ($$iattr{label}||'')){
push(@$item,$datum);
return; }}}
elsif(my $list = $$frontmatter{$tag}){
push(@{$$list[-1]},$datum);
return;}
push(@{$$frontmatter{$tag}},[$tag,($label ? {label=>$label} : undef),$datum]);
return; });

# This is called by afterOpen (by default on <ltx:document>) to
# output any frontmatter that was accumulated.
sub insertFrontMatter {
my($document)=@_;
my $frontmatter = LookupValue('frontmatter');
foreach my $key ('ltx:title','ltx:toctitle','ltx:creator','ltx:date',
grep($_ !~/^(ltx:title|ltx:toctitle|ltx:creator|ltx:date)$/,
keys %$frontmatter)){
if(my $list = $$frontmatter{$key}){
foreach my $item (@$list){
my($tag,$attr,@stuff)=@$item;
$document->openElement($tag,($attr ? %$attr : ()));
map($document->absorb($_), @stuff);
$document->closeElement($tag); }}}
return; }

Tag('ltx:document', afterOpen=>\&insertFrontMatter);

DefConstructor('\beginsection{}',
"<ltx:section><ltx:title>#1</ltx:title>");
# \proclaim ?
Expand Down
1 change: 0 additions & 1 deletion lib/LaTeXML/Package/amsmath.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package LaTeXML::Package::Pool;
use strict;
use LaTeXML::Package;
use encoding 'utf8';

# TODO:
# Interesting options for limits placement
Expand Down
2 changes: 1 addition & 1 deletion lib/LaTeXML/Package/amsrefs.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
package LaTeXML::Package::Pool;
use strict;
use LaTeXML::Package;
use LaTeXML::Util::KeyVal;

RequirePackage('keyval');
#**********************************************************************
# \bib{key}{type}{keyval pairs}

Expand Down
14 changes: 7 additions & 7 deletions lib/LaTeXML/Package/article.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,29 @@ NewCounter('enumi');
NewCounter('enumii');
NewCounter('enumiii');
NewCounter('enumiv');
NewCounter('enumv'); # A couple of more levels, since we use these for ID's!
NewCounter('enumvi');
# Since we don't want enumi (necessarily) to be reset when @itemize is incremented,
# we've got to manually define the ID macros:
DefMacro('\theenumi@ID', '\the@itemize@ID.\@enumi@ID');
DefMacro('\theenumii@ID', '\the@itemize@ID.\@enumii@ID');
DefMacro('\theenumiii@ID', '\the@itemize@ID.\@enumiii@ID');
DefMacro('\theenumiv@ID', '\the@itemize@ID.\@enumiv@ID');
DefMacro('\theenumv@ID', '\the@itemize@ID.\@enumv@ID');
DefMacro('\theenumvi@ID', '\the@itemize@ID.\@enumvi@ID');

DefMacro('\theenumi', '\arabic{enumi}');
DefMacro('\theenumii', '\alph{enumii}');
DefMacro('\theenumiii', '\roman{enumiii}');
DefMacro('\theenumiv', '\Alph{enumiv}');

Tag('ltx:appendix',autoClose=>1);
# Actually we should be using section counter
AssignValue(counter_for_appendix=>'section');
DefPrimitive('\appendix',sub{
NewCounter('section', 'document', idprefix=>'A',nested=>['subsection']);
Let('\\@@section'=>'\\@@appendix');
DefMacro('\section', '\@startsection{appendix}{}{}{}{}{}');
});
DefConstructor('\\@@appendix[][][]{}',
"<ltx:appendix ?#1(refnum='#1') id='#2'>"
. "<ltx:title>#4</ltx:title>"
. "?#3(<ltx:toctitle>#3</ltx:toctitle>)",
bounded=>1);


#**********************************************************************
1;
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/LaTeXML/Package/graphicx.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package LaTeXML::Package::Pool;
use strict;
use LaTeXML::Package;
use LaTeXML::Util::KeyVal;
#**********************************************************************
# Package options: draft, final, hiderotate, hidescale, hiresbb.
# NOTE: More things to implement (?)
Expand All @@ -22,7 +23,6 @@ use LaTeXML::Package;
# \reflectbox{text}
# \resizebox{hlength}{vlength}{text}

RequirePackage('keyval');

# Unimplemented, for now: What should be the result?
# Would seem to require different treatment if the content was ONLY \includegraphic,
Expand Down
Loading

0 comments on commit cf00a4d

Please sign in to comment.