Insert a character in the beginning of each line in a special verbatim environment
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
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
No comments:
Post a Comment