# Ignoring \par commands with \renewcommand{\par}{}?

I would like to ignore \par commands in a predefined LaTeX file. I simply tried:

\renewcommand{\par}{}


but this does not work as \par is ending the paragraph within the \renewcommand command.

! Paragraph ended before \renew@command was complete.


Is there a way to do this?

• Welcome to TeX.SE. And congratulations to have found a way to shoot yourself into your foot with this idea ;-) Sorry! – user31729 Nov 8 '17 at 17:50
• This seems like it could go wrong in many different ways. Why are you wanting to redefine \par? – Teepeemm Nov 8 '17 at 17:58
• Maybe it is better to do a search and replace with your editor. You can also run a script to do that (sed, ...). Not everything has to be done within TeX. And redefining \par seems like a particularly risky idea. – moewe Nov 8 '17 at 18:02
• I'd say it is more dangerous at the TeX level than to fix the input that causes the unwanted .tex code. – moewe Nov 8 '17 at 18:21
• You can do \def\par{}; then wait until TeX exits from some infinite loop. :-) Really, it's a very dangerous thing to do, because in several occasions TeX inserts \par automatically and in such circumstances it may not exit from the loop. – egreg Nov 8 '17 at 18:22

You can easily redefine \par:

\def\par{}


But it is only safe to do this in very controlled contexts, for example:

This document will not terminate and you will need to kill the process

\documentclass{article}

\begin{document}

\def\par{}

aaaaa

\hrule

\end{document}

• Is there a way to completely un-hardcode things from TeX? Or is somehow \par (or some other thing) entirely hardcodded? – Manuel Nov 8 '17 at 20:04
• @Manuel many aspects of \par are hardcoded, (so that the behaviour can be customised) when tex needs to end a paragraph it does not (normally) use the primitive end-of-para action it simply inserts \par (as it does at a blank line) so this allows you to define \par to do interesting things, but if (as here) those things do not include ending a paragraph then things can easily go wrong, here it sees \hrule so needs to get out of hmode, so inserts a \par then it sees \hrule so inserts a \par then.. – David Carlisle Nov 8 '17 at 20:51
• So in TeX there's no way to tell TeX to never use an explicit \par and rather use its meaning (or \engraf or an alternative)? Are there more things that are hardcoded into the program? – Manuel Nov 8 '17 at 20:56
• @Manuel as far as I can think \par is the only command name that can not be changed any other primitive you can save the primitive under another name then redefine the original name to be anything (or make it undefined) but tex itself inserts \par tokens – David Carlisle Nov 8 '17 at 20:57

The best course could be to redefine \par inside a group. For example

\newenvironment{specialpar}{\def\par{\ \P\ }}{\endgraf}


And then that way you can do

\documentclass{article}

\usepackage{kantlipsum} % for this example

\newenvironment{specialpar}{\def\par{\ \P\ }}{\endgraf}

\begin{document}

\begin{specialpar}
Whatever you want, but knowing that \texttt{\string\par} is a special thing in here,
so your input must be controlled. \par
This. \par
That. \par
And many other things, but beware of errors.

Another paragraph.

And yet another.

\kant
\end{specialpar}

\end{document}


PS: note that if you pile a lot of things in the same “TeX paragraph” (that is, before adding the original \par or \engraf for instance) this is piling in memory and makes TeX work much more (the program kind of breathes each time he processes a proper paragraph).