16

Consider the following FMWE (Fairly Minimal Working Example):

\documentclass[a4paper]{article}
\usepackage{kantlipsum,xgalley}
\usepackage[scale=.8]{geometry}
\pagestyle{empty}
\ExplSyntaxOn
\NewDocumentCommand\resetindents { }
{
  \galley_parshape_set_multi:nnnN { 0 } { 0pt } { 0pt } \c_true_bool
}
\NewDocumentCommand\cutleft { m m }
{
  \galley_cutout_left:nn { #1 } { #2 }
}
\NewDocumentCommand\cutright { m m }
{
  \galley_cutout_right:nn { #1 } { #2 }
}
\ExplSyntaxOff
\begin{document}
% \ExplSyntaxOn
\cutleft{0}{25mm,25mm,25mm,25mm,25mm,25mm,25mm,25mm}
This is an extremely short paragraph.

\kant[4]

\cutright{4}{25mm,25mm,25mm,25mm,25mm,25mm}
\kant[5]
% \resetindents

\kant[6-7]

% \ExplSyntaxOff
\end{document}

The expected-by-me output from this code is

expected

The actual output is

actual

Is there a correct way to achieve the expected output without modifying the body of the document?

Note that either of the following two modifications to the body is sufficient to achieve the desired result:

  1. uncomment the line

    % \resetindents
    
  2. uncomment the lines

    % \ExplSyntaxOn
    

    and

    % \ExplSyntaxOff
    

which is why those lines are there in the source.

However, only \resetindents truly seems to resolve the problem since the following example also gives the actual, undesired output.

\begin{document}
\ExplSyntaxOn
\cutleft{0}{25mm,25mm,25mm,25mm,25mm,25mm,25mm,25mm}
This is an extremely short paragraph.\par
\kant[4]
\cutright{4}{25mm,25mm,25mm,25mm,25mm,25mm}
\kant[5]
% \resetindents
\kant[6-7]
\ExplSyntaxOff
\end{document}

Apparently, the removal of blank lines from the source prevents the switch to expl3 syntax from avoiding the problem. Moreover

\begin{document}
\ExplSyntaxOn
\cutleft{0}{25mm,25mm,25mm,25mm,25mm,25mm,25mm,25mm}
This is an extremely short paragraph.\par
\kant[4]\par
\cutright{4}{25mm,25mm,25mm,25mm,25mm,25mm}
\kant[5]\par
% \resetindents
\kant[6-7]\par
\ExplSyntaxOff
\end{document}

also demonstrates the problem.

Hence \resetindents appears to be necessary, but I think that the philosophy of galleys suggests that it ought not be.

I am curious to know how the pattern of cuts is determined. For example,

\begin{document}
\cutleft{0}{25mm,25mm,25mm,25mm,25mm,25mm,25mm,25mm}
This is an extremely short paragraph.\par
\kant[4]

\cutright{4}{25mm,25mm,25mm,25mm,25mm,25mm}

\kant[5-6]

\kant[7]
\end{document}

does not repeat the cut until the final paragraph

final only

while

\begin{document}
\cutleft{0}{25mm,25mm,25mm,25mm,25mm,25mm,25mm,25mm}
This is an extremely short paragraph.\par
\kant[4]

\cutright{4}{25mm,25mm,25mm,25mm,25mm,25mm}

\kant[5]

\kant[6]

\kant[7]
\end{document}

repeats the cut in the final two paragraphs

final two

In no case is the most recent cut repeated, as that would produce a cut on the right. What seems crucial is that the cut which is repeated spans more than a single paragraph.

\begin{document}
\cutright{0}{25mm,25mm,25mm,25mm,25mm,25mm,25mm,25mm}
This is an extremely short paragraph.
Perhaps we should make it a bit longer just to see what happens to things in that case.\par
\kant[4]

\cutleft{4}{25mm,25mm,25mm,25mm,25mm,25mm}

\kant[5]

\kant[6]

\kant[7]
\end{document}

cut again on right

However, at least the effect isn't cumulative.

\begin{document}
\cutright{0}{25mm,25mm,25mm,25mm,25mm,25mm,25mm,25mm}
This is an extremely short paragraph.
Perhaps we should make it a bit longer just to see what happens to things in that case.\par
\kant[4]

\cutleft{4}{25mm,25mm,25mm,25mm,25mm,25mm}
This is another extremely short paragraph.

\kant[5]

\kant[6]

\kant[7]
\end{document}

non-cumulative repeating cuts

Please note that

  • I know perfectly well that l3galley is experimental and that it is expected to break if you try to use it in all kinds of weird and wonderful ways. Consider this a guided adventure through a small part of the weirdnesses and wonders which result.

  • I am also aware that weirdness and wonderment are very much in the eye of the beholder. It is perfectly possible that the effect I consider unexpected is, in fact, a design feature highly prized by the developers who spent long hours poured over a hot keyboard desperately trying to get the cutouts to repeat according to a precise algorithm, however obscure its pattern might be to me. TeX is Mystery (how else to describe the summoning of typographic spirits by strange mixes of miniscules and majuscules?) and I would be disappointed if that mystery were to entirely disappear in its descendants.

2
  • 2
    Looks like a bug: I'll take a look over the set up
    – Joseph Wright
    Jun 11 '16 at 7:25
  • 1
    @JosephWright Thanks. This is what I was trying to ask about in the comment on the other question, but I explained it wrongly.
    – cfr
    Jun 11 '16 at 12:08
8

This was due to a bug in l3galley. In the demo, the \parshape is set up at the top level, then the cutout is 'used up' inside a group (invisible here but present as \kant applies \par inside a group). After the group, the \parshape was not reset as l3galley tries to avoid doing this were not required (there is not cutout actually present and no other margin or whatever is being set up).

The code has now been modified to detect that the cutout is still 'active' and requires \parshape setting if \par occurs and is not at the top group level. This fix will appear in the next expl3 update, likely later this week (mid June 2016).

2
  • @JosephWright I have been thinking about something: Is it really a good idea to have \galley_cutout_right:nn and \galley_cutout_left:nn work additively, adding each cutout to the previous existing cutouts? I would find it much more natural and useful if the cut out space was the maximum of all cutouts rather than the sum. That way, if I add two figures closely to each other, I don’t run the risk of cutting out too much space on the line where they meet. Not sure if you follow? If not, I can provide you with a visual example in a dedicated post.
    – Gaussler
    Jun 14 '16 at 9:02
  • @Gaussler This is all experimental code so certainly is meant as much for discussion as anything else. The format here doesn't really work well for that: chat might be OK but ideally post something to the LaTeX-L mailing list.
    – Joseph Wright
    Jun 14 '16 at 9:22

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.