GeneralCalculating \parshape

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
robertjlee
Posts: 17
Joined: Thu Aug 07, 2008 7:51 pm

Calculating \parshape

Post by robertjlee »

I'm experimenting with changing the shape of paragraphs inside a LaTeX document.

I currently have a command (called from \everypar) that generates the \parshape arguments, and executes it by outputting it to a file and then using \input. I'm sure it could be improved by using either \aftergroup or token registers, but I haven't had any luck in getting that to work yet.

The \input method works well for the most part, but breaks when using a verbatim environment. TeX generates the following error:

ERROR: TeX capacity exceeded, sorry [text input levels=127].

What seems to be happening is that the \begin{verbatim} command is somehow causing the \parshape inside my everypar to be re-evaluated (possibly by throwing a new paragraph), resulting in a loop that only breaks when TeX's file input limit is hit.

Having looked at all the documentation I can find (including the TeX book and the source for the verbatim package), I haven't figured out how this could be happening.

I have attached a minimum example to demonstrate the problem.

Can anyone suggest why this could be happening? Could I fix the problem by writing out the \input, and if so should I use \aftergroup or a token register of some kind?

Many thanks in advance for any help or advice.
Attachments
broken.tex
(1.45 KiB) Downloaded 349 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

robertjlee
Posts: 17
Joined: Thu Aug 07, 2008 7:51 pm

Re: Calculating \parshape

Post by robertjlee »

I can't say that I understand the problem, but I now have a workaround.

The \@verbatim command (called at the start of a verbatim environment) does, indeed, throw a new paragraph (potentially up to two), using the \@@par command, and it does so to prevent any current \parshape from taking effect.

My solution is to use the \every@verbatim token register hook to set a flag that prevents the \parshape command from being output (with effect in the current environment, i.e. the verbatim environment). This effectively lets verbatim control its own paragraph shapes while everything else falls under my "normal" \parshape's control.

I am a little worried that there may be other packages that do similar things, and I still can't say that I understand why the \parshape called from \everypar was causing the \@verbatim command to be re-executed, but this solution seems to be working for now.
Post Reply