4

This is a continuation from another question, but the original issue there is (kind of) resolved.

For this question you need XeTeX, Minion Pro, which is shipped with Adobe Reader. greybox.png can be obtained here and background grid is taken from this answer.

The code is as follows:

\newbox\gridbox
\setbox\gridbox\line{%
  \special{color push rgb .8 .8 1}%
  \vrule height\baselineskip width0pt \hrulefill
  \special{color pop}}
\def\grid{\vtop to0pt{\hrule height0pt\kern-\dimexpr\baselineskip-\topskip\topskip=10pt\relax
    \vbox to\dimexpr\vsize+2pt\relax{\leaders\copy\gridbox\vfil}\vss}}
\def\pagebody{\vbox to\vsize{\boxmaxdepth=\maxdepth \grid\pagecontents}}

\parskip=0pt \frenchspacing \raggedbottom
\parindent=1pc

\font\rm="Minion Pro:+onum,+pnum:mapping=tex-text" at 10pt
\font\it="Minion Pro/I:+onum,+pnum:mapping=tex-text" at 10pt
\rm

\footline={\hfil\rm\folio\hfil}

\newcount\shapenum \newcount\tempnum \newcount\globpar
\newdimen\ii \newdimen\ww
\newdimen\picwidth  \newbox\picbox
\catcode`\@=11  
\def\oblom #1 from #2 indent #3 {\par \ii=#1 \ww=\hsize
   \ifdim\ii>\z@ \advance\ww by-\ii      
   \else \advance\ww by\ii \ii=\z@ \fi
   \shapenum=1 \tempnum=0 \def\shapelist{}
   \loop \ifnum\shapenum<#2 \edef\shapelist{\shapelist\z@\hsize}
      \advance\shapenum by1 \repeat
   \loop \edef\shapelist{\shapelist\ii\ww}
      \advance\tempnum by1 \ifnum\tempnum<#3 \repeat
   \advance\shapenum by#3 \edef\shapelist{\shapelist\z@\hsize}
   \doshape}  
\catcode`\@=12
\def\doshape{\globpar=0 \def\par{\ifhmode\shapepar\fi}}
\def\shapepar{\prevgraf=\globpar \parshape\shapenum\shapelist
   \endgraf \globpar=\prevgraf
   \ifnum \prevgraf>\shapenum \global\let\par=\endgraf \doshapeA \fi}

\ifx\XeTeXpicfile\undefined 
   \def\pic #1{\hbox{\pdfximage width\picwidth {#1}\pdfrefximage\pdflastximage}}
\else
   \def\pic #1{\hbox{\XeTeXpicfile #1 width\picwidth}}
\fi

