Add labels to saved formulas
This commit is contained in:
parent
e6077a2702
commit
e21116b501
@ -42,7 +42,7 @@
|
|||||||
\m@th
|
\m@th
|
||||||
\displaystyle
|
\displaystyle
|
||||||
{##}
|
{##}
|
||||||
\luamml_flag_save:Nn \displaystyle {mtd}
|
\luamml_flag_save:nNn {} \displaystyle {mtd}
|
||||||
$
|
$
|
||||||
\__luamml_amsmath_add_last_to_row:
|
\__luamml_amsmath_add_last_to_row:
|
||||||
\tabskip \z@skip
|
\tabskip \z@skip
|
||||||
@ -54,7 +54,7 @@
|
|||||||
{}
|
{}
|
||||||
##
|
##
|
||||||
}
|
}
|
||||||
\luamml_flag_save:Nn \displaystyle {mtd}
|
\luamml_flag_save:nNn {} \displaystyle {mtd}
|
||||||
$
|
$
|
||||||
\__luamml_amsmath_add_last_to_row:
|
\__luamml_amsmath_add_last_to_row:
|
||||||
\hfil
|
\hfil
|
||||||
@ -85,7 +85,7 @@
|
|||||||
\m@th
|
\m@th
|
||||||
\displaystyle
|
\displaystyle
|
||||||
##
|
##
|
||||||
\luamml_flag_save:Nn \displaystyle {mtd}
|
\luamml_flag_save:nNn {} \displaystyle {mtd}
|
||||||
$
|
$
|
||||||
\__luamml_amsmath_add_last_to_row:
|
\__luamml_amsmath_add_last_to_row:
|
||||||
\hfil
|
\hfil
|
||||||
@ -122,7 +122,7 @@
|
|||||||
\m@th
|
\m@th
|
||||||
\displaystyle
|
\displaystyle
|
||||||
{##}
|
{##}
|
||||||
\luamml_flag_save:Nn \displaystyle {mtd}
|
\luamml_flag_save:nNn {} \displaystyle {mtd}
|
||||||
$
|
$
|
||||||
}
|
}
|
||||||
\__luamml_amsmath_add_box_to_row:
|
\__luamml_amsmath_add_box_to_row:
|
||||||
@ -180,7 +180,7 @@
|
|||||||
\ifmeasuring@
|
\ifmeasuring@
|
||||||
\luamml_flag_ignore:
|
\luamml_flag_ignore:
|
||||||
\else
|
\else
|
||||||
\luamml_flag_save:Nn \displaystyle {mtd}
|
\luamml_flag_save:nNn {} \displaystyle {mtd}
|
||||||
\fi
|
\fi
|
||||||
$
|
$
|
||||||
}
|
}
|
||||||
@ -204,7 +204,7 @@
|
|||||||
\ifmeasuring@
|
\ifmeasuring@
|
||||||
\luamml_flag_ignore:
|
\luamml_flag_ignore:
|
||||||
\else
|
\else
|
||||||
\luamml_flag_save:Nn \displaystyle {mtd}
|
\luamml_flag_save:nNn {} \displaystyle {mtd}
|
||||||
\fi
|
\fi
|
||||||
$
|
$
|
||||||
}
|
}
|
||||||
@ -298,14 +298,14 @@
|
|||||||
% Less luckily, \endmultline@math sometimes get overwritten for the last line.
|
% Less luckily, \endmultline@math sometimes get overwritten for the last line.
|
||||||
% But that isn't a problem since we want special behavior there anyway.
|
% But that isn't a problem since we want special behavior there anyway.
|
||||||
\cs_set:Npn \endmultline@math {
|
\cs_set:Npn \endmultline@math {
|
||||||
\luamml_flag_save:Nn \displaystyle {mtd}
|
\luamml_flag_save:nNn {} \displaystyle {mtd}
|
||||||
$
|
$
|
||||||
\__luamml_amsmath_add_last_to_row:
|
\__luamml_amsmath_add_last_to_row:
|
||||||
}
|
}
|
||||||
|
|
||||||
\cs_set:Npn \rendmultline@ {
|
\cs_set:Npn \rendmultline@ {
|
||||||
\iftag@
|
\iftag@
|
||||||
\luamml_flag_save:Nn \displaystyle {mtd}
|
\luamml_flag_save:nNn {} \displaystyle {mtd}
|
||||||
$
|
$
|
||||||
\__luamml_amsmath_add_last_to_row:
|
\__luamml_amsmath_add_last_to_row:
|
||||||
\let \endmultline@math \relax
|
\let \endmultline@math \relax
|
||||||
@ -370,7 +370,7 @@
|
|||||||
\m@th
|
\m@th
|
||||||
\scriptstyle
|
\scriptstyle
|
||||||
##
|
##
|
||||||
\luamml_flag_save:n {mtd} % No \scriptsize here since we want to add the mstyle nodes
|
\luamml_flag_save:nn {} {mtd} % No \scriptsize here since we want to add the mstyle nodes
|
||||||
$
|
$
|
||||||
\__luamml_amsmath_add_last_to_row:
|
\__luamml_amsmath_add_last_to_row:
|
||||||
\hfil
|
\hfil
|
||||||
@ -381,7 +381,7 @@
|
|||||||
\m@th
|
\m@th
|
||||||
\scriptstyle
|
\scriptstyle
|
||||||
##
|
##
|
||||||
\luamml_flag_save:n {mtd} % No \scriptsize here since we want to add the mstyle nodes
|
\luamml_flag_save:nn {} {mtd} % No \scriptsize here since we want to add the mstyle nodes
|
||||||
$
|
$
|
||||||
\__luamml_amsmath_add_last_to_row:
|
\__luamml_amsmath_add_last_to_row:
|
||||||
\hfil
|
\hfil
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
} {
|
} {
|
||||||
\__luamml_array_init_col:
|
\__luamml_array_init_col:
|
||||||
\insert@column
|
\insert@column
|
||||||
\luamml_flag_save:n {mtd}
|
\luamml_flag_save:nn {} {mtd}
|
||||||
\d@llarend
|
\d@llarend
|
||||||
\__luamml_array_finalize_col:w 0~
|
\__luamml_array_finalize_col:w 0~
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@
|
|||||||
} {
|
} {
|
||||||
\__luamml_array_init_col:
|
\__luamml_array_init_col:
|
||||||
\insert@column
|
\insert@column
|
||||||
\luamml_flag_save:n {mtd}
|
\luamml_flag_save:nn {} {mtd}
|
||||||
\d@llarend
|
\d@llarend
|
||||||
\__luamml_array_finalize_col:w 1~
|
\__luamml_array_finalize_col:w 1~
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@
|
|||||||
} {
|
} {
|
||||||
\__luamml_array_init_col:
|
\__luamml_array_init_col:
|
||||||
\insert@column
|
\insert@column
|
||||||
\luamml_flag_save:n {mtd}
|
\luamml_flag_save:nn {} {mtd}
|
||||||
\d@llarend
|
\d@llarend
|
||||||
\__luamml_array_finalize_col:w 2~
|
\__luamml_array_finalize_col:w 2~
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
\m@th
|
\m@th
|
||||||
#1
|
#1
|
||||||
{#2}
|
{#2}
|
||||||
\luamml_flag_save:Nn #1 {mphantom}
|
\luamml_flag_save:nNn {} #1 {mphantom}
|
||||||
$
|
$
|
||||||
}
|
}
|
||||||
\finph@nt
|
\finph@nt
|
||||||
|
@ -9,6 +9,7 @@ local write_xml = require'luamml-xmlwriter'
|
|||||||
local write_struct = require'luamml-structelemwriter'
|
local write_struct = require'luamml-structelemwriter'
|
||||||
|
|
||||||
local filename_token = token.create'l__luamml_filename_tl'
|
local filename_token = token.create'l__luamml_filename_tl'
|
||||||
|
local label_token = token.create'l__luamml_label_tl'
|
||||||
|
|
||||||
local properties = node.get_properties_table()
|
local properties = node.get_properties_table()
|
||||||
local mmode, hmode, vmode do
|
local mmode, hmode, vmode do
|
||||||
@ -70,6 +71,8 @@ local mlist_result
|
|||||||
local undefined_cmd = token.command_id'undefined_cs'
|
local undefined_cmd = token.command_id'undefined_cs'
|
||||||
local call_cmd = token.command_id'call'
|
local call_cmd = token.command_id'call'
|
||||||
|
|
||||||
|
local labelled_mathml = {}
|
||||||
|
|
||||||
local function save_result(xml, display, structelem)
|
local function save_result(xml, display, structelem)
|
||||||
mlist_result = make_root(xml, display and 0 or 2)
|
mlist_result = make_root(xml, display and 0 or 2)
|
||||||
token.put_next(filename_token)
|
token.put_next(filename_token)
|
||||||
@ -121,6 +124,18 @@ luatexbase.add_to_callback('pre_mlist_to_hlist_filter', function(mlist, style)
|
|||||||
properties[startmath] = props
|
properties[startmath] = props
|
||||||
end
|
end
|
||||||
props.saved_mathml_table, props.saved_mathml_core = xml, core
|
props.saved_mathml_table, props.saved_mathml_core = xml, core
|
||||||
|
token.put_next(label_token)
|
||||||
|
local label = token.scan_argument()
|
||||||
|
if label ~= '' then
|
||||||
|
if labelled_mathml[label] then
|
||||||
|
tex.error('MathML Label already in use', {
|
||||||
|
'A MathML expression has a label which is already used by another \z
|
||||||
|
formula. If you do not want to label this formula with a unique \z
|
||||||
|
label, set a empty label instead.'})
|
||||||
|
else
|
||||||
|
labelled_mathml[label] = xml
|
||||||
|
end
|
||||||
|
end
|
||||||
if flag & 10 == 8 then
|
if flag & 10 == 8 then
|
||||||
write_struct(xml, true) -- This modifies xml in-place to reference the struture element
|
write_struct(xml, true) -- This modifies xml in-place to reference the struture element
|
||||||
end
|
end
|
||||||
@ -148,4 +163,5 @@ require'luamml-tex-annotate'
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
save_result = save_result,
|
save_result = save_result,
|
||||||
|
labelled = labelled_mathml,
|
||||||
}
|
}
|
||||||
|
41
luamml.dtx
41
luamml.dtx
@ -88,6 +88,7 @@
|
|||||||
%<luatex>\tl_new:N \l__luamml_filename_tl
|
%<luatex>\tl_new:N \l__luamml_filename_tl
|
||||||
\tl_new:N \l__luamml_root_tl
|
\tl_new:N \l__luamml_root_tl
|
||||||
\tl_set:Nn \l__luamml_root_tl { mrow }
|
\tl_set:Nn \l__luamml_root_tl { mrow }
|
||||||
|
\tl_new:N \l__luamml_label_tl
|
||||||
%<pdftex>\int_new:N \g__luamml_formula_id_int
|
%<pdftex>\int_new:N \g__luamml_formula_id_int
|
||||||
%<luatex>\int_new:N \tracingmathml
|
%<luatex>\int_new:N \tracingmathml
|
||||||
% \end{macrocode}
|
% \end{macrocode}
|
||||||
@ -110,6 +111,7 @@
|
|||||||
% \cs{luamml_flag_save:}.
|
% \cs{luamml_flag_save:}.
|
||||||
% \begin{macrocode}
|
% \begin{macrocode}
|
||||||
\cs_new_protected:Npn \luamml_flag_process: {
|
\cs_new_protected:Npn \luamml_flag_process: {
|
||||||
|
\tl_set:Nn \l__luamml_label_tl {}
|
||||||
\int_set:Nn \l__luamml_flag_int { 3 }
|
\int_set:Nn \l__luamml_flag_int { 3 }
|
||||||
}
|
}
|
||||||
% \end{macrocode}
|
% \end{macrocode}
|
||||||
@ -128,33 +130,37 @@
|
|||||||
}
|
}
|
||||||
% \end{macro}
|
% \end{macro}
|
||||||
%
|
%
|
||||||
% \begin{macro}{\luamml_flag_save:,
|
% \begin{macro}{\luamml_flag_save:n,
|
||||||
% \luamml_flag_save:N,
|
% \luamml_flag_save:nN,
|
||||||
% \luamml_flag_save:n,
|
% \luamml_flag_save:nn,
|
||||||
% \luamml_flag_save:Nn}
|
% \luamml_flag_save:nNn}
|
||||||
% Convert the current formula but only save it's representation in the math
|
% Convert the current formula but only save it's representation in the math
|
||||||
% node without emitting it as a complete formula. This is useful when the
|
% node without emitting it as a complete formula. This is useful when the
|
||||||
% expression forms part of a bigger formula and will be intergrated into it's
|
% expression forms part of a bigger formula and will be intergrated into it's
|
||||||
% MathML tables later by special code.
|
% MathML tables later by special code.
|
||||||
% It optinally accepts two parameters: One math style command
|
% It optinally accepts three parameters: A label, one math style command
|
||||||
% (\cs{displaystyle}, \cs{textstyle}, etc.) which is the implicit math style
|
% (\cs{displaystyle}, \cs{textstyle}, etc.) which is the implicit math style
|
||||||
% (so the style which the surrounding code expects this style to have) and a
|
% (so the style which the surrounding code expects this style to have) and a
|
||||||
% name for the root element (defaults to \texttt{mrow}).
|
% name for the root element (defaults to \texttt{mrow}).
|
||||||
% If the root element name is \texttt{mrow}, it will get suppressed in some
|
% If the root element name is \texttt{mrow}, it will get suppressed in some
|
||||||
% cases.
|
% cases.
|
||||||
% \begin{macrocode}
|
% \begin{macrocode}
|
||||||
\cs_new_protected:Npn \luamml_flag_save: {
|
\cs_new_protected:Npn \luamml_flag_save:n #1 {
|
||||||
|
\tl_set:Nn \l__luamml_label_tl {#1}
|
||||||
\int_set:Nn \l__luamml_flag_int { \__luamml_maybe_structelem: 1 }
|
\int_set:Nn \l__luamml_flag_int { \__luamml_maybe_structelem: 1 }
|
||||||
}
|
}
|
||||||
\cs_new_protected:Npn \luamml_flag_save:N #1 {
|
\cs_new_protected:Npn \luamml_flag_save:nN #1#2 {
|
||||||
\int_set:Nn \l__luamml_flag_int { \__luamml_maybe_structelem: 17 + 32 * #1 }
|
\tl_set:Nn \l__luamml_label_tl {#1}
|
||||||
|
\int_set:Nn \l__luamml_flag_int { \__luamml_maybe_structelem: 17 + 32 * #2 }
|
||||||
}
|
}
|
||||||
\cs_new_protected:Npn \luamml_flag_save:n {
|
\cs_new_protected:Npn \luamml_flag_save:nn #1 {
|
||||||
|
\tl_set:Nn \l__luamml_label_tl {#1}
|
||||||
\int_set:Nn \l__luamml_flag_int { \__luamml_maybe_structelem: 5 }
|
\int_set:Nn \l__luamml_flag_int { \__luamml_maybe_structelem: 5 }
|
||||||
\tl_set:Nn \l__luamml_root_tl
|
\tl_set:Nn \l__luamml_root_tl
|
||||||
}
|
}
|
||||||
\cs_new_protected:Npn \luamml_flag_save:Nn #1 {
|
\cs_new_protected:Npn \luamml_flag_save:nNn #1#2 {
|
||||||
\int_set:Nn \l__luamml_flag_int { \__luamml_maybe_structelem: 21 + 32 * #1 }
|
\tl_set:Nn \l__luamml_label_tl {#1}
|
||||||
|
\int_set:Nn \l__luamml_flag_int { \__luamml_maybe_structelem: 21 + 32 * #2 }
|
||||||
\tl_set:Nn \l__luamml_root_tl
|
\tl_set:Nn \l__luamml_root_tl
|
||||||
}
|
}
|
||||||
% \end{macrocode}
|
% \end{macrocode}
|
||||||
@ -176,6 +182,7 @@
|
|||||||
% \begin{macrocode}
|
% \begin{macrocode}
|
||||||
%<*luatex>
|
%<*luatex>
|
||||||
\cs_new_protected:Npn \luamml_flag_structelem: {
|
\cs_new_protected:Npn \luamml_flag_structelem: {
|
||||||
|
\tl_set:Nn \l__luamml_label_tl {}
|
||||||
\int_set:Nn \l__luamml_flag_int { 11 }
|
\int_set:Nn \l__luamml_flag_int { 11 }
|
||||||
}
|
}
|
||||||
%</luatex>
|
%</luatex>
|
||||||
@ -350,6 +357,8 @@
|
|||||||
\int_use:N \l__luamml_flag_int
|
\int_use:N \l__luamml_flag_int
|
||||||
:
|
:
|
||||||
\l__luamml_root_tl
|
\l__luamml_root_tl
|
||||||
|
:
|
||||||
|
\l__luamml_label_tl
|
||||||
}
|
}
|
||||||
\__luamml_pdf_showlists:
|
\__luamml_pdf_showlists:
|
||||||
\iow_now:Nx \l__luamml_pdf_stream {
|
\iow_now:Nx \l__luamml_pdf_stream {
|
||||||
@ -359,16 +368,6 @@
|
|||||||
% \end{macrocode}
|
% \end{macrocode}
|
||||||
% \end{macro}
|
% \end{macro}
|
||||||
%
|
%
|
||||||
% \begin{macro}{\luamml_pdf_last_formula:}
|
|
||||||
% A unique identifier for the last formula written with \cs{luamml_pdf_write:}.
|
|
||||||
% Some form of this will probably be added to the Lua\TeX insterface at some point.
|
|
||||||
% \begin{macrocode}
|
|
||||||
\cs_new:Npn \luamml_pdf_last_formula: {
|
|
||||||
\int_use:N \g__luamml_formula_id_int
|
|
||||||
}
|
|
||||||
% \end{macrocode}
|
|
||||||
% \end{macro}
|
|
||||||
%
|
|
||||||
% \begin{macrocode}
|
% \begin{macrocode}
|
||||||
%</pdftex>
|
%</pdftex>
|
||||||
% \end{macrocode}
|
% \end{macrocode}
|
||||||
|
@ -8,7 +8,7 @@ local math_lists_block = l.Ct('### ' * l.Cg(l.C'display' * ' ', 'display')^-1 *
|
|||||||
* non_final_list_block)^1
|
* non_final_list_block)^1
|
||||||
local generic_list_block = '### ' * (line - 'current page:') * non_final_list_block
|
local generic_list_block = '### ' * (line - 'current page:') * non_final_list_block
|
||||||
local luamml_block = l.Cg('LUAMML_FORMULA_BEGIN:' * id * ':' * l.Ct(
|
local luamml_block = l.Cg('LUAMML_FORMULA_BEGIN:' * id * ':' * l.Ct(
|
||||||
l.Cg(id, 'flag') * ':' * l.Cg((1-l.P'\n')^0, 'tag') * l.P'\n'^1
|
l.Cg(id, 'flag') * ':' * l.Cg((1-l.S':\n')^0, 'tag') * ':' * l.Cg((1-l.P'\n')^1, 'label')^-1 * l.P'\n'^1
|
||||||
|
|
||||||
* (math_lists_block + generic_list_block/0)^0
|
* (math_lists_block + generic_list_block/0)^0
|
||||||
* (line - 'LUAMML_FORMULA_END\n')^0
|
* (line - 'LUAMML_FORMULA_END\n')^0
|
||||||
|
@ -67,7 +67,7 @@ end
|
|||||||
-- 1: Only save
|
-- 1: Only save
|
||||||
-- 3: Generate normally
|
-- 3: Generate normally
|
||||||
for i, block in ipairs(parsed.groups) do
|
for i, block in ipairs(parsed.groups) do
|
||||||
local flag, tag = block.flag, block.tag
|
local flag, tag, label = block.flag, block.tag, block.label
|
||||||
block = block[1]
|
block = block[1]
|
||||||
if flag & 3 ~= 0 then
|
if flag & 3 ~= 0 then
|
||||||
local style = block.display and 0 or 2
|
local style = block.display and 0 or 2
|
||||||
@ -84,8 +84,11 @@ for i, block in ipairs(parsed.groups) do
|
|||||||
xml = {[0] = tag, xml}
|
xml = {[0] = tag, xml}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if style == 2 and flag & 1 == 1 then
|
if style == 2 and flag & 1 == 1 and label ~= '' then
|
||||||
parsed.mathml[i] = xml
|
if parsed.mathml[label] then
|
||||||
|
error'Invalid label reuse'
|
||||||
|
end
|
||||||
|
parsed.mathml[label] = xml
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user