|
267 | 267 | \newcommand{\leftshift}[1]{\ensuremath{\mathbin{\mathsf{lshift}_{#1}}}}
|
268 | 268 |
|
269 | 269 | %% Notes and examples
|
270 |
| -\newcommand{\noteintro}[1]{[\textit{#1}:} |
| 270 | +\newcommand{\noteintro}[1]{[\textit{#1}: } |
271 | 271 | \newcommand{\noteoutro}[1]{\textit{\,---\,#1}\kern.5pt]}
|
272 | 272 |
|
273 | 273 | % \newnoteenvironment{ENVIRON}{BEGIN TEXT}{END TEXT}
|
|
278 | 278 | \newcommand{\newnoteenvironment}[3]{
|
279 | 279 | \newsubclausecounter{#1}
|
280 | 280 | \newenvironment{#1}
|
281 |
| -{\def\noteend{#3}\par\small\stepcounter{#1}\noteintro{#2}} |
| 281 | +{\def\noteend{#3}\par\small\stepcounter{#1}\noteintro{#2}\hbox to 0pt{}\ignorespaces} |
282 | 282 | {\noteoutro{\noteend}\par}
|
283 | 283 | }
|
284 | 284 |
|
|
462 | 462 | % Our usual abbreviation for 'listings'. Comments are in
|
463 | 463 | % italics. Arbitrary TeX commands can be used if they're
|
464 | 464 | % surrounded by @ signs.
|
465 |
| -\newcommand{\CodeBlockSetup}{% |
| 465 | +\def\codeblockbeginpenalty{-1} % default: no penalty change before codeblock |
| 466 | +\newcommand{\CodeBlockSetup}{ |
| 467 | +\ifnum\codeblockbeginpenalty=-1 |
| 468 | +\else |
| 469 | + \presetkeys{lst}{beginpenalty=\codeblockbeginpenalty}{}% |
| 470 | +\fi |
466 | 471 | \lstset{escapechar=@, aboveskip=\parskip, belowskip=0pt,
|
467 | 472 | midpenalty=500, endpenalty=-50,
|
468 | 473 | emptylinepenalty=-250, semicolonpenalty=0}%
|
|
473 | 478 |
|
474 | 479 | \lstnewenvironment{codeblock}{\CodeBlockSetup}{}
|
475 | 480 |
|
476 |
| -% Left-align listings titles |
477 | 481 | \makeatletter
|
| 482 | + |
| 483 | +\newsavebox\@signalbox |
| 484 | + |
| 485 | +% Redefine \begin{codeblock} to look for an immediately-preceding |
| 486 | +% \begin{example}. |
| 487 | +\global\@namedef{codeblock}{% |
| 488 | + \def\lstenv@name {codeblock}\begingroup% |
| 489 | + \ifhmode% no last box in vertical mode |
| 490 | + \setbox\@signalbox=\lastbox% grab and consume last box |
| 491 | + \copy\@signalbox% typeset the last box again |
| 492 | + \ifhbox\@signalbox% |
| 493 | + \ifdim\wd\@signalbox=0pt% zero-width box is our marker |
| 494 | + \def\codeblockbeginpenalty{100}% |
| 495 | + \fi% |
| 496 | + \fi% |
| 497 | + \fi% |
| 498 | + \lst@setcatcodes \catcode \active=\active \csname codeblock@\endcsname% |
| 499 | +} |
| 500 | + |
| 501 | +% Left-align listings titles |
478 | 502 | \def\lst@maketitle{\@makeleftcaption\lst@title@dropdelim}
|
479 | 503 | \long\def\@makeleftcaption#1#2{%
|
480 | 504 | \vskip\abovecaptionskip
|
|
0 commit comments