I need to use a form of a verbatim environment, so that after the closing of the environment, there immediately follows another command. In particular I need something like the following - assuming moreverb package - but the problem is not specific to moreverb:

... stuff ...

Most verbatim-facilitating packages (moreverb, fancyvrb, etc.) either discard whatever characters follow the closing environment tag (moreverb), or result in an error (fancyvrb).

Is there a solution to this? Note, dividing the last line into two is not an option!

Would it be an option to "fool" TeX to think there actually is EOL character, while there is none (e.g., using \scancodes) and at the same time preserve compatibility with some implementation of verbatim functionality? Alternatively, could you point me to an (re-)implementation of the "verbatimwrite" functionality, which would allow characters after the closing tag?

To explain why dividing the last line is not an option: I need to integrate my package with LyX and it allows only single-line TeX snippets in its layout style definitions (Command/Environment). Wrapping the end of environment together with the \somecommand in a new command wouldn't work due to the verbatim implemenation and multi-line solution is not allowed in LyX layout format.

  • I'm at least curious why this happens ({\tiny\begin{verbatim} ... \end{verbatim}} is an error in a memoir document). Jul 11 '12 at 15:43
  • Welcome to TeX.SX! Is \somecommand always the same?
    – egreg
    Jul 11 '12 at 15:44
  • @egreg: thanks for the warm welcome. No, it isn't. The command is always the same, but it's arguments are user defined.
    – walkmanyi
    Jul 11 '12 at 15:53
  • @JackSchmidt: I guess because the closing '}' is thrown away by the \end{verbatim}. I am not even sure the parser finds the end of the environment... It should be on its own line. This has to do with detection of the end of the verbatim environment. My understanding is that there is string matching going on to do this and the implementations in various packages (sverb?) try to match "\end{verbatim}" at the beginning of line to find that the environment finished. But this beyond my knowledge of TeX internal workings.
    – walkmanyi
    Jul 11 '12 at 15:56

You can insert a character ASCII 13 before your command. For example, using vim as editor, you press Ctrl+V and then Ctrl+M. Your input would look like this:

... stuff ...

But note that ^M is the way vim shows the ASCII 13, and thus it is a single char, not the sequence of chars ^ and M.

Compiling that document produces the desired output:


I don't know however if this solution is valid for you, since I don't know if LyX would allow you to insert this control character.

  • Thanks a lot for for the reply. You are right, this would work in tex file, though it does not work in LyX. LyX fails to read a layout file containing that character. Isn't there a solution with partial re-implementation of verbatim environment to use different way of detecting end of the verbatim environment?
    – walkmanyi
    Jul 13 '12 at 10:59

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.