add tag
user202729
In the newest version of PDFTeX, it looks like the behavior of the `\endwrite` token was changed somehow that the [method](https://tex.stackexchange.com/questions/609423/accessing-texs-internal-tokens) to access the token no longer work.

With some experiment:

```
\catcode`\  9
\endlinechar 32
\def \weird {    aaa \expandafter \weirda \expandafter { \iffalse } \fi }
\def \weirda #1  {  \expandafter \meaning  \noexpand }
\immediate\write-1{\weird}
bcdef
```
(run with `tex`, not `pdftex`, it segmentation fault in the latter as if `\meaning` is applied to unsafe `\endwrite` before the patch) -- looks like the meaning remains `\outer macro:`, but now `\noexpand` no longer "works" with `\endwrite` token -- normally `\meaning <safe \endwrite>` would result in `\relax`.

Question: is there any way to create the `\endwrite` token in TeX/PDFTeX outside of `\write` context?

I don't see any obvious way because it's not possible to duplicate the `\endwrite` token, and section 1372 of TeX source code:

![image.png](/image?hash=a634c33e3253b7768672d3d05d0088fabf4d42ccd548710c75e72c7fd8b14773)

tokens will be unconditionally gobbled until `\endwrite` itself is seen.
Top Answer
user202729
Answering my own question: I suspect the answer is no.

As mentioned in a comment, the patch being applied is exactly that `\noexpand\endwrite` will not result in the safe `\endwrite` anymore.

An `end write token` will only be inserted when `write` starts, and it will be removed later (the only way I can think of to interrupt the `get token` loop is to use invalid (cat 15) characters, and that doesn't allow breaking out of the loop either). With `\noexpand` gone there's very little things that can be done with `\endwrite` -- in particular it doesn't look possible to duplicate it, the error recovery on encountering a forbidden token while scanning argument seems to just terminate the argument scanning (around paragraph 392 but I haven't read carefully).


Anyway, looking through occurrences of `scanner status ← normal`, the only occurrences within expandable primitives I can find are `\ifx`, `\noexpand`, `\string`, `\meaning`. `\noexpand` is now useless and the other 3 just throw away the token.

I manage to segmentation fault `tex` again by doing `\ifx\endwrite\a` (not particularly useful however):

```tex
\outer\def\a{}
\def\weird{\expandafter\weirda\string}
\def\weirda#1{\ifx}
\immediate\write-1{\weird}\a
```

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.