In short, yes. Try
\edef\foo{\scantokens{Test\noexpand}}
or
\everyeof={\noexpand}
\edef\foo{\scantokens{text}}
in which the \noexpand
‘hides’ the EOF marker by turning it into \relax
.
You might like to take a look at the definition of expl3's \tl_rescan:nn
and \tl_set_rescan:Nnn
, both wrappers for \scantokens
based on the ideas in Heiko Oberdiek's catchfile
package.
Then you can write
\tl_set_rescan:Nnn \foo { «catcode setup» } { «rescanned tokens» }
or
\tl_rescan:nn { «catcode setup» } { «tokens to re-scan (in a group)» }
The latter cannot be used inside an \edef
but can otherwise come in handy when you're processing a macro argument that has already been tokenised. In practise I find the set_rescan
version a little more convenient.
What's happening in your sample code is that first, you create a box of 10mm width having some glue at both ends and a letter in the middle. The glue is set, within the box, so that the whole space is filled. Then you unbox it. The contents are emptied into the main horizontal list, and the glue is reset in that context. The error you are getting is
! Infinite glue shrinkage found in a paragraph.
which comes about when TeX starts trying to reset the infinitely-shrinkable \hss
(this despite the fact that it only needs to expand, and you can see in the output that the letter a is indeed centered on its line).
The situation with your new example is exactly the same. If you place a whole box into a paragraph, then regardless of the glue in it, there will be no infinite shrinkage because the glue is already set in the box. If you unbox it, then the glue loses its dimensions and has to be reset, and its infinite shrink component gives an error.
Perhaps it is best to think of the situation as follows. Let .
denote glue and let -
denote set glue; i.e. actual space. I'll write an actual box with bars |
. Then you have the following correspondence:
\hbox to 10cm {\hss a\hss} ---> \hbox to 10cm {.a.} ---> |---a---|
First the \hbox
examines the horizontal list inside, which includes glue, and sets the length of that glue so that it fills the box, resulting in the last picture. Suppose that's the box stored in \box0
. Then your example is:
\unhbox0 ---> \unhbox |---a---| ---> .a. ---> -----------a------------
You see, when the bars are removed, the -
's revert to .
's and have to be reinterpreted, leading to some different lengths, as shown at right. The problem is that even though those lengths are stretched, the glue itself has an infinite shrink component, and this is not allowed in a computation outside an \hbox
.
Best Answer
\everypar
is a token list register, so its value is assigned byIts default value in Plain TeX is empty.
What's for? Its contents is delivered into the token list TeX is reading when it switches from vertical to horizontal mode. This happens when TeX, in vertical mode, sees a horizontal command, for instance a character to be typeset or
\indent
or\noindent
.At that time the horizontal command is set aside; before examining it again, TeX contributes
\parskip
glue to the vertical list and goes into horizontal mode; now it delivers the contents of\everypar
as if\the\everypar
was implicit and reexamines the horizontal command that forced the switch to horizontal mode. However the switching to horizontal mode caused by a horizontal command other than\noindent
causes TeX to insert an empty box of width\parindent
before the contents of\everypar
.One can use
\everypar
to perform automatically some job at paragraph start, for example to number them.LaTeX exploits heavily this mechanism, so it's not recommended to play with it when the job involves lists. An example is the declaration
that is in force until
\begin{document}
is processed;\@nodocument
issues the error messageMissing \begin{document}
in order to warn the user that text starting a paragraph has been found in the preamble.As all token registers, its value can be augmented by
since
\the\everypar
will deliver the current register's contents.