5

I am using t-vim module and I would like to format my listings similar to figures with captions, but with the ability to spread them over multiple pages. I can see three ways to do it:

  • Put the \typeCfile{mycode.c} command inside a float object. The problem is that floats cannot be split over multiple pages.
  • Type the listing as text and add a caption after it. However, my listings are sometimes split by figures and I did not find a way to prevent a float object from entering my listings.
  • Put each line of code inside a row of an invisible table and make the table to be splitable. Unfortunately, I did not find a way to automatically create such a table out of my source file.

Is there any other solution or can one of my solutions be fixed?

  • KOMA supports a \FloatBarrier. You can also do it using \setcounter{topnum}{0} and \setcounter{bottomnum}{0} temporarily. You would need a \clearpage to stop [p] floats. – John Kormylo Oct 17 '18 at 15:52
  • See also tex.stackexchange.com/questions/204703/… – John Kormylo Oct 17 '18 at 15:56
  • Also, \afterpage (afterpage package} runs to completion before the first float. – John Kormylo Oct 17 '18 at 15:58
  • 2
    @John Kormylo : you are not using a ConTeXt syntax. The wiki recommands \definenumber and \setnumber[][]. I do not know wether KOMA scripts are ConTeXt compatible. – sztruks Oct 17 '18 at 17:07
  • 3
    I asked on the mailing list. Here is your answer: mailman.ntg.nl/pipermail/ntg-context/2018/093069.html – Henri Menke Oct 17 '18 at 17:41
8

By default only tables can be broken across pages when you put them in a float block. With ConTeXt version 2018.10.18 00:07 a new environment with the name splittext was added which can be used to create multipage floats for other text based content, e.g. code listing.

To create such a multipage float you have to put your text in the splittext environment.

\setuppapersize [A6] [A5,landscape]

\setuparranging [2SIDE]

\showframe [page]

\definefloat [listing]

\starttext

\startplacefloat [listing] [location={split},title={Dummy listing}]
  \startsplittext
  \dorecurse{35}{Line \recurselevel\endgraf}
  \stopsplittext
\stopplacefloat

\stoptext

enter image description here

  • 1
    Is there a way to get Listing 1 (cont) or something similar on the 2nd page? – Aditya Oct 18 '18 at 22:50
  • Thank you for your solution. It works, but for some reason figures can still break the listing parts: Example1. Moreover, small listing parts can occupy whole page, which is also kind of a problem: Example2. Is there a way control this behavior? – Goshik Oct 20 '18 at 16:50
  • @Goshik: For Example 2, why use a split if you have a small listing. Is this in an automated workflow? – Aditya Oct 21 '18 at 22:00
  • @Aditya: That small listing is a part of the big one. Even if it was a separate one, it would be convenient to use the same code for all listings, since you never know in advance how long each of them is. – Goshik Oct 22 '18 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.