8000 Add \tl_retokenize:n by josephwright · Pull Request #1761 · latex3/latex3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add \tl_retokenize:n #1761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open

Add \tl_retokenize:n #1761

wants to merge 5 commits into from

Conversation

josephwright
Copy link
Member

No description provided.

@josephwright
Copy link
Member Author

Thoughts on the name welcome: I'm aiming for different-from-rescan as this is 'dynamic', but wasn't sure that was the best term. (Context: I need this for ltx-talk, really want it for documenting l3draw and more generally it 'goes withthe newc-type grabber in ltcmd`.)

@muzimuzhi
Copy link
Collaborator

\tl_rescan_dynamic:n or \tl_dynamic_rescan:n?

\group_begin:
\int_set:Nn \tex_newlinechar:D { 13 }
\exp_after:wN \group_end:
\tex_scantokens:D \exp_after:wN { \tl_to_str:n {#1} }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened to the \scantextokens idea? Should we try to add something that will (most likely) remove the trailing space? If not, the fact that if this is used in horizontal mode it'll have a trailing space in output should be documented!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a way to do the same as \scantextokens reliably in pdfTeX - ideas welcome

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly the same behaviour won't be possible (the grabbing additional arguments for instance). The space-suppression is possible, but only sort of unreliable. Provided the argument doesn't contain a NUL char (or any other arbitrary char), and doesn't change the category code of that character (the latter will be impossible to check, so we have to hope for the best here), you can put \char_set_catcode_comment:n { 0 } in the setup code and put a catcode 12 NUL char at the end of the \tex_scantokens:D argument.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or persuade someone (not me, I've given up on grasping WEB) to back port it...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked at a back-port - quite a bit of work and not a high priority.

@muzimuzhi
Copy link
Collaborator

Is \scantokens supported by LuaMetaTeX?

The LuaMetaTeX version of \tl_(g)set_rescan:Nnn says

in LuaMetaTeX there is no \scantokens so something different is needed.

but running the following ConTeXt example shows that \scantokens still exists in LuaMetaTeX 2.11.07.

\starttext
\show\scantokens
\stoptext
> \scantokens=global primitive \scantokens
...
mkxl run stats  > used engine: luametatex version: 2.11.07, functionality level: 20250609, format id: 720, compiler: clang
mkxl run stats  > tex properties: 938216 hash slots used of 2097152, 52562 control sequences, approximate memory usage: 113 MB
mkxl run stats  > lua properties: engine: lua 5.5, format 7, used memory: 57 MB, ctx: 54 MB, max: 81 MB, symbol mask: utf (τεχ)

@josephwright
Copy link
Member Author

I've updated to allow for \scantextokens.

@josephwright
8000 Copy link
Member Author

I guess I could ask Hans about \scantokens in LuaMetaTeX ...

@josephwright
Copy link
Member Author
Screenshot 2025-06-18 at 07 55 43

% Hans that LuaMeta\TeX{} will retain this primitive, so we should be
% OK for all engines.
% \begin{macrocode}
\cs_gset_protected:Npn \tl_rescan_dynamic:n #1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be new then.

Suggested change
\cs_gset_protected:Npn \tl_rescan_dynamic:n #1
\cs_set_protected:Npn \tl_rescan_dynamic:n #1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is deliberate - as we are wanting a global def (yes, i know we should be at top-level but if you look at new it works globally).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is deliberate - as we are wanting a global def (yes, i know we should be at top-level but if you look at new it works globally).

@muzimuzhi
Copy link
Collaborator

As \tl_rescan_dynamic:n is protected, do we also need \tl_(g)set_rescan_dynamic:Nn?

Copy link
@car222222 car222222 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some wording queries.

% régime. In contrast to \cs{tl_rescan:nn}, this function retokenizes
% the input \enquote{dynamically}: category code changes which occur
% whilst processing the retokenized material \emph{will} apply to later
% content. The \emph{tokens} are always treated as ending with a space.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it clear what is meant by this sentence?

@@ -2213,6 +2229,23 @@
% \end{macro}
% \end{macro}
%
% \begin{macro}{\tl_rescan_dynamic:n, \tl_rescan_dynamic:V}
% A thin wrapper from \tn{scantokens}. At present, we are told by

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from ==> for

@josephwright
Copy link
Member Author

As \tl_rescan_dynamic:n is protected, do we also need \tl_(g)set_rescan_dynamic:Nn?

No, the whole issue with \scantokens is that isn't really workable - a 'dynamic' interface which is only usable in typesetting contexts is necessary if a bit awkward. (It's this or I have to stick to a classical beamer-like write-and-read-back approach).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0