Quero adicionar algo a cada nova linha, assim:
\documentclass{article}
\newenvironment{mystuff}{dark magic goes here}{or here}
\begin{document}
\begin{mystuff}
first row
second row
\end{mystuff}
\end{document}
e quero que o Latex renderize assim:
first row -and this was added by mystuff environment
second row -and this was added by mystuff environment
Como eu faço isso?
Responder1
Como diz Henri Menke, o ^^M
truque é arriscado, mas funciona em caso de emergência. Editei isso para usar \obeylines
(essencialmente equivalente e arriscado), o que simplifica um pouco o código. Também removi os \makeatletter
... \makeatother
comandos. Alterei um pouco o código para que você possa especificar imediatamente o texto adicionado:
\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}
Uma edição final. O original utilizado \newline
que não inicia novos parágrafos. Substituí \par
o que por sua vez permite todo tipo de formatação interessante:
Responder2
Estou usando um caractere de fim de linha ativo ^^M
. Isso énãouma boa solução, mas 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}