On 1/23/2017 9:26 AM, Aditya Mahajan wrote:
On Tue, 27 Dec 2016, Sašo Živanović wrote:

I'm the author of a PGF/TikZ-based LaTeX package Forest for drawing
(linguistic) trees. I have received several requests to support
ConTexT and I'm trying to do that now.

Thank you for trying to port your code to ConTeXt. Although I don't
foresee that I will use the forest package, I do use pgfplots quite a
lot and appreciate the extra effort put in by the package authors to
support two different macro packages.

Forest uses a lot of \boxes. Actually, the number of boxes used cannot
be known in advance, as it depends on the document. Here's why:
Forest's main job is to place the nodes of a tree so that they don't
overlap and to do that, it needs to first typeset the individual nodes
and measure them. The typeset nodes are kept around and later used
when typesetting the entire tree.

I don't have an answer to your questions, but I am replying partly to
bump this thread again.

The typeset nodes are kept in "local" boxes. They are created using
\locbox, which is defined either by plain eTeX format or package
elocalloc.sty for LaTeX >2015. (Prior to LaTeX 2015, \locbox was
defined in etex.sty.) elocalloc.sty's \locbox is somewhat broken, but
still works, mainly because it seems no other package is using local
allocation. ;-)

Let me see if I understand this correctly.

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

Reply via email to