\insert
is a TeX primitive not a plain TeX command.
If you go
\insert\boxregister{
.... vertical mode material ...
}
then two things happen, the vertical mode material is saved away and an insert node is placed in the current list.
If the current list is a horizontal list in a paragraph the node "migrates" to the surrounding vertical list.
Any insert nodes that end up being inside a box are essentially lost.
Insert nodes that end up on the main vertical list affect the page breaker in several ways.
depending on \count\boxregister
and \skip\footins
the output routine leaves space for the inserts when chopping off the page.
Inside the output routine \box\boxregister
contains the contents of the insertion boxes u to a maximum of \dimen\boxregister
. Any additional inserts are held over on to the next page (and the last insert on the page may be split if it doesn't fit (and is splittable)
so in your example the output routine will be handed \box\paragraphednote
which will be a vbox with a sequence of hboxes. the output routine is responsible for adding (or not) those boxes to the page before it is shipped out, it could unbox the contents or process them in any way or it could decide not to make any inserts on the page being shipped out and re-insert them into the material returned to the main vertical list.
You probably need to add an actual runnable example showing any problem. The code you link to is rather long to take in by eye but as far as I can see the intention is that teh boxing is only temporary and the \removehboxes
macro is invoked to unbox and re-package the notes.
You say that \hbox
prevents line breaking but that does not appear to be the intention of the code.
The following example defines \embedvideo
. It uses the same media embedding method as the media9
LaTeX package. Video files in the MP4/H264 and FLV formats are played back within the video player component VPlayer.swf shipping with media9
.
See the media9 manual on how to configure VPlayer
via FlashVars, which are passed as the 3rd argument of \embedvideo
.
The video player can be controlled by left mouse button press (pause) and release (play/resume), via the context menu accessed by right mouse button click and via the keyboard (see context menu for keys).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \embedvideo{<width>}{<height>}{<flashvars>}{<video file (MP4+H264 or FLV)>}
% flashvars documented in `texdoc media9`, page 19
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\embedvideo#1#2#3#4{%
\ifdefined\vplayer\else%
\immediate\pdfobj stream file {VPlayer.swf}%
\immediate\pdfobj{<<
/Type/Filespec/F (VPlayer.swf)/UF (VPlayer.swf)
/EF <</F \the\pdflastobj\space 0 R>>
>>}%
\edef\vplayer{\the\pdflastobj}%
\fi%
%
\immediate\pdfobj stream file {#4}%
\immediate\pdfobj{<<
/Type/Filespec/F (#4)/UF (#4)
/EF <</F \the\pdflastobj\space 0 R>>
>>}%
\edef\video{\the\pdflastobj}%
%
\immediate\pdfobj{<<
/Type/RichMediaInstance/Subtype/Video
/Asset \vplayer\space 0 R
/Params <</Binding/Foreground/FlashVars (source=#4)>>
>>}%
%
\immediate\pdfobj{<<
/Type/RichMediaConfiguration/Subtype/Video
/Instances [\the\pdflastobj\space 0 R]
>>}%
%
\immediate\pdfobj{<<
/Type/RichMediaContent
/Assets <<
/Names [(VPlayer.swf) \vplayer\space 0 R (#4) \video\space 0 R]
>>
/Configurations [\the\pdflastobj\space 0 R]
>>}%
\edef\rmcontent{\the\pdflastobj}%
%
\pdfobj{<<
/Activation <<
/Condition/PO
/Presentation <<
/Transparent true
/Style/Embedded
/PassContextClick true
>>
>>
/Deactivation <</Condition/PC>>
>>}%
%
\setbox0=\vbox to #2 {\vss\hbox to #1{\tt #4\hss}\vss}%
\immediate\pdfxform 0%
%
\pdfannot width #1 height #2 depth 0pt {
/Subtype/RichMedia
/BS <</W 0/S/S>>
/Contents (embedded video file:#4)
/NM (rma:#4)
/AP <</N \the\pdflastxform\space 0 R>>
/RichMediaSettings \the\pdflastobj\space 0 R
/RichMediaContent \rmcontent\space 0 R
}%
\hbox to #1 {\vbox to #2 {}\hss}%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Plain\TeX{} video example:
top
left\embedvideo{4cm}{3cm}{autoPlay=true&loop=true}{random.mp4}right
bottom
\bye
To answer the follow-up question:
The lines \setbox0=...
and \immediate\pdfxform 0%
produce a poster text for the inactive video. The text (video file name) is put in a box and subsequently distilled into a so-called Form-XObject. The latter is bound to the RichMedia annotation using the /AP
entry. Without a poster text, AR displays an ugly box with a "?" inside if the video is inactive.
Best Answer
The reason is in the definition:
So
\bye
doesn't just issue\end
(that would by itself issue\par
, but not\vfill
): it also performs\supereject
, which isWhy a -20000 penalty? The reason is in the output routine:
If the penalty that triggers the output routine is greater than -20000, nothing special is done after advancing the page number. Otherwise
\dosupereject
comes into action:The macro ensures all pending insertions are shipped out, by repeated call of
\supereject
until\insertpenalties
is not positive any more.One can call
\supereject
at any time (which is the reason for\par
at the beginning), for instance when a chapter is beginning.Some more ideas from comments to the question and to the answer
TeX can be run interactively and it goes interactive if the main input file ends without an
\end
command (or makes an “Emergency stop” if the running mode is not interactive). Due to this possible interactivity, an implied\end
command would be undesirable.Only a few operating systems add an implied
<EOF>
marker at the end of a file, which could be^^D
(EOT) or^^Z
. The^^Z
character used to be added in MS-DOS files, but not all text editors were compliant.Depending on the operating system and the shell, hitting Control-D at the interactive prompt can stop the execution, but no
\end
command is executed.Since TeX keeps a stack of the
\input
files, it knows when it has reached the end of the main file, so a possible feature could be “insert the token\end
when you reach the end of the main file”. However, there should also be a “disable automatic\end
” feature to allow interaction at the end of the file. There is a similar feature in TeX: when switching from horizontal to vertical mode due to finding a<vertical command>
, TeX adds a\par
token (which could not be the primitive\par
any more). However, the situation for an “automatic\end
” is very different: breaking a paragraph into files is a common TeX activity, while the end of the main file just happen once.Having the terminating
\end
allows for adding structure to it. One could redefine\end
(after keeping a copy of the primitive) to do other bookkeeping business like\bye
does. Socould be thought of, but it was not Knuth's choice (and it wouldn't be mine as well).
Finally, having
\end
(or\bye
or\end{document}
) at the end of the main file allows for putting comments and additional material after the end marker, which wouldn't be possible otherwise. Since most programming languages require programs to be explicitly terminated, I don't see why TeX should be an exception.