Skip to content

Commit

Permalink
Merge pull request #153 from dohyunkim/master
Browse files Browse the repository at this point in the history
enhanced tagging of usemplibgroup
  • Loading branch information
dohyunkim authored Nov 28, 2024
2 parents d15a132 + 366297f commit 4ef1d0f
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 27 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
History of the luamplib package

2024/11/28 2.35.2
* fix height/depth of boxes made by \mplibgroup command
* enhanced tagging of \usemplibgroup

2024/11/25 2.35.1
* cope with 'TEX(char13)': remove everything from char13 to the end of
input string (https://tug.org/pipermail/metapost/2024-November/003572.html)
Expand Down
109 changes: 82 additions & 27 deletions luamplib.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ See source file '\inFileName' for licencing and contact information.
%<*driver>
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{luamplib.drv}%
[2024/11/25 v2.35.1 Interface for using the mplib library]%
[2024/11/28 v2.35.2 Interface for using the mplib library]%
\documentclass{ltxdoc}
\usepackage{metalogo,multicol,xspace}
\usepackage[x11names]{xcolor}
Expand Down Expand Up @@ -155,7 +155,7 @@ See source file '\inFileName' for licencing and contact information.
% \author{Hans Hagen, Taco Hoekwater, Elie Roux, Philipp Gesang and Kim Dohyun\\
% Current Maintainer: Kim Dohyun\\
% Support: \url{https://github.com/lualatex/luamplib}}
% \date{2024/11/25 v2.35.1}
% \date{2024/11/28 v2.35.2}
%
% \maketitle
%
Expand Down Expand Up @@ -354,7 +354,7 @@ See source file '\inFileName' for licencing and contact information.
% will be typeset with the current \TeX\ font.
%
% From v2.35, however, the redefinition of |infont| operator has been revised:
% when the character slot of the text argument is less than $32$~(control characters),
% when the character code of the text argument is less than $32$~(control characters),
% or is equal to $35$~(|#|), $36$~(|$|), \iffalse |$|\fi
% $37$~(|%|), $38$~(|&|), $92$~(|\|), $94$~(|^|),
% $95$~(|_|), $123$~(|{|), $125$~(|}|), $126$~(|~|) or $127$~(DEL),
Expand Down Expand Up @@ -1009,7 +1009,8 @@ See source file '\inFileName' for licencing and contact information.
% As shown in the example, you can reuse the mplibgroup once defined
% using the \TeX\ command \cs{usemplibgroup} or
% the \metapost command |usemplibgroup|.
% The behavior of these commands is the same as that described \hyperlink{usemplibgroup}{above}.
% The behavior of these commands is the same as that described \hyperlink{usemplibgroup}{above},
% excepting that mplibgroup made by \TeX\ code (not by \metapost code) respects original height and depth.
%
%
% \subsection{Lua}
Expand Down Expand Up @@ -1097,8 +1098,8 @@ See source file '\inFileName' for licencing and contact information.

luatexbase.provides_module {
name = "luamplib",
version = "2.35.1",
date = "2024/11/25",
version = "2.35.2",
date = "2024/11/28",
description = "Lua package to typeset Metapost with LuaTeX's MPLib.",
}

Expand Down Expand Up @@ -2811,7 +2812,7 @@ def withgroupname expr s =
withprescript "mplibgroupname=" & s
enddef;
def usemplibgroup primary s =
draw maketext("\mplibnoforcehmode\csname luamplib.group." & s & "\endcsname")
draw maketext("\csname luamplib.group." & s & "\endcsname")
shifted runscript("return luamplib.trgroupshifts['" & s & "']")
enddef;
]],
Expand Down Expand Up @@ -3684,12 +3685,17 @@ local function do_preobj_GRP (object, prescript)
put2output(tableconcat{
"\\saveboxresource type 2 attr{/Type/XObject/Subtype/Form/FormType 1",
"/BBox[", bbox, "]", grattr, "} resources{", res, "}\\mplibscratchbox",
"\\luamplibtagasgroupbegin",
[[\setbox\mplibscratchbox\hbox{\useboxresource\lastsavedboxresourceindex}]],
[[\wd\mplibscratchbox 0pt\ht\mplibscratchbox 0pt\dp\mplibscratchbox 0pt]],
[[\box\mplibscratchbox\endgroup]],
[[\box\mplibscratchbox]],
"\\luamplibtagasgroupend",
"\\endgroup",
"\\expandafter\\xdef\\csname luamplib.group.", trgroup.name, "\\endcsname{",
"\\noexpand\\mplibstarttoPDF{",llx,"}{",lly,"}{",urx,"}{",ury,"}",
"\\useboxresource \\the\\lastsavedboxresourceindex\\noexpand\\mplibstoptoPDF}",
"\\setbox\\mplibscratchbox\\hbox{\\hskip",-llx,"bp\\raise",-lly,"bp\\hbox{",
"\\useboxresource \\the\\lastsavedboxresourceindex",
"}}\\wd\\mplibscratchbox",urx-llx,"bp\\ht\\mplibscratchbox",ury-lly,"bp",
"\\box\\mplibscratchbox}",
})
else
trgroup.cnt = (trgroup.cnt or 0) + 1
Expand All @@ -3699,11 +3705,14 @@ local function do_preobj_GRP (object, prescript)
"\\unhbox\\mplibscratchbox",
"\\special{pdf:put @resources <<", res, ">>}",
"\\special{pdf:exobj <<", grattr, ">>}",
"\\special{pdf:uxobj ", objname, "}\\endgroup",
"\\special{pdf:uxobj ", objname, "}",
"\\endgroup",
})
token.set_macro("luamplib.group."..trgroup.name, tableconcat{
"\\mplibstarttoPDF{",llx,"}{",lly,"}{",urx,"}{",ury,"}",
"\\special{pdf:uxobj ", objname, "}\\mplibstoptoPDF",
"\\setbox\\mplibscratchbox\\hbox{\\hskip",-llx,"bp\\raise",-lly,"bp\\hbox{",
"\\special{pdf:uxobj ", objname, "}",
"}}\\wd\\mplibscratchbox",urx-llx,"bp\\ht\\mplibscratchbox",ury-lly,"bp",
"\\box\\mplibscratchbox",
}, "global")
end
trgroup.shifts[trgroup.name] = { llx, lly }
Expand Down Expand Up @@ -3739,16 +3748,13 @@ function luamplib.registergroup (boxid, name, opts)
local trgroup = pdfetcs.tr_group
trgroup.shifts[name] = { get_macro'MPllx', get_macro'MPlly' }
local whd
local urx, ury = wd/factor, (ht+dp)/factor
if pdfmode then
attr = tableconcat(attr) :gsub(decimals,rmzeros)
local index = tex.saveboxresource(boxid, attr, res, true, grtype)
token.set_macro("luamplib.group."..name, tableconcat{
"\\mplibstarttoPDF{0}{0}{",urx,"}{",ury,"}",
"\\useboxresource ", index,
"\\mplibstoptoPDF",
}, "global")
whd = format("%.3f %.3f 0", urx, ury) :gsub(decimals,rmzeros)
whd = format("%.3f %.3f 0", wd/factor, (ht+dp)/factor) :gsub(decimals,rmzeros)
else
trgroup.cnt = (trgroup.cnt or 0) + 1
local objname = format("@mplibtrgr%s", trgroup.cnt)
Expand All @@ -3764,15 +3770,13 @@ function luamplib.registergroup (boxid, name, opts)
"\\special{pdf:econtent}}",
}
token.set_macro("luamplib.group."..name, tableconcat{
"\\mplibstarttoPDF{0}{0}{",urx,"}{",ury,"}",
"\\setbox\\mplibscratchbox\\hbox{\\special{pdf:uxobj ", objname, "}}",
"\\wd\\mplibscratchbox ", wd, "sp",
"\\ht\\mplibscratchbox ", ht, "sp",
"\\dp\\mplibscratchbox ", dp, "sp",
"\\box\\mplibscratchbox",
"\\mplibstoptoPDF",
}, "global")
whd = format("%.3f %.3f %.3f", urx, ht/factor, dp/factor) :gsub(decimals,rmzeros)
whd = format("%.3f %.3f %.3f", wd/factor, ht/factor, dp/factor) :gsub(decimals,rmzeros)
end
info("w/h/d of group '%s': %s", name, whd)
end
Expand Down Expand Up @@ -4201,7 +4205,7 @@ end
% \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{luamplib}
[2024/11/25 v2.35.1 mplib package for LuaTeX]
[2024/11/28 v2.35.2 mplib package for LuaTeX]
\fi
\ifdefined\newluafunction\else
\input ltluatex
Expand Down Expand Up @@ -4286,7 +4290,13 @@ end
% use Transparency Group
% \begin{macrocode}
\protected\def\usemplibgroup#1#{\usemplibgroupmain}
\def\usemplibgroupmain#1{\csname luamplib.group.#1\endcsname}
\def\usemplibgroupmain#1{%
\mplibstarttousemplibgroup
\csname luamplib.group.#1\endcsname
\mplibstoptousemplibgroup
}
\def\mplibstarttousemplibgroup{\prependtomplibbox\hbox\bgroup}
\def\mplibstoptousemplibgroup{\egroup}
\protected\def\mplibgroup#1{%
\begingroup
\def\MPllx{0}\def\MPlly{0}%
Expand Down Expand Up @@ -4713,6 +4723,8 @@ end
% \begin{macrocode}
\def\luamplibtagtextbegin#1{}
\let\luamplibtagtextend\relax
\let\luamplibtagasgroupbegin\relax
\let\luamplibtagasgroupend\relax
\ifcsname SuspendTagging\endcsname\else\endinput\fi
\ifcsname [email protected]\endcsname \else
\ExplSyntaxOn
Expand Down Expand Up @@ -4742,6 +4754,8 @@ end
\let\mplibstarttoPDForiginal\mplibstarttoPDF
\let\mplibstoptoPDForiginal\mplibstoptoPDF
\let\mplibputtextboxoriginal\mplibputtextbox
\let\mplibstarttousemplibgrouporiginal\mplibstarttousemplibgroup
\let\mplibstoptousemplibgrouporiginal\mplibstoptousemplibgroup
\ExplSyntaxOn
\tl_new:N \l__luamplib_tag_alt_tl
\tl_new:N \l__luamplib_tag_alt_dflt_tl
Expand Down Expand Up @@ -4773,8 +4787,8 @@ end
}
{
\tag_if_active:TF
{ \chardef\mplibtmpnum\@ne }
{ \chardef\mplibtmpnum\z@ }
{ \bool_set_true:N \l_tmpa_bool }
{ \bool_set_false:N \l_tmpa_bool }
\SuspendTagging{luamplib.textext}
}
}
Expand All @@ -4796,9 +4810,8 @@ end
\tag_mc_begin_pop:n{}
}
{
\ifnum\mplibtmpnum=\@ne
\ResumeTagging{luamplib.textext}
\fi
\bool_if:NT \l_tmpa_bool
{ \ResumeTagging{luamplib.textext} }
}
}
\msg_new:nnn {luamplib}{figure-text-reuse}
Expand Down Expand Up @@ -5082,6 +5095,46 @@ end
}
}
}
\cs_set_nopar:Npn \luamplibtagasgroupbegin
{
\bool_if:NT \l__luamplib_tag_usetext_bool
{
\ResumeTagging{luamplib.asgroup}
\tag_mc_begin:n{}
}
}
\cs_set_nopar:Npn \luamplibtagasgroupend
{
\bool_if:NT \l__luamplib_tag_usetext_bool
{
\tag_mc_end:
\SuspendTagging{luamplib.asgroup}
}
}
\cs_set_nopar:Npn \mplibstarttousemplibgroup
{
\prependtomplibbox\hbox\bgroup
\luamplibtaggingbegin
\setbox\mplibscratchbox\hbox\bgroup
\bool_if:NT \l__luamplib_tag_usetext_bool
{
\tag_mc_end:
\tag_mc_begin:n{}
}
}
\cs_set_nopar:Npn \mplibstoptousemplibgroup
{
\bool_if:NT \l__luamplib_tag_usetext_bool
{
\tag_mc_end:
\tag_mc_begin:n{artifact}
}
\egroup
\luamplibtaggingBBox
\unhbox\mplibscratchbox
\luamplibtaggingend
\egroup
}
\cs_set_nopar:Npn \mplibstarttoPDF #1 #2 #3 #4
{
\prependtomplibbox
Expand Down Expand Up @@ -5161,7 +5214,9 @@ end
}
\keys_set:nn{luamplib/tag}{#1}
\tl_set:Nn\l__luamplib_tag_alt_dflt_tl {metapost~figure~#2}
\mplibstarttousemplibgroup
\csname luamplib.group.#2\endcsname
\mplibstoptousemplibgroup
\endgroup
}
\cs_new_nopar:Npn \mplibalttext #1
Expand Down

0 comments on commit 4ef1d0f

Please sign in to comment.