Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

\begin{verbatimwrite}{filename}
... stuff ...
\end{verbatimwrite}\somecommand...

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.

share|improve this question
    
I'm at least curious why this happens ({\tiny\begin{verbatim} ... \end{verbatim}} is an error in a memoir document). –  Jack Schmidt 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

1 Answer 1

up vote 1 down vote accepted

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:

\documentclass{article}
\usepackage{moreverb}
\def\somecommand{Foo}
\begin{document}
\thispagestyle{empty}
\begin{verbatimwrite}{filename}
... stuff ...
\end{verbatimwrite}^M\somecommand
Bar
\end{document}

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:

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.

share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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