I am setting a macro in lualatex, and would like to use ~ as a non-breaking space character. However, it produces a new line between first and last.

    Note tilde is fine in luacode*.\\
  • 1
    This is not supported by token.set_macro. Just use something along the lines of tex.sprint("\\gdef\\NAME{First~Last}"). Oct 12, 2021 at 16:48

1 Answer 1


This is possibly a luatex feature...

If I use plain text and \directlua primitive to avoid any interference from macro packages then

\show    \NAME




where the \show\NAME shows ~1 instead of just ~ where the ~1 produces a line break.

> \NAME=macro:
l.6 \show    \NAME

The loop then shows each token and you get:

> the letter F.
> the letter i.
> the letter r.
> the letter s.
> the letter t.
> [unknown command code! (13, -1113986)].
> the letter L.
> the letter a.
> the letter s.
> the letter t.

So basically the token library hasn't wanted to add the active character.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .