|
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 | +\def\codeblockbeginpenalty{0} % default penalty before codeblock |
465 | 466 | \newcommand{\CodeBlockSetup}{%
|
466 | 467 | \lstset{escapechar=@, aboveskip=\parskip, belowskip=0pt,
|
467 |
| - midpenalty=500, endpenalty=-50, |
| 468 | + beginpenalty=\codeblockbeginpenalty, midpenalty=500, endpenalty=-50, |
468 | 469 | emptylinepenalty=-250, semicolonpenalty=0}%
|
469 | 470 | \renewcommand{\tcode}[1]{\textup{\CodeStylex{##1}}}
|
470 | 471 | \renewcommand{\term}[1]{\textit{##1}}%
|
|
473 | 474 |
|
474 | 475 | \lstnewenvironment{codeblock}{\CodeBlockSetup}{}
|
475 | 476 |
|
476 |
| -% Left-align listings titles |
477 | 477 | \makeatletter
|
| 478 | + |
| 479 | +\newsavebox\@signalbox |
| 480 | + |
| 481 | +% Redefine \begin{codeblock} to look for an immediately-preceding |
| 482 | +% \begin{example}. |
| 483 | +\global\@namedef{codeblock}{% |
| 484 | + \def\lstenv@name {codeblock}\begingroup% |
| 485 | + \ifhmode% no last box in vertical mode |
| 486 | + \setbox\@signalbox=\lastbox% grab and consume last box |
| 487 | + \copy\@signalbox% typeset the last box again |
| 488 | + \ifhbox\@signalbox% |
| 489 | + \ifdim\wd\@signalbox=0pt% zero-width box is our marker |
| 490 | + \def\codeblockbeginpenalty{100}% |
| 491 | + \fi% |
| 492 | + \fi% |
| 493 | + \fi% |
| 494 | + \lst@setcatcodes \catcode \active=\active \csname codeblock@\endcsname% |
| 495 | +} |
| 496 | + |
| 497 | +% Left-align listings titles |
478 | 498 | \def\lst@maketitle{\@makeleftcaption\lst@title@dropdelim}
|
479 | 499 | \long\def\@makeleftcaption#1#2{%
|
480 | 500 | \vskip\abovecaptionskip
|
|
0 commit comments