Difference between revisions of "TeX Boxes"

From Wiki
Jump to navigation Jump to search
(New page on TeX boxes)
 
m
Line 1: Line 1:
 
Boxes are the basis of all (low level) TeX typesetting. As the building blocks they store typeset parts of lines, paragraphs or pages. For storing material not being typeset yet, like input text for later use, use [[Buffers_in_LuaTeX|Buffers]].
 
Boxes are the basis of all (low level) TeX typesetting. As the building blocks they store typeset parts of lines, paragraphs or pages. For storing material not being typeset yet, like input text for later use, use [[Buffers_in_LuaTeX|Buffers]].
  
The introduction to LuaTeX boxes can be found in  [https://www.overleaf.com/learn/latex/Articles/Pandora%E2%80%99s_%5Chbox:_Using_LuaTeX_to_Lift_the_Lid_of_TeX_Boxes|Pandora’s \hbox: Using LuaTeX to Lift the Lid of TeX Boxes].
+
The introduction to LuaTeX boxes can be found in  [https://www.overleaf.com/learn/latex/Articles/Pandora%E2%80%99s_%5Chbox:_Using_LuaTeX_to_Lift_the_Lid_of_TeX_Boxes | Pandora’s \hbox: Using LuaTeX to Lift the Lid of TeX Boxes].
  
 
LuaMetaTeX boxes serve the same purpose, but their properties are changed and extended. For the details see [http://distribution.contextgarden.net/current/context/latest/doc/context/documents/general/manuals/lowlevel-boxes.pdf Low Level TeX: Boxes] manual.
 
LuaMetaTeX boxes serve the same purpose, but their properties are changed and extended. For the details see [http://distribution.contextgarden.net/current/context/latest/doc/context/documents/general/manuals/lowlevel-boxes.pdf Low Level TeX: Boxes] manual.

Revision as of 20:01, 16 February 2021

Boxes are the basis of all (low level) TeX typesetting. As the building blocks they store typeset parts of lines, paragraphs or pages. For storing material not being typeset yet, like input text for later use, use Buffers.

The introduction to LuaTeX boxes can be found in | Pandora’s \hbox: Using LuaTeX to Lift the Lid of TeX Boxes.

LuaMetaTeX boxes serve the same purpose, but their properties are changed and extended. For the details see Low Level TeX: Boxes manual.

Cached Boxes (LMTX)

Box has to be typeset with TeX. Usually the user is on the TeX side, where box is typeset, stored and can be used later. However, combining TeX with Lua demands some extra work. While being on the Lua side to typeset and store the box you must finish the Lua block jump to TeX and typeset boxes. Thus setting the boxes on Lua side will be forgotten and boxes will not exist after finishing the Lua block. To let TeX do something from within Lua there is a Lua Steps mechanism described in CLD Manual, but in LMTX we also have mechanism for cached boxes.

List of the commands to work with cached boxes:

\putboxincache          {category} {name} number
\getboxfromcache        {category} {name} number
\doifelseboxincache     {category} {name}
\copyboxfromcache       {category} {name} number
\directboxfromcache     {category} {name}
\directcopyboxfromcache {category} {name}
\resetboxesincache      {category}
\putnextboxincache      {category} {name} box
\getboxwdfromcache      {category} {name}
\getboxhtfromcache      {category} {name}
\getboxdpfromcache      {category} {name}

All these commands can be used on Lua side with the usual syntax context.<command>(<params>)


Boxed are stored in user defined categories (namespaces) and every box has its name inside its category.

If the boxes are not cached for the subsequent runs, one needs to clear the category cache at the beginning of the document.

\resetboxesincache{category}

One defines and typesets the box as usual:

\setbox0=\hbox{\framed[width=50mm,
                      background=color,
                      backgroundcolor=gray,
                      frame=off,
                      align={flushleft}]{framed text}}

To cache that box the user can use either

\putboxincache ... [to test]

or

\putnextboxincache{category}{name}\box0

and the box can be retrieved any time later (or even in subsequent runs) with

\getboxfromcache{category}{name}% analogy to \box0, box will be forgotten

or

\copyboxfromcache{category}{name}% analogy to \copy0, box will persist

One can trace the creation of cached boxes with

\enabletrackers[nodes.boxes]