estilo de nueva línea personalizado en entornos

estilo de nueva línea personalizado en entornos

Quiero agregar algo a cada nueva línea, como esto:

\documentclass{article}
\newenvironment{mystuff}{dark magic goes here}{or here}
\begin{document}
\begin{mystuff}
first row
second row
\end{mystuff}
\end{document}

y quiero que Latex lo represente así:

first row -and this was added by mystuff environment
second row -and this was added by mystuff environment

¿Cómo lo hago?

Respuesta1

Como dice Henri Menke, el ^^Mtruco es arriesgado, pero funciona en caso de apuro. Edité esto para usarlo \obeylines(esencialmente equivalente y arriesgado), lo que simplifica un poco el código. También eliminé los \makeatletter... \makeatothercomandos. Modifiqué ligeramente el código para que puedas especificar, sobre la marcha, el texto que se agrega:

\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{blindtext}

%\def\specialccr{\mytext\newline}
\def\specialccr{\mytext\par}

{\obeylines
    \gdef\specialcr{\obeylines \let^^M=\specialccr}%
}

\newenvironment{mystuff}[1]{%
    \def\mytext{#1}%
    \parindent0pt
    \leftskip3em
    \everypar={$\bullet$\ }
    \par
    \noindent
    \specialcr}{%
}

\begin{document}
\blindtext[1]

\begin{mystuff}{\ -- and this was added by mystuff environment}% <- % Necessar
first row
second row
third row
\end{mystuff}

\blindtext[1]
\end{document}

Una edición final. El original utilizado \newlineque no inicia nuevos párrafos. Lo sustituí \par, lo que a su vez permite todo tipo de formatos interesantes:

ingrese la descripción de la imagen aquí

Respuesta2

Estoy usando un carácter activo de fin de línea ^^M. Esto esnouna buena solución, pero funciona.

\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{blindtext}
\makeatletter
\def\special@cr{!\newline}
{\catcode`\^^M=\active%
    \gdef\specialcr{\catcode`\^^M=\active \let ^^M=\special@cr}%
}
\makeatother
\newenvironment{mystuff}{\par\noindent\specialcr}{}
\begin{document}
\blindtext[1]
\begin{mystuff}% You will want to suppress the ^^M here.
first row
second row
\end{mystuff}
\blindtext[1]
\end{document}

ingrese la descripción de la imagen aquí

información relacionada