Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macros] Avoid page break between example and codeblock introducers #4237

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jensmaurer
Copy link
Member

if they are immediately following each other.

Partially addresses #4228

@jensmaurer
Copy link
Member Author

This destroys the penalty after a heading and thus needs more fine-tuning.

@jensmaurer
Copy link
Member Author

Let's not do this for C++20, but it seems viable for C++23.

@tkoeppe
Copy link
Contributor

tkoeppe commented Sep 26, 2020

I agree. Thanks a lot, though, this is a very interesting tweak to explore.

Comment on lines +485 to +521
% Redefine \begin{codeblock} to look for an immediately-preceding
% \begin{example}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of redefining it, can we rename the listing environment and define our codeblock environment in terms of the listings environment? Or is that not possible due to the way that listings monkeys with the input stream?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what you mean. We already have \lstnewenvironment{codeblock}{\CodeBlockSetup}{}, above.
The problem is that I can't put the "detect marker" code into \CodeBlockSetup, because that's too late and I can't get at the preceding box anymore. In order to get control earlier, I'm redefining the codeblock environment to get an earlier grab.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I'm asking is whether we can instead use (say) \lstnewenvironment{codeblockimpl}.... and then define a new codeblock environment in terms of codeblockimpl. Modifying an existing environment like this, rather than composing this environment out of the existing one, is a hack that we should avoid if we can. (Maybe we can't; so be it.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried this:

\newenvironment{codeblock}
{%
  \ifhmode%                             no last box in vertical mode
    \setbox\@signalbox=\lastbox%        grab and consume last box
    \copy\@signalbox%                   typeset the last box again
    \ifhbox\@signalbox%
      \ifdim\wd\@signalbox=0pt%         zero-width box is our marker
        \def\codeblockbeginpenalty{100}%
      \fi%
    \fi%
  \fi%
\begin{codeblockimpl}}
{\end{codeblockimpl}}

Result:

! Extra }, or forgotten \endgroup.
\egroup

l.228 ...( ) < > % : ; . ? * + - / ^ & | ~ ! = , @
\textbackslash@ " '

So, the environment nesting appears to negatively impact @ recognition. No idea why.

@zygoloid
Copy link
Member

@godbyk Can you take a look at this?

I don't understand LaTeX well enough to know if this is reasonable.

@godbyk
Copy link
Contributor

godbyk commented Oct 18, 2020

@zygoloid Yeah, I can take a look. Do you have a couple examples of bad page breaks I can use for testing?

@wg21bot wg21bot added the needs rebase The pull request needs a git rebase to resolve merge conflicts. label Jun 15, 2021
@jensmaurer jensmaurer removed the needs rebase The pull request needs a git rebase to resolve merge conflicts. label Jul 4, 2021
@jensmaurer jensmaurer force-pushed the excb branch 2 times, most recently from f095f05 to 6c74f10 Compare July 7, 2021 21:00
if they are immediately following each other.
@jensmaurer
Copy link
Member Author

@tkoeppe, this does fix a few situations where we have a lone "[ Example 1:" at the bottom of the preceding page. Those introducers are moved to the next page. You could argue that the mechanics is too hacky, but we should decide whether we want to go forward here or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
decision-required A decision of the editorial group (or the Project Editor) is required.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants