From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/107450 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Rik Kabel Newsgroups: gmane.comp.tex.context Subject: Re: Getting width of text to be typeset Date: Fri, 22 May 2020 19:49:34 -0400 Message-ID: <357d26e1-2571-b30c-2eb6-c787ed3bbf18@rik.users.panix.com> References: <1217e4fe7a813a0e714d342b9efec0c4@vivaldi.net> <639ff2c9-65f6-b818-1d8f-9249331a9b8a@xs4all.nl> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0206756930610573056==" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="63619"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Firefox/68.0 Thunderbird/68.8.0 To: ntg-context@ntg.nl Original-X-From: ntg-context-bounces@ntg.nl Sat May 23 01:50:01 2020 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jcHQP-000GQZ-5z for gctc-ntg-context-518@m.gmane-mx.org; Sat, 23 May 2020 01:50:01 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id BA00B184422; Sat, 23 May 2020 01:49:42 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4DspAa41ELHo; Sat, 23 May 2020 01:49:40 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 6877B184428; Sat, 23 May 2020 01:49:40 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id C8E901843FC for ; Sat, 23 May 2020 01:49:38 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TgzPnNJby3qU for ; Sat, 23 May 2020 01:49:37 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=166.84.1.89; helo=mailbackend.panix.com; envelope-from=context@rik.users.panix.com; receiver= Original-Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 4A2B9183EC0 for ; Sat, 23 May 2020 01:49:37 +0200 (CEST) Original-Received: from [192.168.201.21] (cpe-72-228-11-252.nycap.res.rr.com [72.228.11.252]) by mailbackend.panix.com (Postfix) with ESMTPSA id 49TNWM2k1JzsXs for ; Fri, 22 May 2020 19:49:35 -0400 (EDT) In-Reply-To: <639ff2c9-65f6-b818-1d8f-9249331a9b8a@xs4all.nl> Content-Language: en-US X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:107450 Archived-At: This is a multi-part message in MIME format. --===============0206756930610573056== Content-Type: multipart/alternative; boundary="------------B81E20CA6A18F246D3D50780" Content-Language: en-US This is a multi-part message in MIME format. --------------B81E20CA6A18F246D3D50780 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 5/22/2020 18:18, Hans Hagen wrote: > On 5/23/2020 12:03 AM, Hans Hagen wrote: >> On 5/22/2020 11:22 AM, context@vivaldi.net wrote: >>> Hello, >>> >>> is it possible to get somehow the width of the "material" (box?) of >>> the current line which is "ready" to be typeset? >>> >>> See the case: >>> >>> ---- >>> \starttext >>> >>>    some text >>> >>>    pqrs % Here I need to get width (or content) of the text from the >>> begin of the current line, >>>         % i.e. width of the text "pqrs". >>>         % (Depending of the width I will decide what to do later.) >>> >>> \stoptext >>> ---- >>> >>> I am too laical to know how to "inject" TeX workflow or whether to >>> access LuaTeX internals (nodes?) to get the desired information. >>> >>> - Is it possible somehow? >> Too easy ... >> >> \startluacode >>      function document.whatever() >>          context(nodes.hpack(tex.getnest().head.next).width) >>      end >> \stopluacode >> >> \unexpanded\def\widthuptohere{\dimexpr\ctxlua{document.whatever()}sp\relax} >> >> >> \starttext >> >>      \dorecurse {10} { >>          snippet #1\scratchdimen\widthuptohere\ has >> \the\scratchdimen\ width\par >>      } >> >> \stoptext >> >> but still you have to wikify it ... maybe i'll make it a low level >> helper (but than you also need to wikify that because i have no clue >> where to explain it) > Actually, one needs to flush a bit > > \startluacode >     function document.whatever() >         local h = nodes.hpack(tex.getnest().head.next) >         local w = h.width >         h.list = nil >         nodes.free(h) >         context(w) >     end > \stopluacode > > \unexpanded\def\widthuptohere{\dimexpr\ctxlua{document.whatever()}sp\relax} > > > \starttext > >     \dorecurse {10} { >         snippet #1\scratchdimen\widthuptohere\ has \the\scratchdimen\ > width\par >     } > > \stoptext > > not that it matters much, because it's unlikely that you leak more > than a dozen nodes in a run. > > Hans > If the OP simply wants the width of a string, one can use \setwidthof#1\to#2. \define\String{pqrs} \setwidthof{\String}\to\Wdth \String\ is \Wdth\ wide. \setwidthof{{\tfb\em\String}}\to\Wdth {\tfb\em\String} is \Wdth\ wide. I do not know if that is different from the width of the same string unboxed from the paragraph. There may be some adjustments made in justification, expansion, and such that are not treated. -- Rik --------------B81E20CA6A18F246D3D50780 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit


On 5/22/2020 18:18, Hans Hagen wrote:
On 5/23/2020 12:03 AM, Hans Hagen wrote:
On 5/22/2020 11:22 AM, context@vivaldi.net wrote:
Hello,

is it possible to get somehow the width of the "material" (box?) of the current line which is "ready" to be typeset?

See the case:

----
\starttext

   some text

   pqrs % Here I need to get width (or content) of the text from the begin of the current line,
        % i.e. width of the text "pqrs".
        % (Depending of the width I will decide what to do later.)

\stoptext
----

I am too laical to know how to "inject" TeX workflow or whether to access LuaTeX internals (nodes?) to get the desired information.

- Is it possible somehow?
Too easy ...

\startluacode
     function document.whatever()
         context(nodes.hpack(tex.getnest().head.next).width)
     end
\stopluacode

\unexpanded\def\widthuptohere{\dimexpr\ctxlua{document.whatever()}sp\relax}

\starttext

     \dorecurse {10} {
         snippet #1\scratchdimen\widthuptohere\ has \the\scratchdimen\ width\par
     }

\stoptext

but still you have to wikify it ... maybe i'll make it a low level helper (but than you also need to wikify that because i have no clue where to explain it)
Actually, one needs to flush a bit

\startluacode
    function document.whatever()
        local h = nodes.hpack(tex.getnest().head.next)
        local w = h.width
        h.list = nil
        nodes.free(h)
        context(w)
    end
\stopluacode

\unexpanded\def\widthuptohere{\dimexpr\ctxlua{document.whatever()}sp\relax}

\starttext

    \dorecurse {10} {
        snippet #1\scratchdimen\widthuptohere\ has \the\scratchdimen\ width\par
    }

\stoptext

not that it matters much, because it's unlikely that you leak more than a dozen nodes in a run.

Hans

If the OP simply wants the width of a string, one can use \setwidthof#1\to#2.

\define\String{pqrs}
\setwidthof{\String}\to\Wdth
\String\ is \Wdth\ wide.

\setwidthof{{\tfb\em\String}}\to\Wdth
{\tfb\em\String} is \Wdth\ wide.

I do not know if that is different from the width of the same string unboxed from the paragraph. There may be some adjustments made in justification, expansion, and such that are not treated.

--
Rik

--------------B81E20CA6A18F246D3D50780-- --===============0206756930610573056== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============0206756930610573056==--