1

If you already know what sticky and non-sticky commands are, skip down to the header REAL QUESTION

A sticky command remains in effect until you explicitly turn it off.
For example, $ to enter math mode is sticky. Math mode will stay on for almost all future characters until something like another $ is encountered. Also, \it is a sticky command.

\it oh mY GOURD! THE ENTIRE REMAINDER OF THIS DOCUMENT IS IN ITALICS!

The scope of sticky command can be limited by one of the following methods:

  • by putting an end-delimiter where you want the effect to stop

    not-italic \it ITALIC ITALIC \em not-italic, not-italic
    
  • by only executing the sticky command in very small contained environment

    not-italic {\it ITALIC ITALIC} not-italic, not-italic
    

A non-sticky command affects only the next item on the input stream, and then turns itself off automatically. Either the input is its own end-delimiter, you you never give the non-sticky command the whole stream in the first place. _ in math-mode is almost a sticky-command, but not quite. If '_' was sticky, then following two lines of code would have the same effect:

    $thing_s_u_b_s_c_r_i_p_t$
    $thing_{subscript}$

math-mode '_' is sticky in the sense that the following only makes teh first letter of subscript be subscripted:

    $thing_subscript$

For non-sticky commands, if you want the next several inputs to all be affected, you have to do one of the following:

  • use the non-sticky command repeatedly

    CMD input CMD input CMD input CMD input [...]
    
  • lump together the many inputs into a single input and give the single input to the non-sticky command. CMD {input input input input}

  • use a different command

REAL QUESTION

When we use \nolinebreak, how long does it last? Next character only? Up until the next white-space character? Up until ... when exactly? Does \nolinebreak affect the previous characters? (characters to the left of the command or above the command?)

I suppose it might depend on how \nolinebreak is used. Pick any one or more of the following examples,

HAM HAM  \nolinebreak STEAK STEAK 

ORANGE ORANGE  \nolinebreak{STRAWBERRY STRAWBERRY } KIWI KIWI

AZALEA AZALEA AZALEA AZALEA AZALEA AZALEA 
\begin{nolinebreak}
    CHRYSANTHEMUM CHRYSANTHEMUM 
\end{nolinebreak}
IdleCustard
  • 1,194

1 Answers1

4

\nolinebreak does not "last" at all. You clearly have some mental model of how TeX is working that is not at all like it works. \nolinebreak adds a penalty node into the current horizontal list in exactly the same way as x adds a character node into the current horizontal list.

Try the complete document

\documentclass{article}

\begin{document}

\showoutput

 x\nolinebreak[1]y\nolinebreak[2]z

\end{document}

you will see in the log the 5 nodes

....\OT1/cmr/m/n/10 x
....\penalty 51
....\OT1/cmr/m/n/10 y
....\penalty 151
....\OT1/cmr/m/n/10 z

corresponding to the input.

David Carlisle
  • 757,742
  • maybe one should add that the "environment form" as used in the question is just executing \nolinebreak at the start of the env and nothing at the end (other than having the effect of a scope deimiter for anything inside -- thus it doesn't make sense to use that ever. – Frank Mittelbach Jan 10 '19 at 14:44
  • Saying that, "\nolinebreak does not last at all is equivalent to saying, that \nolinebreak is "non-sticky." – IdleCustard Jan 12 '19 at 01:53
  • @IdleCustard no not at all, as I say above the terminoligy is not useful, but you defined it as A non-sticky command affects only the next item on the input stream, \nolinebreak doesn't affect the next token any more than b affects c in abc , exactly like a character token it just adds a node to the current horizontal list. – David Carlisle Jan 12 '19 at 01:56
  • @ David Carlisle says that my mental model is not at all how TeX actually works. However, the vast majority of LaTeX commands have two behaviors: (1) they behave like non-sticky text stream manipulators. The non-sticky command modifies the next tiny piece of the text stream. None of the text coming afterwards is affected by the non-sticky command. (2) the command can be viewed as turning on some sort of "mode" which sticks until removed. All of the text which comes afterwards is affected (example: made boldface) until you turn off the mode with some sort of end delimiter. – IdleCustard Jan 12 '19 at 01:59
  • @IdleCustard no they do not act that way, with some effort your description could be applied to font commands but very little else. – David Carlisle Jan 12 '19 at 02:00
  • @IdleCustard so is b sticky or non sticky in abcd the affect on c and d is via the same mechanism as the effect that \nolinebreak[1] has in a\nolinebreak[1]cd in both cases the only thing that happens is that a node is inserted between a and c and so that node may or may not have an affect on how the horizontal list is finally positioned, and it may affect the position of all of a, c and d. – David Carlisle Jan 12 '19 at 02:04