How can I insert a special character or a symbol in the beginning of each line in a verbatim environment? In particular, there is a constraint that applies to the verbatim environment: it must be of a special type (given below); it cannot be any of the standard verbatim
environments, e.g. from packages fancyvrb
or listings
..
I am working on developing an environment to format email correspondence. It is based on a modification of the standard verbatim
environment without the \obeylines
part, see "Format a verbatim paragraph"
As the code has mainly been developed by Frank Mittelbach I am not sure what would be the minimal working example.. So I think I have to include the whole environment. Here is an example:
\documentclass{article}
\usepackage{xstring}
\makeatletter
\newdimen\outerparindent
\def\myverbatim#1{%
\IfStrEq{#1}{c}{\renewcommand{\verbatim@font}{\slshape\ttfamily}}
{\renewcommand{\verbatim@font}{\upshape\ttfamily}}%
\def\do@noligs##1{%
\catcode`##1\active
\begingroup
\lccode`\~`##1\relax
\lowercase{\endgroup\def~{\leavevmode\kern\z@\char`##1 }}}%
\outerparindent\parindent
\def\obeylines{\rightskip=0pt plus 1fil
\parindent=\outerparindent
\let\par\@@par
\leavevmode\indent}%
\def\@xobeysp{\penalty\z@\mbox{}\space\penalty\z@}%
\@verbatim
\@myverbatimescape\@myverbatimnewline
\frenchspacing\@vobeyspaces\@xmyverbatim}
\let\endmyverbatim\endverbatim
\begingroup
\catcode`\^^M=\active%
\gdef\@myverbatimnewline{\catcode`\^^M=\active \let^^M\@xmyverbatimnewline}%
\gdef\@xmyverbatimnewline{\@ifnextchar ^^M{\@myverbatimpar}{\@xobeysp}}%
\gdef\@ymyverbatimnewline{\@ifnextchar ^^M{\@myverbatimpar}{}}%
\gdef\@myverbatimpar ^^M{\par%
\vskip\baselineskip%
\@ymyverbatimnewline}%
\gdef\@zmyverbatimnewline{\@ifnextchar ^^M{\@zmyverbatimpar}{}}%
\gdef\@zmyverbatimpar^^M{\@ifnextchar ^^M{\@myverbatimpar}{}}%
\endgroup
\begingroup \catcode `|=0 \catcode `[= 1
\catcode`]=2 \catcode `\{=12 \catcode `\}=12
\catcode`\\=13
|gdef|@myverbatimescape[|catcode`|\|active|let\|@myverbatimbslash]
|gdef|@myverbatimbslash[|@ifnextchar\[|@xmyverbatimbslash][|string\]]
|gdef|@xmyverbatimbslash\[|\]
|catcode`|^^M=|active
|long|gdef|@xmyverbatim#1\end{myverbatim}[|@zmyverbatimnewline#1^^M|vskip-|lastskip|vskip|z@skip|end[myverbatim]]%
|endgroup
\makeatother
\begin{document}
\begin{myverbatim}{c}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sed orci quis urna volutpat tincidunt. Praesent ultrices commodo auctor. Nunc vel nulla sed arcu aliquet faucibus quis nec ante. Nam elementum neque vitae sem fringilla a euismod eros malesuada. Duis orci eros, tincidunt et venenatis at, tristique in tortor
\end{myverbatim}
\begin{myverbatim}{n}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sed orci quis urna volutpat tincidunt. Praesent ultrices commodo auctor. Nunc vel nulla sed arcu aliquet faucibus quis nec ante. Nam elementum neque vitae sem fringilla a euismod eros malesuada. Duis orci eros, tincidunt et venenatis at, tristique in tortor
\end{myverbatim}
\end{document}
The current output:
(Goal: I would like to insert a special symbol like >
or |
in the beginning of each line of the first paragraph (i.e. in the beginning of each line with slanted text))
More specifically: How can I modify the environment such that if the parameter to the myverbatim
environment is, say, the character c
, then each line is preceded by a symbol, say >
, if the parameter is not c
then no symbol is inserted in the beginning of the line..
I have studied David's answer to this post "Environment prints same character at beginning of each output line" but I could not get it to work for my case.. Maybe there is a simpler solution?
(See also: How to format an email conversation?)
listings
package it will run into the problem with line-breaking and -joining, see Format a verbatim paragraph..fancyvrb
package and its macro\FancyVerbFormatLine
(explained on p.6 of the package's user guide) to insert some character at the start of each line? In the user guide, examples are given which take one argument (the line to be printed); it's straightforward to make this a two-argument macro.fancyvrb
package has line breaking, see e.g. How to force line breaks within a fancyvrb verbatim environment? and Format a verbatim paragraph ..