निरंजन
I want to remember where a coffin was placed. The basic objective is to achieve something similar to `\coffin_join:NnnNnnnn`, but without actually using it. I have different reasons for not using `join` or `attach`. I want to be able to say `\coffin_typeset:Nnnnn \l_tmpa_coffin` first, then say `\coffin_typeset:Nnnnn \l_tmpb_coffin` and join the latter's top left to the the bottom right of the former. In TikZ, there is `remember picture`. How to get that with L3? No packages please. Just kernel tools.
```
\documentclass{article}
\begin{document}
\ExplSyntaxOn
\hcoffin_set:Nn \l_tmpa_coffin { abcd }
\hcoffin_set:Nn \l_tmpb_coffin { efgh }
\coffin_join:NnnNnnnn \l_tmpa_coffin { r } { b }
\l_tmpb_coffin { l } { t }
{ 0ex } { 0ex }
\coffin_typeset:Nnnnn \l_tmpa_coffin { l } { t }
{ 0ex } { 0ex }
\ExplSyntaxOff
\end{document}
```
Top Answer
Skillmon
I don't know whether there's a nicer interface to this, but there is the newish (introduced in 2023-11-01) `\RecordProperties` mechanism to store the current position on the page.
```
\documentclass{article}
\usepackage{iftex}
\ifLuaTeX
\let\mysavepos\savepos
\let\mypagewidth\pagewidth
\let\mypageheight\pageheight
\else
\let\mysavepos\pdfsavepos
\let\mypagewidth\pdfpagewidth
\let\mypageheight\pdfpageheight
\fi
\makeatletter
\NewDocumentCommand\storepos { m O{} }
{%
% #1: label name (same name space as `\label`s)
% #2: additional properties to store (see `clsguide.pdf` subsection 5.6)
\@bsphack
\mysavepos
\RecordProperties{#1}{xpos,ypos,#2}%
\@esphack
}
\makeatother
\newcommand\pmoverlay[1]% poor man's overlay
{\smash{\rlap{#1}}}
\begin{document}
\ExplSyntaxOn
\hcoffin_set:Nn \l_tmpa_coffin { abcd }
\hcoffin_set:Nn \l_tmpb_coffin { efgh }
\coffin_join:NnnNnnnn \l_tmpa_coffin { r } { b }
\l_tmpb_coffin { l } { t }
{ 0ex } { 0ex }
\coffin_typeset:Nnnnn \l_tmpa_coffin { l } { t }
{ 0ex } { 0ex }
\ExplSyntaxOff
\clearpage
\ExplSyntaxOn
\hcoffin_set:Nn \l_tmpa_coffin { abcd \storepos{myposition} }
\hcoffin_set:Nn \l_tmpb_coffin { efgh }
\coffin_typeset:Nnnnn \l_tmpa_coffin { l } { t } { 0ex } { 0ex }
\AddToHookNext{shipout/background} % this is like an `overlay` tikzpicture
{
\put
(
% retrieve the stored position. On first run it'll appear in the bottom
% left corner
\RefProperty{myposition}{xpos}sp,
\RefProperty{myposition}{ypos}sp-\mypageheight
)
{
% positioning done via the `\put` mechanism, so no offsets here.
\coffin_typeset:Nnnnn \l_tmpb_coffin { l } { t } { 0ex } { 0ex }
}
}
\ExplSyntaxOff
\clearpage
\ExplSyntaxOn
\hcoffin_set:Nn \l_tmpa_coffin { abcd \storepos{mypos1} }
\hcoffin_set:Nn \l_tmpb_coffin { efgh }
\coffin_typeset:Nnnnn \l_tmpa_coffin { l } { t } { 0ex } { 0ex }
\par
Some~ more~ text.
\storepos{mypos2}\pmoverlay{%
\coffin_typeset:Nnnnn \l_tmpb_coffin { l } { t }
{ \RefProperty{mypos1}{xpos} sp - \RefProperty{mypos2}{xpos} sp }
{ \RefProperty{mypos1}{ypos} sp - \RefProperty{mypos2}{ypos} sp }
}
\ExplSyntaxOff
\end{document}
```