3

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.

\documentclass{scrartcl}
\usepackage{luacode}
\begin{document}
    Note tilde is fine in luacode*.\\
    \begin{luacode*}
        token.set_macro('NAME','First~Last','global')
    \end{luacode*}
    \NAME
\end{document}
1
  • 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

4

This is possibly a luatex feature...

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



   \directlua{
        token.set_macro('NAME','First\string~Last','global')
}
\show    \NAME


\def\zz#1{\show#1\ifx!#1\else\expandafter\zz\fi}

\expandafter\zz\NAME!

\bye

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

> \NAME=macro:
->First~1Last.
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.

2

You must log in to answer this question.

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