diff options
author | Karl Berry <karl@freefriends.org> | 2023-09-11 21:18:21 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2023-09-11 21:18:21 +0000 |
commit | ae083fc25ee9fdf450d486d4f890261f40deebb9 (patch) | |
tree | 8395f901d45235ad409c17b934526c727c8bc1b0 /Master/texmf-dist/tex/latex | |
parent | 17c4a2fddf7936f6c81aa83dd7ea1a4f65a01578 (diff) |
newpax (11sep23)
git-svn-id: svn://tug.org/texlive/trunk@68242 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex')
-rw-r--r-- | Master/texmf-dist/tex/latex/newpax/newpax.lua | 40 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/newpax/newpax.sty | 263 |
2 files changed, 179 insertions, 124 deletions
diff --git a/Master/texmf-dist/tex/latex/newpax/newpax.lua b/Master/texmf-dist/tex/latex/newpax/newpax.lua index 84af72af05b..549effa1ac0 100644 --- a/Master/texmf-dist/tex/latex/newpax/newpax.lua +++ b/Master/texmf-dist/tex/latex/newpax/newpax.lua @@ -20,8 +20,8 @@ -- local ProvidesLuaModule = { name = "newpax", - version = "0.53", --TAGVERSION - date = "2022-09-15", --TAGDATE + version = "0.54", --TAGVERSION + date = "2023-09-11", --TAGDATE description = "newpax lua code", license = "The LATEX Project Public License 1.3c" } @@ -406,11 +406,19 @@ local function outputKV_gotor (pdfedict) -- action dictionary return a end +-- this outputs the key DestLabel with a count + local function outputKV_goto (count) local a = strKV_BEG .. constKEY_DEST_LABEL .. strVALUE_BEG .. count .. strVALUE_END .. strKV_END return a end +-- this outputs the key DestName with a name +local function outputKV_goto_name (name) + local a = strKV_BEG .. constKEY_DEST_NAME .. strVALUE_BEG .. name .. strVALUE_END .. strKV_END + return a +end + local function outputENTRY_dest (destcount,name,pagereftonum,destnamestoref,pdfedoc) local pagenum, data = getdestdata(name,pagereftonum,destnamestoref) local mediabox = pdfe.getbox(GETPAGE(pdfedoc,pagenum),"MediaBox") @@ -430,7 +438,7 @@ local function outputENTRY_dest (destcount,name,pagereftonum,destnamestoref,pdfe if data[4] and data[4][2] then a = a .. strKV_BEG .. constKEY_DEST_Y .. strVALUE_BEG .. data[4][2] .. strVALUE_END .. strKV_END else - a = a .. strKV_BEG .. constKEY_DEST_X .. strVALUE_BEG .. mediabox[4] .. strVALUE_END .. strKV_END + a = a .. strKV_BEG .. constKEY_DEST_Y .. strVALUE_BEG .. mediabox[4] .. strVALUE_END .. strKV_END end if data[5] and data[5][2] then a = a .. strKV_BEG .. constKEY_DEST_ZOOM .. strVALUE_BEG .. data[5][2] .. strVALUE_END .. strKV_END @@ -460,6 +468,11 @@ local function outputENTRY_dest (destcount,name,pagereftonum,destnamestoref,pdfe a = a .. data[5][2] .. strRECT_SEP a = a .. data[6][2] .. strVALUE_END .. strKV_END end + -- output also the name. This perhaps need a check if the name exists + -- print("DEBUG TYPE name", TYPE(name)) + if not (TYPE(name) == "pdfe.array") then + a = a .. strKV_BEG .. constKEY_DEST_NAME .. strVALUE_BEG .. name .. strVALUE_END .. strKV_END + end a = a .. strKVS_END .. strENTRY_END return a end @@ -480,6 +493,7 @@ local function __writepax (ext,file) -- build from names table: local destnamestorefVAR = getdestreferences (docVAR) local collected_destinations = {} + local useddestnames = {} -- output ... WRITE(strENTRY_BEG .. "{pax}{0.1l}" .. strENTRY_END) WRITE(outputENTRY_file(fileVAR,docVAR)) @@ -508,6 +522,7 @@ local function __writepax (ext,file) annotgoto,pagereftonumVAR,destnamestorefVAR,docVAR)) else local annotaction = GETDICTIONARY(annot,"A") + -- print("DEBUG A:",table.serialize(DICTIONARYTOTABLE(annotaction))) local annotactiontype ="" if annotaction then annotactiontype = GETNAME(annotaction,"S") @@ -521,8 +536,14 @@ local function __writepax (ext,file) if annotactiontype == constKEY_URI then WRITE ( outputKV_uri(annotaction) ) elseif annotactiontype =="GoTo" then + local desttype, destname, destdetail = GETFROMDICTIONARY(annotaction,"D") + -- print("DEBUG annotaction", desttype, destname, destdetail) destcountVAR=destcountVAR + 1 WRITE ( outputKV_goto (destcountVAR) ) + -- this needs perhaps a check if destname actually exists. + if desttype == 6 then + WRITE ( outputKV_goto_name(destname) ) + end elseif annotactiontype=="GoToR" then WRITE ( outputKV_gotor(annotaction) ) elseif annotactiontype=="Named" then @@ -532,6 +553,10 @@ local function __writepax (ext,file) WRITE(strENTRY_END) -- end annot data if annotactiontype =="GoTo" then local type,annotactiongoto,hex = GETFROMDICTIONARY(annotaction,"D") + if type==6 then + -- record used name + useddestnames[annotactiongoto] = 1 + end table.insert(collected_destinations, outputENTRY_dest(destcountVAR,annotactiongoto,pagereftonumVAR,destnamestorefVAR,docVAR)) end end @@ -542,6 +567,15 @@ local function __writepax (ext,file) for i=1,#collected_destinations do WRITE (collected_destinations[i]) end + -- write out the rest of the destinations. + for k,v in pairs (destnamestorefVAR) do + -- ignore use dests and page destinations. + i=string.find(k,"page.",1) + if not useddestnames[k] and not i then + destcountVAR=destcountVAR + 1 + WRITE(outputENTRY_dest(destcountVAR,k,pagereftonumVAR,destnamestorefVAR,docVAR)) + end + end io.close(writeVAR) end diff --git a/Master/texmf-dist/tex/latex/newpax/newpax.sty b/Master/texmf-dist/tex/latex/newpax/newpax.sty index bfb11d9a4dc..dae7710a71c 100644 --- a/Master/texmf-dist/tex/latex/newpax/newpax.sty +++ b/Master/texmf-dist/tex/latex/newpax/newpax.sty @@ -18,14 +18,12 @@ %% This file is part of the "newpax bundle" (The Work in LPPL) %% and all files in that bundle must be distributed together. %% -\NeedsTeXFormat{LaTeX2e} +\NeedsTeXFormat{LaTeX2e}[2022-11-01] \ProvidesPackage{newpax}% - [2022-09-15 v0.53 Annotation support for PDF graphics based on pax.sty adapted by (UF)]% + [2023-09-11 v0.54 Annotation support for PDF graphics based on pax.sty adapted by (UF)]% \ExplSyntaxOn -\bool_if:nF - { - \cs_if_exist_p:N \pdfmanagement_if_active_p: - } +\IfDocumentMetadataTF + {} { %error for now, perhaps warning later. \PackageError{newpax} { @@ -34,30 +32,30 @@ } { Load~it~with \MessageBreak - \string\RequirePackage{pdfmanagement-testphase}\MessageBreak + \string\DocumentMetadata{}\MessageBreak before~loading~the~class } } \ExplSyntaxOff \RequirePackage{graphicx} -\RequirePackage{ltxcmds}[2011/04/18] -\RequirePackage{kvsetkeys}[2011/04/07] -\RequirePackage{kvoptions}[2010/12/23] -\RequirePackage{auxhook}[2011/03/04] \RequirePackage{etoolbox} -\RequirePackage{xfp} \ExplSyntaxOn -\cs_set_eq:NN \newpax@str@if@eq@@nnT\str_if_eq:nnT +\box_new:N \l__newpax_tmpa_box \bool_new:N \l__newpax_use_attributes_bool \bool_new:N \l__newpax_addannots_bool +\bool_new:N \l__newpax_dests_all_bool \tl_new:N \l__newpax_destsuffix_tl \tl_new:N \NEWPAX@fileextension - +\tl_new:N \NEWPAX@Gin@box@opts +\newif\ifNEWPAX@Gin@clip +\cs_set_eq:NN \newpax@str@if@eq@@nnT\str_if_eq:nnT \cs_generate_variant:Nn \pdfannot_dict_put:nnn {nnx,xnx,xnn} +\cs_generate_variant:Nn \pdfannot_link_goto_begin:nw {xw} +\cs_generate_variant:Nn \pdf_destination:nn {xx} \NewDocumentCommand\newpaxsetup { m } { \keys_set:nn {newpax}{ #1} @@ -66,14 +64,18 @@ \keys_define:nn {newpax} { usefileattributes .bool_set:N = \l__newpax_use_attributes_bool, - destsuffix .tl_set:N = \l__newpax_destsuffix_tl, + destsuffix .code:n = {\tl_set:Nn \l__newpax_destsuffix_tl{@#1}}, addannots .bool_set:N = \l__newpax_addannots_bool, addannots .default:n = true, addannots .initial:n = true, paxextension .choices:nn = {pax,newpax} {\tl_set:Nn \NEWPAX@fileextension {#1}}, - paxextension .initial:n = newpax + paxextension .initial:n = newpax, + dests .choice:, + dests/all .code:n = {\bool_set_true:N \l__newpax_dests_all_bool}, + dests/used .code:n = {\bool_set_false:N \l__newpax_dests_all_bool}, + dests .initial:n = used } \cs_new_protected:Npn \@NEWPAX@setattributes@n #1 %link type @@ -126,75 +128,64 @@ \cs_new_protected:Npn \@NEWPAX@linkgoto@xnn #1 #2 #3 %#1 dest #2 width #3 height { \group_begin: - \exp_args:Nx\@NEWPAX@setattributes@n {GoTo} + \@NEWPAX@setattributes@n {GoTo} \leavevmode - \exp_args:Nx\pdfannot_link_goto_begin:nw + \pdfannot_link_goto_begin:xw { #1 } \@NEWPAX@ensurelinkbox@n{\hbox_to_wd:nn {#2}{ { \rule{0pt}{#3} }\hfill}} \pdfannot_link_goto_end: \group_end: } - \cs_new_protected:Npn \@NEWPAX@link@setaction@nn #1 #2 { \pdfannot_dict_put:nnn{link/#1}{Subtype}{/Link} \pdfannot_dict_put:nnx{link/#1}{A} {<</Type/Action/S/#1 #2>>} } - \cs_new_protected:Npn \@NEWPAX@annotboxlink@nnn #1 #2 #3 %#1 type, #2 width #3 height { \group_begin: - \exp_args:Nx\@NEWPAX@setattributes@n {#1} + \@NEWPAX@setattributes@n {#1} \leavevmode \pdfannot_box:nnnx {#2}{#3}{0pt} {\pdfannot_dict_use:n{link/#1}} \group_end: } - \cs_new_protected:Npn \@NEWPAX@destination@xx #1 #2 { - \exp_args:Nxx \pdf_destination:nn {#1}{#2} + \pdf_destination:xx {#1}{#2} } - -\sys_if_engine_xetex:TF +\cs_new_eq:NN \@NEWPAX@ensurelinkbox@n \use:n +\AddToHook{package/hyperref/after} { - \cs_set_eq:NN \@NEWPAX@ensurelinkbox@n \XeTeXLinkBox + \sys_if_engine_xetex:T + { + \cs_set_eq:NN \@NEWPAX@ensurelinkbox@n \XeTeXLinkBox + } } +\NewCommandCopy\NEWPAX@ORG@includegraphics\includegraphics +\RenewDocumentCommand\includegraphics{sO{}m} { - \cs_set_eq:NN \@NEWPAX@ensurelinkbox@n \use:n + \IfBooleanTF {#1} + { + \NEWPAX@includegraphics[clip,#2]{#3} + } + { + \NEWPAX@includegraphics[#2]{#3} + } } -\ExplSyntaxOff -\let\NEWPAX@ORG@includegraphics\includegraphics -\def\includegraphics{% - \@ifstar{% - \@ifnextchar[{% - \begingroup - \def\x{\endgroup - \NEWPAX@includegraphics[clip,% - }% - \expandafter\x\@gobble - }{% - \NEWPAX@includegraphics[clip]% - }% - }{% - \@ifnextchar[{% - \NEWPAX@includegraphics - }{% - \NEWPAX@includegraphics[]% - }% - }% -} - -\ExplSyntaxOn \def\NEWPAX@includegraphics[#1]#2{% - \begingroup - \sbox0{\NEWPAX@ORG@includegraphics[{#1}]{#2}}% - \edef\NEWPAX@inc@width{\the\wd0}% - \edef\NEWPAX@inc@height{\the\dimexpr\dp0+\ht0}% - \leavevmode - \hbox to \wd0{% - \rlap{\copy0}% + \group_begin: + \hbox_set:Nn \l__newpax_tmpa_box {\NEWPAX@ORG@includegraphics[{#1}]{#2}}% + \tl_set:Nx \NEWPAX@inc@width + { \dim_eval:n { \box_wd:N \l__newpax_tmpa_box } }% + \tl_set:Nx \NEWPAX@inc@height + { \dim_eval:n { \box_dp:N \l__newpax_tmpa_box + \box_ht:N \l__newpax_tmpa_box } }% + \mode_leave_vertical: + \hbox_to_wd:nn + { \box_wd:N \l__newpax_tmpa_box } + { + \hbox_overlap_right:n { \box_use:N \l__newpax_tmpa_box } \bool_if:nT { \l__newpax_addannots_bool && @@ -211,31 +202,39 @@ ) } { - \raise-\dp0\hbox - { - \NEWPAX@AddAnnots{#1}{#2}% - } + \box_move_down:nn + {\box_dp:N \l__newpax_tmpa_box } + { + \hbox:n + { + \NEWPAX@AddAnnots{#1}{#2}% + } + } } \hfill } - \endgroup + \group_end: } +\keys_define:nn {newpax/Gin} + { + ,page .tl_set:N = \NEWPAX@Gin@page + ,page .initial:n = 1 + ,angle .tl_set:N = \NEWPAX@Gin@angle + ,angle .initial:n = 0 + ,clip .legacy_if_set:n = NEWPAX@Gin@clip + ,viewport .code:n = + { + \tl_put_right:Nn\NEWPAX@Gin@box@opts + {\NEWPAX@viewport#1\\} + } + ,trim .code:n = + { + \tl_put_right:Nn\NEWPAX@Gin@box@opts + {\NEWPAX@trim#1\\} + } + ,unknown .code:n = {} + } \ExplSyntaxOff -\SetupKeyvalOptions{family=NEWPAX@Gin,prefix=NEWPAX@Gin@} -\DeclareStringOption[1]{page} -\DeclareStringOption[0]{angle} -\DeclareBoolOption{clip} -\define@key{NEWPAX@Gin}{viewport}{% - \ltx@LocalAppendToMacro\NEWPAX@Gin@box@opts{% - \NEWPAX@viewport#1\\% - }% -} -\define@key{NEWPAX@Gin}{trim}{% - \ltx@LocalAppendToMacro\NEWPAX@Gin@box@opts{% - \NEWPAX@trim#1\\% - }% -} -\let\NEWPAX@Gin@box@opts\@empty \def\NEWPAX@viewport#1 #2 #3 #4\\{% \NEWPAX@defaultbp\NEWPAX@vllx{#1}% @@ -257,7 +256,6 @@ \edef\NEWPAX@page@urx{\dimexpr\NEWPAX@page@urx-\NEWPAX@turx\relax}% \edef\NEWPAX@page@ury{\dimexpr\NEWPAX@page@ury-\NEWPAX@tury\relax}% } - \def\NEWPAX@defaultbp#1#2{% \afterassignment\NEWPAX@def@bp\dimen@#2bp\relax{#1}{#2}% } @@ -268,11 +266,8 @@ \edef#2{#3}% \fi } - -\kv@set@family@handler{NEWPAX@Gin}{} - \def\NEWPAX@AddAnnots#1#2{% - \kvsetkeys{NEWPAX@Gin}{#1}% + \SetKeys[newpax/Gin]{#1}% \Grot@setangle{\NEWPAX@Gin@angle}% % a little careful, is type of angle int or real? \loop @@ -357,10 +352,12 @@ \NEWPAX@call{link}{#2}{% \begingroup \NEWPAX@getrect{annot}#1\@nil - \kvsetkeys{NEWPAX}{#3}% + \SetKeys[newpax/key]{#3}% }% \NEWPAX@skip } + + \newif\ifNEWPAX@ok \NEWPAX@oktrue @@ -450,7 +447,7 @@ %additional box for lualatex ... \hbox{% \@NEWPAX@linkgoto@xnn - {NEWPAX@\NEWPAX@file @\NEWPAX@key@DestLabel @\csname l__newpax_destsuffix_tl\endcsname}% + {\NEWPAX@file @\NEWPAX@DestName}% {\NEWPAX@width}% {\NEWPAX@height}% }% @@ -466,12 +463,10 @@ \fi \endgroup } - \def\NEWPAX@htype@GoToR{file} \def\NEWPAX@htype@GoTo{link} \def\NEWPAX@htype@Named{link} \def\NEWPAX@htype@URI{url} - \ExplSyntaxOn \def\NEWPAX@link@URI{% \NEWPAX@pdf@annot{% @@ -495,25 +490,39 @@ \fi }% } - - -\AddLineBeginAux{% - \string\providecommand{\string\NEWPAX@DestReq}[2]{}% -} -\AddLineBeginAux{% - \string\providecommand{\string\NEWPAX@DestProv}[2]{}% -} +\AddToHook{begindocument} + { + \immediate\write\@mainaux{\string\providecommand{\string\NEWPAX@DestReq}[2]{}} + \immediate\write\@mainaux{\string\providecommand{\string\NEWPAX@DestProv}[2]{}} + } +\AddToHook + {include/before} + { + \immediate\write\@partaux{\string\providecommand{\string\NEWPAX@DestReq}[2]{}} + \immediate\write\@partaux{\string\providecommand{\string\NEWPAX@DestProv}[2]{}} + } \AtBeginDocument{% \let\NEWPAX@DestReq\@gobbletwo \let\NEWPAX@DestProv\@gobbletwo } + \def\NEWPAX@DestReq#1#2{% \expandafter\gdef\csname NEWPAX@REQ@#1@#2\endcsname{}% } + \def\NEWPAX@DestProv#1#2{% \expandafter\gdef\csname NEWPAX@PROV@#1@#2\endcsname{}% } +\ExplSyntaxOn +\cs_new:Npn \NEWPAX@DestName + { + \tl_if_empty:eTF + { \NEWPAX@key@DestName } + { \NEWPAX@key@DestLabel} + { \NEWPAX@key@DestName } + \l__newpax_destsuffix_tl + } \def\NEWPAX@link@GoTo{% \ifnum0<0\NEWPAX@key@DestLabel\relax \expandafter\@firstofone @@ -524,11 +533,11 @@ {% \if@filesw \protected@write\@auxout{}{% - \string\NEWPAX@DestReq{\NEWPAX@file}{\NEWPAX@key@DestLabel}% + \string\NEWPAX@DestReq{\NEWPAX@file}{\NEWPAX@DestName}% }% \fi % Generate link, if destination exists - \@ifundefined{NEWPAX@PROV@\NEWPAX@file @\NEWPAX@key@DestLabel}{% + \@ifundefined{NEWPAX@PROV@\NEWPAX@file @\NEWPAX@DestName}{% \endgroup }{% \NEWPAX@GoTotrue @@ -536,20 +545,29 @@ }% }% } - \def\NEWPAX@cmd@dest#1#2#3#4{% + \def\NEWPAX@key@DestLabel{#2}% + \def\NEWPAX@key@DestName{}% + \keys_set_groups:nnn {newpax/key} {destinit} {#4} \NEWPAX@filter@page{#1}{% \if@filesw \protected@write\@auxout{}{% - \string\NEWPAX@DestProv{\NEWPAX@file}{#2}% + \string\NEWPAX@DestProv{\NEWPAX@file}{\NEWPAX@DestName}% }% + \bool_if:NT\l__newpax_dests_all_bool + { + \protected@write\@auxout{} + { + \string\NEWPAX@DestReq{\NEWPAX@file}{\NEWPAX@DestName}% + } + } \fi - \@ifundefined{NEWPAX@REQ@\NEWPAX@file @#2}{% + \@ifundefined{NEWPAX@REQ@\NEWPAX@file @\NEWPAX@DestName}{% }{% \begingroup \let\NEWPAX@key@DestY\NEWPAX@page@ury \let\NEWPAX@key@DestX\NEWPAX@page@llx - \kvsetkeys{NEWPAX}{#4}% + \keys_set_filter:nnn {newpax/key} {destinit} {#4} \let\NEWPAX@dest@llx\NEWPAX@key@DestX \let\NEWPAX@dest@urx\NEWPAX@key@DestX \let\NEWPAX@dest@lly\NEWPAX@key@DestY @@ -621,7 +639,8 @@ \NEWPAX@scale@y\dimexpr\NEWPAX@dest@lly-\NEWPAX@page@lly\relax }% \fi - \edef\NEWPAX@name{NEWPAX@\NEWPAX@file @#2@\csname l__newpax_destsuffix_tl\endcsname}% + \edef\NEWPAX@name + {\NEWPAX@file @\NEWPAX@DestName}% \let\NEWPAX@type\@empty \newpax@str@if@eq@@nnT{#3}{FITR}{\def\NEWPAX@type{xyz}}%too lazy for now for better fitr \newpax@str@if@eq@@nnT{#3}{XYZ} @@ -647,31 +666,33 @@ \hss }% \endgroup + \cs_undefine:c{NEWPAX@REQ@\NEWPAX@file @\NEWPAX@DestName} }% \NEWPAX@skip }% } +\keys_define:nn {newpax/key} + { + ,URI .tl_set:N = \NEWPAX@key@URI + ,Name .tl_set:N = \NEWPAX@key@Name + ,DestName .tl_set:N = \NEWPAX@key@DestName + ,DestName .groups:n = {destinit} + ,DestPage .tl_set:N = \NEWPAX@key@DestPage + ,DestView .tl_set:N = \NEWPAX@key@DestView + ,File .tl_set:N = \NEWPAX@key@File + ,C .tl_set:N = \NEWPAX@key@C + ,Border .tl_set:N = \NEWPAX@key@Border + ,BS .tl_set:N = \NEWPAX@key@BS + ,H .tl_set:N = \NEWPAX@key@H + ,DestLabel .tl_set:N = \NEWPAX@key@DestLabel + ,DestLabel .groups:n = {destinit} + ,DestRect .tl_set:N = \NEWPAX@key@DestRect + ,DestZoom .tl_set:N = \NEWPAX@key@DestZoom + ,DestX .code:n = { \NEWPAX@defaultbp\NEWPAX@key@DestX{#1} } + ,DestY .code:n = { \NEWPAX@defaultbp\NEWPAX@key@DestY{#1} } + } +\ExplSyntaxOff -\SetupKeyvalOptions{family=NEWPAX,prefix=NEWPAX@key@} -\DeclareStringOption{URI} -\DeclareStringOption{Name} -\DeclareStringOption{DestName} -\DeclareStringOption{DestPage} -\DeclareStringOption{DestView} -\DeclareStringOption{File} -\DeclareStringOption{C} -\DeclareStringOption{Border} -\DeclareStringOption{BS} -\DeclareStringOption{H} -\DeclareStringOption{DestLabel} -\DeclareStringOption{DestRect} -\DeclareStringOption{DestZoom} -\define@key{NEWPAX}{DestX}{% - \NEWPAX@defaultbp\NEWPAX@key@DestX{#1}% -} -\define@key{NEWPAX}{DestY}{% - \NEWPAX@defaultbp\NEWPAX@key@DestY{#1}% -} %% %% %% End of file `newpax.sty'. |