ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: "黄复雄 via ntg-context" <ntg-context@ntg.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: 黄复雄 <aahuaang@gmail.com>
Subject: Re: how to simulate \hss in luametatex?
Date: Fri, 11 Nov 2022 18:53:44 +0800	[thread overview]
Message-ID: <CAHN0TNj64av3m1uDP9MY+-SHFkh3cb34+JddPEkg8tUJy1iufw@mail.gmail.com> (raw)
In-Reply-To: <132865e0748c4e51a275bfba699b0b6a9b5a10d8.camel@telus.net>

Dear Max,
I am very grateful that you took the time to tweak and test my
non-running code snippet
and found the problem.

 > local box = node.hpack(hss + b, "exactly", 0)

You are absolutely right, the cause of the problem was that I wasn't
using node.hpack().
Actually, I tried to use it, but used it wrong, as follows:

local box, _ = node_hpack(list)
box.width = 0
box.shift = -tex_sp("1ex")

My app works fine now. Also, I learned a lot from your code, like
font.current(), hss + b
and tex.forcehmode() - I immediately used the last one to set
box.shift, making it relative.

Best regards

Huang Fusyong(黄复雄)

Max Chernoff via ntg-context <ntg-context@ntg.nl> 于2022年11月11日周五 17:55写道:
>
> Hi,
>
> > I want to  simulate \hss  in lua end in ConTeXt/luametatex environment.
> > For example,
> >
> > ```ConTeXt
> > a{\raise 1.5ex\hbox to 0pt{\hss b}}c
> > ```
>
> > And in lua, I do as follows(part of my app seen in attachment):
>
> Your code doesn't compile as is. I think that this is the same thing
> though:
>
>    \starttext
>    \startluacode
>    local a = node.new"glyph"
>    a.char = string.byte("a")
>    a.font = font.current()
>
>    local b = node.new"glyph"
>    b.char = string.byte("b")
>    b.font = font.current()
>
>    local c = node.new"glyph"
>    c.char = string.byte("c")
>    c.font = font.current()
>
>    local hss = node.new("glue")
>    hss.stretch = 65536
>    hss.stretchorder = 2
>    hss.shrink = 65536
>    hss.shrinkorder = 2
>    hss.width = 0
>    b = node.insertbefore(b, b, hss)
>
>    local box = node.new("hlist", "box")
>    box.head = b
>    box.width = 0
>    box.shift = -tex.sp("1ex")
>
>    tex.forcehmode()
>    node.write(a + box + c)
>    \stopluacode
>    \stoptext
>
> > And got 'b' on top of 'c' in pdf as follows:
> >
> > ```pdf
> >   b
> > ac
> > ```
>
> The \hss isn't the problem here. The problem is actually with the box.
> When you manually make the \hbox like that, I think (although I could be
> wrong) that you're bypassing all of TeX's glue calculations. You should
> probably use "node.hpack" instead:
>
>    \starttext
>    \startluacode
>    local a = node.new"glyph"
>    a.char = string.byte("a")
>    a.font = font.current()
>
>    local b = node.new"glyph"
>    b.char = string.byte("b")
>    b.font = font.current()
>
>    local c = node.new"glyph"
>    c.char = string.byte("c")
>    c.font = font.current()
>
>    local hss = node.new("glue")
>    hss.stretch = 65536
>    hss.stretchorder = 2
>    hss.shrink = 65536
>    hss.shrinkorder = 2
>    hss.width = 0
>
>    local box = node.hpack(hss + b, "exactly", 0)
>    box.shift = -tex.sp("1ex")
>
>    tex.forcehmode()
>    a.next = box
>    box.next = c
>    node.write(a)
>    \stopluacode
>    \stoptext
>
> -- Max
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : https://contextgarden.net
> ___________________________________________________________________________________
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

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

      parent reply	other threads:[~2022-11-11 10:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-11  2:37 黄复雄 via ntg-context
2022-11-11  9:53 ` Max Chernoff via ntg-context
2022-11-11 10:50   ` Hans Hagen via ntg-context
2022-11-11 11:00     ` 黄复雄 via ntg-context
2022-11-11 10:53   ` 黄复雄 via ntg-context [this message]

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=CAHN0TNj64av3m1uDP9MY+-SHFkh3cb34+JddPEkg8tUJy1iufw@mail.gmail.com \
    --to=ntg-context@ntg.nl \
    --cc=aahuaang@gmail.com \
    /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).