Skip to content

Commit

Permalink
one way to do embellished atoms and bases
Browse files Browse the repository at this point in the history
  • Loading branch information
dginev committed Jul 11, 2020
1 parent dea8329 commit e8be86d
Showing 1 changed file with 43 additions and 15 deletions.
58 changes: 43 additions & 15 deletions lib/LaTeXML/Package/a11ymark.sty.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,45 @@ use strict;
use warnings;
use LaTeXML::Package;

## 0. Semantic infrastructure
DefConstructor('\meaning{}{}', '#2', afterConstruct => sub {
my ($doc, $whatsit) = @_;
my $apply = $doc->getNode->lastChild;
if ($apply->localName eq 'XMApp') { # should be an apply, if by design
$apply->setAttribute('meaning', ToString($whatsit->getArg(1))); } },
bounded => 1, requireMath => 1);

# Embellishment is hard to write, hard to speak, but describes exactly several cases
# I will abbreviate it "emb", for now, and use it as a prefix
DefConstructor('\emb@atom{}{}',
'<ltx:XMDual>'
. '<ltx:XMTok meaning="#1" />'
. '<ltx:XMWrap>#2</ltx:XMWrap>'
. '</ltx:XMDual>',
bounded => 1, requireMath => 1);

DefMacro('\emb@base{}{}{}', sub {
my ($gullet, $meaning, $base, $emb) = @_;
# Package::dualize_arglist seems to be doing this with more sophistication,
# a good bit to read if we ever need to build more infra here.
# for now, fast and loose, these don't get saved and are only for local association
my $id_token = T_OTHER("id" . int(rand(10000)));
my $ref_token = Invocation(T_CS('\@XMRef'), $id_token);
my $arg_token = Invocation(T_CS('\@XMArg'), $id_token, $base);
return Invocation(T_CS('\emb@base@build'), $meaning, $ref_token, Tokens($arg_token, $emb))->unlist;
});

DefConstructor('\emb@base@build{}{}{}',
'<ltx:XMDual>'
. '<ltx:XMApp>'
. '<ltx:XMTok meaning="#1"/>'
. '#2'
. '</ltx:XMApp>'
. '<ltx:XMWrap>#3</ltx:XMWrap>'
. '</ltx:XMDual>',
bounded => 1, requireMath => 1);

## I. Calculus
DefConstructor('\diffd', '<ltx:XMTok meaning="differential" name="diffd" role="DIFFOP">d</ltx:XMTok>');
DefMath('\deriv[]{}{}',
'\frac{\@MAYBEAPPLY{\@SUPERSCRIPT{\diffd}{#1}}{#2}}'
Expand All @@ -28,21 +67,10 @@ DefMath('\deriv[]{}{}',

DefMath('\integral{}{}', '\int #1 \diffd #2', meaning => 'integral');

DefConstructor('\meaning{}{}', '#2', afterConstruct => sub {
my ($doc, $whatsit) = @_;
my $apply = $doc->getNode->lastChild;
if ($apply->localName eq 'XMApp') { # should be an apply, if by design
$apply->setAttribute('meaning', ToString($whatsit->getArg(1))); } },
bounded => 1, requireMath => 1);

DefMacro('\power{}{}', '\meaning{power}{#1^{#2}}');

# These still need work, since currently we get
# annotations "transpose(#1,#2)" and "frobulator(#1,#2)"
# instead of the desired "transpose(#1)" and "frobulator"
# I guess this needs a different type of XMath structural pattern...
DefMacro('\transpose{}', '\meaning{transpose}{#1^T}');
DefMacro('\frobulator', '\meaning{frobulator}{x\'}');
## II. Scripts
DefMacro('\power{}{}', '\meaning{power}{#1^{#2}}');
DefMacro('\frobulator', '\emb@atom{frobulator}{x\'}');
DefMacro('\transpose{}', '\emb@base{transpose}{#1}{^T}');

########
1;

0 comments on commit e8be86d

Please sign in to comment.