TransWikia.com

storebox not working as expected since texlive 2020

TeX - LaTeX Asked by moepi on January 24, 2021

I have to include page-specific content multiple times per page (DM codes to be specific) in a LaTeX document. To that end I use a combination of storebox and everypage such that content is typeset once and referenced multiple times in the resulting PDF:

documentclass[a4paper]{article}
 
usepackage[pagestyles,extramarks]{titlesec}
usepackage{everypage}
usepackage{storebox}
AtBeginDocument{{}} % due to https://tex.stackexchange.com/a/141540

newpagestyle{mypagestyle}{%
    sethead[%
    ][%
        usestorebox{mybox}%
    ][%
    ]{%
    }{%
        usestorebox{mybox}%
    }{%
    }%
    setfoot[%
    ][%
        usestorebox{mybox}%
    ][%
    ]{%
    }{%
        usestorebox{mybox}%
    }{%
    }%
}

pagestyle{mypagestyle}

AddEverypageHook{storebox{mybox}{some page-specific stuff repeated multiple times on that page}}

begin{document}

Page 1

clearpage

Page 2

end{document}

This works fine for any version prior to 2020. However, texlive 2020 introduced native hooks, making the everypage package obsolete. Since that version, the approach above results in:

! Undefined control sequence.
<argument> pdfrefxform mybox

Using the new hooks directly, i.e., AddToHook{shipout/before}{stuff}, gives the same error. Using xsavebox instead of storebox would work fine, but xsavebox is way slower such that it is not an alternative.

Does anyone has an idea how to make storebox work with texlive 2020?

One Answer

The following allows to store a new box on every page and to reuse it on various place in the footer or header. The pdf contains two xobjects, one for every page. Something similar is probably possible with titlesec but I don't know the package very well.

The patch of the internal storebox command is needed as it doesn't store the reference to the xform global. This and the AtBeginDocument bug should be reported to the author.

documentclass{article}
usepackage{fancyhdr}
usepackage{storebox}
makeatletter
%make command global
def@storebox#1{%
    begingroup
    @collectboxtocollectedbox{%
        storebox@immediatepdfxform resources {thepdfpageresources}collectedbox
        endgroupglobalmathchardef#1=pdflastxform
    }%
}
makeatother
pagestyle{fancy}
fancyhf{}
newcommandmybox{} %allocate the name to avoid to overwrite an existing command.
lhead{storebox{mybox}{some page-specific stuff repeated multiple times on that pagethepage/leftmark}%
       usestorebox{mybox}}
rfoot{usestorebox{mybox}}


begin{document}
section{abc}
Page 1

clearpage
section{cde}
Page 2

end{document}

Answered by Ulrike Fischer on January 24, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP