다음과 같이 각 줄 바꿈에 뭔가를 추가하고 싶습니다.
\documentclass{article}
\newenvironment{mystuff}{dark magic goes here}{or here}
\begin{document}
\begin{mystuff}
first row
second row
\end{mystuff}
\end{document}
그리고 저는 Latex가 다음과 같이 렌더링하길 원합니다:
first row -and this was added by mystuff environment
second row -and this was added by mystuff environment
어떻게 해야 하나요?
답변1
앙리 멘케(Henri Menke)가 말했듯이 이 ^^M
방법은 위험하지만 위기 상황에서는 효과가 있습니다. \obeylines
코드를 약간 단순화하는(본질적으로 동일하고 위험함) 사용하도록 이것을 편집했습니다 . \makeatletter
... 명령 도 제거했습니다 \makeatother
. 추가되는 텍스트를 즉시 지정할 수 있도록 코드를 약간 변경했습니다.
\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}
최종 편집 하나. \newline
새로운 단락을 시작하지 않는 원본이 사용되었습니다 . 나는 \par
모든 종류의 흥미로운 형식을 허용하는 것으로 대체했습니다.
답변2
활성 줄 끝 문자를 사용하고 있습니다 ^^M
. 이것은~ 아니다좋은 해결책이지만 작동합니다.
\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}