ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Jano Kula <jano.kula@gmail.com>
To: Hans Hagen <j.hagen@xs4all.nl>
Cc: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Setting and measuring boxes TeX/Lua
Date: Fri, 27 Nov 2020 17:47:07 +0100	[thread overview]
Message-ID: <CAPefzZ25tRrNQubBmoT=cYu393GS5AabtbJhfMUsQrN5UR=Mow@mail.gmail.com> (raw)
In-Reply-To: <d1a69d4f-9a85-a196-4c70-dc7ae267540b@xs4all.nl>


[-- Attachment #1.1: Type: text/plain, Size: 2836 bytes --]

Hello again, Hans!

On Thu, 26 Nov 2020 at 09:18, Hans Hagen <j.hagen@xs4all.nl> wrote:

> (this mechanism is already kind of old, there are also other cheats
> possible)
>

Diving into functions and using context.stepwise() worked, until I've got
to: /cldf-stp.lua:48: bad argument #1 to 'resume' (thread expected) and
other errors. It was triar/error approach, not exactly knowing how
context.stepwise() works, and I was some more lua functions and iterations
before needing expansion.

Therefore I've changed the strategy (cannot give up):

   - Create named buffers with formatted content (and store measures)
   before they are needed.
   - When needed, use the reference to the buffer.

Tests looked promising. After \starttext buffers and measures are known
(both TeX & Lua). Also tested in functions, etc.
But inside the first \xmlsetup, they are not expanded anymore, they are
typeset (like \typebuffer).

   - How to have them expanded in \xmlsetup?
   - Is other mechanism better suited for storing typeset blocks than
   buffers (and will survive \xmlsetup)?
   - If none of them is possible, what are the *other **cheats *then?

Thanks,
Jano

MWE attached

% BUFFERS
\startluacode
-- fill buffers
for i=1,1000 do
    local content = "framed-" .. i
    context.startbuffer( { i } )
    context.StartBox()
    context.bold(i)context.par()
    context.color( { "red" }, content )
    context.StopBox()
    context.copy(false,0)
    context.stopbuffer()
    print(">>", i)
end
\stopluacode

\def\StartBox{\setbox0=\hbox\bgroup\framed[width=50mm,
                                           background=color,
                                           backgroundcolor=gray,
                                           frame=off,align={flushleft}]%
                                           \bgroup%
                                                \vbox\bgroup}
\def\StopBox{\egroup\egroup\egroup}% close vbox, framed, hbox

\def\MeasureBuffer[#1]{\setbox0\hbox{\getbuffer[#1]}%
                       ht: \the\ht0\par}


% XML
\startbuffer[doc]
<?xml version "1.0"?>
<document>
    <section>section</section>
    <section>section</section>
</document>
\stopbuffer

\startxmlsetups xml:name
    \xmlsetsetup{\xmldocument}{*}{-}
    \xmlsetsetup{\xmldocument}{document}{xml:name:*}
\stopxmlsetups

\xmlregistersetup{xml:name}

\startxmlsetups xml:name:document
    \Title{inside xml:name:document}
    \Title{TeX}
    \MeasureBuffer[333]
    \getbuffer[333]
    \Title{Lua}
    \startluacode
    context.MeasureBuffer({"444"})
    context.getbuffer({"444"})
    \stopluacode
\stopxmlsetups

\def\Title#1{\blank{\bf #1}\par}


\starttext

\Title{TeX}
\MeasureBuffer[111]
\getbuffer[111]

\Title{Lua}
\startluacode
context.MeasureBuffer({"222"})
context.getbuffer({"222"})
\stopluacode

\xmlprocessbuffer{xml:name}{doc}{}

\stoptext

[-- Attachment #1.2: Type: text/html, Size: 4327 bytes --]

[-- Attachment #2: xml-buffers.tex --]
[-- Type: application/x-tex, Size: 1740 bytes --]

[-- Attachment #3: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2020-11-27 16:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-25 18:31 Jano Kula
2020-11-25 20:25 ` Hans Hagen
2020-11-25 21:28   ` Jano Kula
2020-11-26  8:18     ` Hans Hagen
2020-11-27 16:47       ` Jano Kula [this message]
2020-11-27 18:05         ` Hans Hagen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPefzZ25tRrNQubBmoT=cYu393GS5AabtbJhfMUsQrN5UR=Mow@mail.gmail.com' \
    --to=jano.kula@gmail.com \
    --cc=j.hagen@xs4all.nl \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).