I'm afraid this doesn't do the trick: \c_syst_last_allocated_box is definitely incremented.

Let me try explaining again. This is essentially what I do:

{
  \newbox\TempBox
  \setbox\TempBox\hbox{Box One}
  \let\BoxOne\TempBox
  \global\let\TempBox\relax

  \newbox\TempBox
  \setbox\TempBox\hbox{Box Two}
  \let\BoxTwo\TempBox
  \global\let\TempBox\relax

  \the\numexpr\BoxOne: [\box\BoxOne]
  \the\numexpr\BoxTwo: [\box\BoxTwo]
}

But I want the number of available box registers at entering and exiting the group to be the same, and substituting \newbox for \locbox is what does the trick in my package. So I can run the following a million times:

{
  \newlocalbox\TempBox
  \setbox\TempBox\hbox{Box One}
  \let\BoxOne\TempBox
  \global\let\TempBox\relax

  \newlocalbox\TempBox
  \setbox\TempBox\hbox{Box Two}
  \let\BoxTwo\TempBox
  \global\let\TempBox\relax

  \the\numexpr\BoxOne: [\box\BoxOne]
  \the\numexpr\BoxTwo: [\box\BoxTwo]
}

Each of the million "\the\numexpr\BoxOne" should produce the same number, whereas in the \newbox-based example these numbers increment.

Best,
Sašo

On 24. 01. 2017 09:52, Hans Hagen wrote:
You are asking how to define a macro, \locbox, such that the following
code should not change the value of \c_syst_last_allocated_box.

\bgroup
\locbox\BoxOne
\locbox\BoxTwo

\BoxOne\hbox{Box One}
\BoxTow\hbox{Box Two}
% Do some measurement based on the size of the boxes
\egroup

The fact that a LaTeX package implements this behaviour by allocating
local box numbers from the end seems to be an implementation detail.

I don't know the best way to implement such a macro in ConTeXt, but I
want to make sure that the user-level behavior that you want is properly
understood. Given the details in your question, one can easily lose the
forest for the trees (pun intended :-)

\unprotect

\installcorenamespace{localbox}

\unexpanded\def\newlocalbox#1%
  {\expandafter\let\expandafter#1\csname\??localbox\string#1\endcsname
   \ifx#1\relax
     \syst_aux_new_localbox#1%
   \fi}

\def\syst_aux_new_localbox#1%
  {\expandafter\newbox\csname\??localbox\string#1\endcsname
   \newlocalbox#1}

\protect

\starttext

\newlocalbox\BoxOne
\newlocalbox\BoxTwo

\setbox\BoxOne\hbox{Box One}
\setbox\BoxTwo\hbox{Box Two}

[\box\BoxTwo]
[\box\BoxOne]

\let\locbox\newlocalbox

\stoptext

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
_______________________________________________
dev-context mailing list
dev-context@ntg.nl
https://mailman.ntg.nl/mailman/listinfo/dev-context

_______________________________________________
dev-context mailing list
dev-context@ntg.nl
https://mailman.ntg.nl/mailman/listinfo/dev-context

Reply via email to