2

I had defined an environment which disabled \par temporarily with \let\par\relax precisely to disallow paragraph breaks in that environment. It was working fine until I last compiled the document (mid 2018), but now (with TeXLive 2019) it gets stuck into an infinite compilation.

I managed to strip down the problem to a code (at the bottom of this post) that uses only the minted package with \setminted{bgcolor=white} and my nopar environment.

If I comment out \let\par\relax the document compiles fine, but I need to disable \par here (unless, of course, there is another way to disallow paragraph breaks, in which case I'd accept as an answer). If I comment out \setminted{bgcolor=white} then I get the fearsome Missing \item error. If I comment out the text before \begin{minted} it works as well, but I can't do that.

Here's the guilty code:

\documentclass{article}
\usepackage{minted}
\setminted{bgcolor=white}
\newenvironment{nopar}{%
  \let\par\relax}{}
\begin{document}
\begin{nopar}
  hello
  \begin{minted}{latex}
    world
  \end{minted}
\end{nopar}
\end{document}
  • What would be the purpose of disabling \par? Are you perhaps trying to typeset the minted part in line? Then Hello \mintinline{latex}{world} should suffice. – egreg May 27 at 22:09
  • By the way, I get an infinite loop with all TeX Live releases from 2016 onwards; only TL 2015 compiles, but with a very disputable output. – egreg May 27 at 22:13
  • This is very confusing. What exactly are you hoping your environment is going to do? Do you just don't like the indent, that par does? Just use \noindent. Do you just don't like the extra empty line? Use \newline. Do you want an empty line, but not with par? Use \vspace{"Enter Number with units"}. Or am I missing another option? – DonFangzahn May 27 at 22:41
  • @egreg Sorry if I didn't express myself right. This is only a stripped down example. In the actual document I have an environment which is not supposed to have paragraph breaks, and in the middle of it there is a block of code (not inline). I disable \par because this package is supposed to be used by other people and I want to ensure that there will be no paragraph breaks. Of course I can simply remove the blank lines, but I'd rather make the code work with \par disabled. However, if you know some other form of disallowing paragraph breaks inside an environment, I'd be open to change! – LaTeXer May 27 at 23:14
  • @DonFangzahn No, it's not about the indentation. I know I can set \parindent=0pt as well inside the environment. The thing is, as I (hopefully :) explained in the comment to egreg, that I want the text inside the nopar environment to not have paragraph breaks, even if the user inserts a blank line (of course, if one wants to be stubborn, one can use \endgraf). The text in the environment is supposed to be a single, long paragraph. – LaTeXer May 27 at 23:17
4

I'm not sure what's the purpose of \let\par\relax in a context where minted is allowed.

Anyway, use etoolbox to restore \par in the minted environment.

\documentclass{article}
\usepackage{minted}
\usepackage{etoolbox}

\makeatletter
\AtBeginEnvironment{minted}{\let\par\@@par}
\makeatother

\setminted{bgcolor=white}

\newenvironment{nopar}{\let\par\relax}{}

\begin{document}

\begin{nopar}
  hello
  \begin{minted}{latex}
    world
  \end{minted}
  again

  Again
\end{nopar}

\end{document}

enter image description here

3

The intention of the code in the question is very unclear but redefining \par to anything is highly likely to throw LaTeX into an infinite loop or break it in other ways.

In some highly controlled environments it can be a useful technique but never in environments taking arbitrary LaTeX content. Your example loops on including the rather complex minted code, but this trivial example also loops.

When TeX sees a command that should be in vertical mode (there are lots of these, but I used \vskip here) when it is not in vmode, it inserts \par to try to start the vmode and tries the command again. If you disable \par it loops... This is built into TeX-the-program so it is not under LaTeX control.

\documentclass{article}

\begin{document}

{\let\par\relax

a  \vskip 2pt

}


\end{document}
  • Thank you for your answer! Can you please explain what happens here that makes the code loop forever? – LaTeXer May 28 at 11:56
  • @LaTeXer tex sees a command that should be in vertical mode (there are lots of these, but vskip here) when it is not in vmode, so it inserts \par and tries again, if you disable \par it loops....... this is built into tex-the-program so not under latex control. – David Carlisle May 28 at 12:06
  • I think I understand. Thanks a lot for the explanation! I will accept egreg's answer because it solves the issue, ok? However seeing how fragile this is I think I will un-disable \par. Doesn't look that good an idea anymore... – LaTeXer May 28 at 12:12
  • @LaTeXer oh no, disaster! (giving the tick to egreg:-) – David Carlisle May 28 at 12:13
  • Oh no! :) Your answer is more interesting, I must say ;) – LaTeXer May 28 at 12:24

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.