3

Is it possible to modify TeX/LaTeX commands so that certain commands are executed before/after a paragraph? For instance, we know that when the LaTeX compiler sees the \par command or a whitespace line, it ends the current paragraph and enters vertical mode (?).

So, I'm looking for a command that I could modify such that I could type

%redefine some commands up here

\begin{document}
Paragraph 1

Paragraph 2
\end{document}

and have it produce the same output as

\begin{document}
$\triangle$Paragraph 1

$\triangle$Paragraph 2
\end{document}

Another related question would be also producing output like

\begin{document}
Paragraph 1$\square$

Paragraph 2$\square$
\end{document}
2

Redefine \par globally is very dangerous. But limited to an environment it could be possible add some elements without writing any command. Example:

(not guarantee of safety in a real document)

MWE

\documentclass{article}
\usepackage{xcolor}

\newenvironment{crazypar}{%at begin 
\smallskip
\def\par{%
\pdfprimitive\par\noindent\rule{\textwidth}{0.4mm}%
\pdfprimitive\par\makebox[-2em][c]{\color{red}$\triangle$}\hspace{1.5em}
}}%
{%at end
\newline\noindent\rule{\textwidth}{0.4mm}
}


\begin{document}

This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text.

This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text. 

This is a dummy text. This is a dummy text.

\begin{crazypar}

This is a dummy text. 

This is a dummy text. This is a dummy text. This is a dummy text.

This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text.

This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text.  % no blank line here
\end{crazypar}

This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text.

\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.