|
280 | 280 | \newcommand{\leftshift}[1]{\ensuremath{\mathbin{\mathsf{lshift}_{#1}}}}
|
281 | 281 |
|
282 | 282 | %% Notes and examples
|
283 |
| -\newcommand{\noteintro}[1]{[\textit{#1}:} |
| 283 | +\newcommand{\noteintro}[1]{[\textit{#1}: } |
284 | 284 | \newcommand{\noteoutro}[1]{\textit{\,---\,#1}\kern.5pt]}
|
285 | 285 |
|
286 | 286 | % \newnoteenvironment{ENVIRON}{BEGIN TEXT}{END TEXT}
|
|
292 | 292 | \newcommand{\newnoteenvironment}[3]{
|
293 | 293 | \newsubclausecounter{#1}
|
294 | 294 | \newenvironment{tail#1}
|
295 |
| -{\par\small\stepcounter{#1}\noteintro{#2}} |
| 295 | +{\par\small\stepcounter{#1}\noteintro{#2}\hbox to 0pt{}\ignorespaces} |
296 | 296 | {\noteoutro{#3}}
|
297 | 297 | \newenvironment{#1}
|
298 | 298 | {\begin{tail#1}}
|
|
497 | 497 | % Our usual abbreviation for 'listings'. Comments are in
|
498 | 498 | % italics. Arbitrary TeX commands can be used if they're
|
499 | 499 | % surrounded by @ signs.
|
500 |
| -\newcommand{\CodeBlockSetup}{% |
| 500 | +\def\codeblockbeginpenalty{-1} % default: no penalty change before codeblock |
| 501 | +\newcommand{\CodeBlockSetup}{ |
| 502 | +\ifnum\codeblockbeginpenalty=-1 |
| 503 | +\else |
| 504 | + \presetkeys{lst}{beginpenalty=\codeblockbeginpenalty}{}% |
| 505 | +\fi |
501 | 506 | \lstset{escapechar=@, aboveskip=\parskip, belowskip=0pt,
|
502 | 507 | midpenalty=500, endpenalty=-50,
|
503 | 508 | emptylinepenalty=-250, semicolonpenalty=0}%
|
|
508 | 513 |
|
509 | 514 | \lstnewenvironment{codeblock}{\CodeBlockSetup}{}
|
510 | 515 |
|
511 |
| -% Left-align listings titles |
512 | 516 | \makeatletter
|
| 517 | + |
| 518 | +\newsavebox\@signalbox |
| 519 | + |
| 520 | +% Redefine \begin{codeblock} to look for an immediately-preceding |
| 521 | +% \begin{example}. |
| 522 | +\global\@namedef{codeblock}{% |
| 523 | + \def\lstenv@name {codeblock}\begingroup% |
| 524 | + \ifhmode% no last box in vertical mode |
| 525 | + \setbox\@signalbox=\lastbox% grab and consume last box |
| 526 | + \copy\@signalbox% typeset the last box again |
| 527 | + \ifhbox\@signalbox% |
| 528 | + \ifdim\wd\@signalbox=0pt% zero-width box is our marker |
| 529 | + \def\codeblockbeginpenalty{100}% |
| 530 | + \fi% |
| 531 | + \fi% |
| 532 | + \fi% |
| 533 | + \lst@setcatcodes \catcode \active=\active \csname codeblock@\endcsname% |
| 534 | +} |
| 535 | + |
| 536 | +% Left-align listings titles |
513 | 537 | \def\lst@maketitle{\@makeleftcaption\lst@title@dropdelim}
|
514 | 538 | \long\def\@makeleftcaption#1#2{%
|
515 | 539 | \vskip\abovecaptionskip
|
|
0 commit comments