\def\\{\par}
\def\flowpic from #1 minus #2 width #3 #4#5{\par
   \dimen0=#3 \ifdim\dimen0<0pt \dimen0=-\dimen0 \fi
   %\advance\dimen0 by -1pc %(margin around picture)
   % create this margin differently: add margin to #3
   \dimen2=#3 \ifdim\dimen2<0pt \advance\dimen2 by -1pc
                          \else \advance\dimen2 by  1pc \fi
   \picwidth=\dimen0
   \setbox0=\vbox{\hsize\picwidth\pic{#4}%\kern .7mm 
                  \emergencystretch=2em \noindent\it #5\par}
   \dimen0=\ht0 
   \divide\dimen0 by\baselineskip \advance\dimen0 by1sp
   \advance\dimen0 by -#2sp
   \oblom \dimen2 from #1 indent \dimen0
   \advance\dimen0 by #2sp
   \multiply\dimen0  by\baselineskip
   \setbox\picbox=\vbox to\dimen0{\vss\box0}
   \dimen0=\pagegoal \ifdim\pagegoal=\maxdimen \dimen0=\vsize\fi   
   \advance\dimen0 by-\pagetotal \advance\dimen0 by-#1\baselineskip
   \ifdim\dimen0<0pt 
      \def\doshapeA{\tempnum=\prevgraf \advance\tempnum by-#1 \advance\tempnum by2
         \line{\ifdim#3<0pt \hfill\fi \vbox to0pt{\vss\vtop to0pt{\kern0pt\box\picbox\vss}%
                   \kern\the\tempnum\baselineskip}\hfil}
         \nobreak\vskip-\baselineskip
      }
   \else \def\doshapeA{}
      \line{\ifdim#3<0pt \hfill\fi 
            \vtop to0pt{\kern-2\baselineskip\kern#1\baselineskip\box\picbox\vss}\hfil}
      \nobreak\vskip-\baselineskip
   \fi
}

\noindent
A work in progress, {\tt JSBox} is a self-contained
library---written in portable C---that instantiates sandbox-able,
\TeX-language interpreters within the memory space
of any C, Objective-C, or C++ 32- or 64-bit client
program. Built and documented anew, {\tt JSBox}
is faithful to the \TeX\ language's primitives,
syntax, typesetting algorithms, measurements, data
structures, and speed. At the same time, it fixes---in an
upwardly compatible manner---a variety of important
problems with or lacunæ in the current \TeX\ engine's
implementation. These include integral support for
21-bit Unicode, namespaces, OpenType font tables
and metrics, job-specific 8-bit to 21-bit Unicode
mapping, run-time settable compatibility levels,
full 32-bit fixed-point math, and more.
Especially pertinent to interactive applications---such as an
eBook reader---is that all of a document's pages can
optionally be kept as \TeX\ data structures in memory
after a job is done, with direct random access of any
requested page exported to the client program's screen
without file I/O or DVI or PDF conversion if unneeded.
Tracing (including recursive expansion, re-tracing
interrupted commands, alignments, math, etc.) and
all error messages have been significantly improved
over what \TeX\ does. The author will demo what
{\tt JSBox} can do now, and discuss what it
could do in the future.

A work in progress, {\tt JSBox} is a self-contained
library---written in portable C---that instantiates sandbox-able,
\TeX-language interpreters within the memory space
of any C, Objec\-tive-C, or C++ 32- or 64-bit client
program. Built and documented anew, {\tt JSBox}
is faithful to the \TeX\ language's primitives,
syntax, typesetting algorithms, measurements, data
structures, and speed. At the same time, it fixes
in an
upwardly compatible manner---a variety of important
problems with or lacunæ in the current \TeX\ engine's
implementation. These include integral support for
21-bit Unicode, namespaces, OpenType font tables
and metrics, job-specific 8-bit to 21-bit Unicode
mapping, run-time settable compatibility levels,
full 32-bit fixed-point math, and more. Especially
pertinent to interactive applications---such as an
eBook reader---is that all of a document's pages can
optionally be kept as \TeX\ data structures in memory
after a job is done, with direct random access of any
requested page exported to the client program's screen
without file I/O or DVI or PDF conversion if unneeded.
Tracing (including recursive expansion, re-tracing
interrupted commands, alignments, math, etc.) and
all error messages have been significantly improved
over what \TeX\ does. The author will demo what
{\tt JSBox} can do now, and discuss what it
could do in the future.

\flowpic from 11 minus 0 width -7cm {greybox.png}{The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.}
A work in progress, {\tt JSBox} is a self-contained
library---written in portable C---that instantiates sandbox-able,
\TeX-language interpreters within the memory space
of any C, Objective-C, or C++ 32- or 64-bit client
program. Built and documented anew, {\tt JSBox}
is faithful to the \TeX\ language's primitives,
syntax, typesetting algorithms, measurements, data
structures, and speed. At the same time, it fixes---in an
upwardly compatible manner---a variety of important
problems with or lacunæ in the current \TeX\ engine's
implementation. These include integral support for
21-bit Unicode, namespaces, OpenType font tables
and metrics, job-spe\-cific 8-bit to 21-bit Unicode
mapping, run-time settable compatibility levels,
full 32-bit\nobreak\ fixed-point math, and more.
Especially pertinent to interactive applications---such as an
eBook reader---is that all of a document's pages
can optionally be kept as \TeX\ data structures in memory
after a job is done, with direct random access of any
requested page exported to the client program's screen
without file I/O or DVI or PDF conversion if unneeded.
Tracing (including recursive expansion, re-tracing
interrupted commands, alignments, math, etc.) and
all error messages have been significantly improved
over what \TeX\ does. The author will demo what
{\tt JSBox} can do now, and discuss what it
could do in the future.

A work in progress, {\tt JSBox} is a self-contained
library---written in portable C---that instantiates sandbox-able,
\TeX-language interpreters within the memory space
of any C, Objective-C, or C++ 32- or 64-bit client
program. Built and documented anew, {\tt JSBox}
is faithful to the \TeX\ language's primitives,
syntax, typesetting algorithms, measurements, data
structures, and speed. At the same time, it fixes---in an
upwardly compatible manner---a variety of important
problems with or lacunæ in the current \TeX\ engine's
implementation. These include integral support for
21-bit Unicode, namespaces, OpenType font tables
and metrics, job-specific 8-bit to 21-bit Unicode
mapping, run-time settable compatibility levels,
full 32-bit fixed-point math, and more. 
These include integral support for
21-bit Unicode, namespaces, OpenType font tables
and metrics, job-specific 8-bit to 21-bit Unicode
mapping, run-time settable compatibility levels,
full 32-bit fixed-point\nobreak\ math, and more. These include integral support for
21-bit Unicode,{\parfillskip=0pt\par}
\flowpic from 1 minus 0 width -7cm {greybox.png}{The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.}
\noindent namespaces, OpenType font tables
and metrics, job-specific 8-bit to 21-bit Unicode
mapping, run-time settable compatibilitylevels,
full 32-bit fixed-point math, and more. Especially
pertinent to interactive applications---such as an
eBook reader---is that all of a document's pages can
optionally be kept as \TeX\ data structures in memory
after a job is done, with direct random access of any
requested page exported to the client program's screen
without file I/O or DVI or PDF conversion if unneeded.
Tracing (including recursive expansion, re-tracing
interrupted commands, alignments, math, etc.) and
all error messages have been significantly improved
over what \TeX\ does. The author will demo what
{\tt JSBox} can do now, and discuss what it
could do in the future.

A work in progress, {\tt JSBox} is a self-contained
library---written in portable C---that instantiates sandbox-able,
\TeX-language interpreters within the memory space
of any C, Objective-C, or C++ 32- or 64-bit client
program. Built and documented anew, {\tt JSBox}
is faithful to the \TeX\ language's primitives,
syntax, typesetting algorithms, measurements, data
structures, and speed. At the same time, it fixes---in an
upwardly compatible manner---a variety of important %\nobreak\
problems with or lacunæ in the current \TeX\ engine's
implementation. These include integral support for
21-bit Unicode, namespaces, OpenType font tables
and metrics, job-specific 8-bit to 21-bit Unicode
mapping, run-time settable compatibility levels,
full 32-bit fixed-point math, and more. Especially
pertinent to interactive applications---such as an
eBook reader---is that all of a document's pages can
optionally be kept as \TeX\ data structures in memory
after a job is done, with direct random access of any
requested page exported to the client program's screen
without file I/O or DVI or PDF conversion if unneeded.
Tracing (including recursive expansion, re-tracing
interrupted commands, alignments, math, etc.) and
all error messages have been significantly improved
over what \TeX\ does. The author will demo what
{\tt JSBox} can do now, and discuss what it
could do in the future.
\bye

As you can see, the picture on page 2 is moved to the left:

example image

(also note the wider caption below the picture). The strange thing is that when I remove the (re)declaration of \rm, so cmr10 is used, the image isn't moved to the left (the use of Minion Italic in the caption apparently doesn't matter).

Why is this? Is this a bug in XeTeX?

  • It seems that there is a little bug in your modification of the macro \flowpic. The \par token at the end of the \vbox (... \noindent\it #5\par}...) is the source of the problem: this token is temporary redefined as a macro and it works as this (unwanted) macro when caption is formatted. Remove this token \par. The end of paragraph is processed at the end of \vbox without explicitly \par token, so it needn't to be here. Or replace the token \par by \endgraf here. – wipet Dec 30 '14 at 16:02
  • @wipet Indeed. But why doesn't it cause this issue when cmr10 is used? Anyway, post it as an answer and I'll happily mark it. BTW, I like your philosophy regarding TeX vs. LaTeX as described in your bio: I hate black boxes I don't understand and, in the worst case, conflict with eachother. – Marcel Korpel Dec 30 '14 at 16:50
  • I have no Minion Pro font. I tried to modify your text with cmr10 in order to get the same problem. It was somewhat problematic because the line-break points are different and page-break depends on line-breaks due to \brokenpenalty register. But I was successful after little tests with cmr10 only. – wipet Dec 31 '14 at 03:56

1 Answers1

4

The core of the problem is the \par token at line 54 of your code:

   \setbox0=\vbox{\hsize\picwidth\pic{#4}%\kern .7mm 
                  \emergencystretch=2em \noindent\it #5\par}

The \oblom macro temporary redefines \par token in order to reset \parshape parameters for next paragraph if the indentation isn't finished. This is the reason why \oblom works in more than one paragraph. Note, that normal TeX \par removes \parshape settings definitely, so it cannot be used across more paragraphs without redefinition of \par.

So, the \par in your code at line 54 is expanded as a macro and this is the reason of broken typesetting. Solution: simply remove \par here, because the creating of paragraph is invoked at the end of \vbox automatically if horizontal mode is detected here. And this is an exception from another auto-\par processing: in TeX no \par token is inserted here (on the other hand \par token is inserted before \vskip, \end, etc. primitives by these primitives, pages 90--91 in TeXbook naruby).

You can object that the \par needn't to be redefined here because all indented lines from previous paragraphs were printed and the \par would be restored by

\ifnum \prevgraf>\shapenum \global\let\par=\endgraf \doshapeA \fi}

This is true, but there is a little bug in this code, because we need to say \ifnum\prevgraf>=\shapenum... which can be coded by:

\ifnum \prevgraf<\shapenum\else \global\let\par=\endgraf \doshapeA \fi}

I detected this bug in my code of the \oblom macro thanks your problem. Thank you, I'll correct this in the errata of TeXbook naruby.

wipet
  • 74,238
  • You're welcome. And I noticed that I can get paragraphs within the caption text (parameter #5) when I do \let\\=\par outside of \oblom and then I can use \\ inside the actual parameter without unwanted side-effects. – Marcel Korpel Dec 31 '14 at 12:53
  • That \\ should be two backslashes, of course, but the second one is eaten as an escape character in markdown. – Marcel Korpel Dec 31 '14 at 13:00
  • @MarcelKorpel Use \let\\=\endgraf instead \let\\=\par, because \endgraf is saved "original meaning" of \par. – wipet Dec 31 '14 at 14:37