adityam / filter

ConTeXt module to process contents of a start-stop environment through an external program
45 stars 10 forks source link

Line numbers not visible if wrapped in float #21

Closed JensBee closed 7 years ago

JensBee commented 9 years ago

Hi, I'm trying to use a vim typing block inside a float. If it's wrapped in a float the line numbers are not visible. Here's a short example:

\usemodule[vim]
\definefloat[sourcecode][sourcecodes]
\definevimtyping[JSON][syntax=json,numbering=yes]

\starttext
    \startplacesourcecode
        \startJSON
            some code
        \stopJSON
    \stopplacesourcecode
\stoptext

If I comment \*placesourcecode the code get's typeset as expeced (numbering visible).

Is there anything I can do to make them visible inside floating areas?

adityam commented 9 years ago

This is an upstream bug/limitation. Line numbering does not work inside floats:

\definefloat[sourcecode][sourcecodes]

\startbuffer
\startlinenumbering
  \input tufte
\stoplinenumbering
\stopbuffer

\starttext
    \startplacesourcecode
      \getbuffer
    \stopplacesourcecode

    \getbuffer
\stoptext

The best way will be to post a feature request on the ConTeXt mailing list.

adityam commented 9 years ago

This has been fixed upstream, but you need to wrap the contents inside a framed. Here is one option:

\usemodule[vim]
\definefloat[sourcecode][sourcecodes]

\defineframedtext
  [JSONframed]
  [
    align=normal,
    frame=off,
    width=fit,
  ]

\definevimtyping
  [JSON]
  [
    syntax=json,
    numbering=yes,
    before=\startJSONframed,
    after=\stopJSONframed,
  ]

\starttext
    \startplacesourcecode
        \startJSON
            some code
        \stopJSON
    \stopplacesourcecode
\stoptext

Note that a drawback of this approach is that the listings will not split across pages.