summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/luamml/luamml-demo.sty
blob: 9aabb38719d9052ae42e5daa91f7de142ef6b1ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
\NeedsTeXFormat{LaTeX2e}
\ProvidesExplPackage{luamml-demo}{2024-10-30}{0.2.0}{Reasonable default definitions for luamml}

\sys_if_engine_luatex:F {
  \msg_new:nnn {luamml-demo} {pdftex-option-ignored} {Option~`#1'~is~being~ignored~in~pdfTeX~mode.}
  \DeclareOption*{\msg_warning:nnx {luamml-demo} {pdftex-option-ignored} {\CurrentOption}}
  \ProcessOptions\relax
  \RequirePackage{luamml-pdf-demo}
  \endinput
}

\RequirePackage{luamml}% Loading luamml is pretty much the point
\RequirePackage{amsmath,array}% These are more or less expected in luamml especially for advanced constructs

\AtBeginDocument{%
  \@ifpackageloaded{unicode-math}{}{%
    \RegisterFamilyMapping\symsymbols{oms}%
    \RegisterFamilyMapping\symletters{oml}%
    \RegisterFamilyMapping\symlargesymbols{omx}%
  }
}

\bool_new:N \l__luamml_demo_structelem_bool

\DeclareOption{tracing}{
  \tracingmathml=2
}
\DeclareOption{structelem}{
  \bool_set_true:N \l__luamml_demo_structelem_bool
  \luamml_structelem:
}
\DeclareOption{files}{
  \int_new:N \g__luamml_demo_mathml_int
  \luamml_set_filename:n {
    \immediateassignment \int_gincr:N \g__luamml_demo_mathml_int
    \jobname -formula- \int_use:N \g__luamml_demo_mathml_int .xml
  }
}
\DeclareOption{l3build}{
  \luamml_set_filename:n {
    \jobname .mml
  }
  \luamml_begin_single_file:
}
\ProcessOptions\relax

\cs_new_eq:NN \LuaMMLSetFilename \luamml_set_filename:n

\cs_generate_variant:Nn \pdffile_filespec:nnn {ene}
\int_new:N \g__luamml_demo_af_int
\cs_new_protected:Npn \LuaMMLTagAF #1#2 {
  \tag_mc_end_push:
  \int_gincr:N \g__luamml_demo_af_int
  \exp_args:Ne \pdf_object_new:nn{__luamml_demo_\int_use:N \g__luamml_demo_af_int}{dict}
  \exp_args:Ne \tag_struct_begin:n{tag=Formula,AF=__luamml_demo_\int_use:N \g__luamml_demo_af_int,#1}
  \bool_if:NF \l__luamml_demo_structelem_bool {
    \tag_mc_begin:n{tag=Formula}
  }
  #2
  \group_begin:
    \pdfdict_put:nnn {l_pdffile/Filespec} {AFRelationship}{/Supplement}
    \pdffile_filespec:ene
      { __luamml_demo_ \int_use:N \g__luamml_demo_af_int }
      { test.xml }
      { \luamml_get_last_mathml_stream:e{}\c_space_tl 0~R}
  \group_end:
  \bool_if:NF \l__luamml_demo_structelem_bool {
    \tag_mc_end:
  }
  \tag_struct_end:
  \tag_mc_begin_pop:n{}
}

\NewDocumentCommand\AnnotateFormula{ o m m }{%
  \IfValueTF{#1}{%
    \luamml_annotate:nen{#1}%
  }{
    \luamml_annotate:en
  }{#2}{#3}
}

\cs_set_eq:NN \WriteoutFormula \luamml_pdf_write: