¿Cómo alinear las líneas de base del texto de la imagen y el texto del cuerpo?

¿Cómo alinear las líneas de base del texto de la imagen y el texto del cuerpo?

El siguiente código envuelve el texto del cuerpo alrededor de una imagen y el texto que la acompaña. Colóquelo de esta manera (con la \vfills) para que la imagen y el texto queden centrados verticalmente en el hueco.

Lo que quiero lograr es alinear el texto debajo de la imagen con la cuadrícula de referencia (bajando ambos). Si omito el último \vfilldentro del tercer parámetro, \figflowel texto se establece en un nivel demasiado bajo.

Recursos: estoy usando XeTeX (para incluir la imagen),figflow.tex,cajagris.pngy cuadrícula de fondo tomada deesta respuesta.

\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}}

\input figflow
\parskip=0pt \frenchspacing \raggedbottom
\font\smallrm=cmr8

\def\includegraphics#1#2#3#4{
{\parfillskip=0pt\par}\dimen0=#1
\dimen1=#2
\advance\dimen0 by 1pc
\setbox0=\vbox to #2{\hsize=#1
\XeTeXpicfile #3 width #1 height #2}
\setbox1=\vbox{\hsize=#1{\noindent\it #4\par}}
\advance\dimen1 by \ht1
\divide\dimen1 by \baselineskip
\multiply\dimen1 by \baselineskip
\advance\dimen1 by \baselineskip
\setbox2=\vbox to \dimen1{\vfil\box0\vskip2mm\box1}
\figflow{\dimen0}{\dimen1}{\vfill\box2\vfill}\noindent\ignorespaces}

\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\ae\ 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.%
\includegraphics{7cm}{7cm}{greybox.png}{Lorem ipsum dolor sit
amet, consectetur adipiscing elit. Donec a diam lectus.}
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\ae\ 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

ACTUALIZAR:

Enestecaso, donde \baselineskipy el tamaño de fuente en el texto debajo de la figura es el mismo que el del cuerpo del texto, logré alinear las líneas de base cambiando la \figflowlínea a

\figflow{\dimen0}{\dimen1}{\vfill\box2\vskip0pt}\noindent\ignorespaces}

¿Por qué funciona insertar un \vskipespacio vacío? Tenga en cuenta que no funciona con otros tamaños de fuente, ni con otros \baselineskipcorreos electrónicos, ni siquiera al insertar \strutcorreos electrónicos dentro o fuera del grupo dentro del cuadro 1.

ACTUALIZACIÓN 2:

Gracias a la respuesta de Wipet, creé otro MWE con un caso no tan infrecuente: cuando la imagen y el título deben estar en la esquina inferior derecha (o izquierda) de una página:

\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}}

\input figflow
\parskip=0pt \frenchspacing \raggedbottom
\font\smallrm=cmr8

\def\includegraphics#1#2#3#4{%
   {\parfillskip=0pt\par}
   \dimen0=#1 \ifdim#1<0pt \dimen0=-\dimen0 \fi
   \dimen1=#2 
   \dimen2=#1 \advance\dimen2 by \ifdim#1<0pt-\fi 1pc
   \setbox0=\vbox {\XeTeXpicfile #3 width\dimen0 height #2}
   \setbox1=\vbox{\hsize=\dimen0 \baselineskip=9.5pt\noindent\smallrm #4\par} 
   \advance\dimen1 by \ht1
   \divide\dimen1 by \baselineskip
   \multiply\dimen1 by \baselineskip
   \advance\dimen1 by 1\baselineskip
   \setbox2=\vbox to\dimen1{\vss\box0\vskip2mm\box1}
   \figflow{\dimen2}{\dimen1}{}%
   \line{\ifdim#1<0pt\hfill\fi\vtop to0pt{\kern0pt\box2\vss}\hfil}
   \nobreak\vskip-\baselineskip
   \noindent\ignorespaces}

\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\ae\ 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, 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\ae\ 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, 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\ae\ 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%
\includegraphics{-7cm}{7cm}{greybox.png}{Lorem ipsum dolor sit
amet, consectetur adipiscing elit. Donec a diam lectus.}
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\ae\ 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

El problema es (creo) que en algún lugar \baselineskipse inserta a que se deshace usando \vskip-\baselineskipal final de la macro. Eso \baselineskiphace que la imagen completa y el texto junto a la imagen aparezcan en la página siguiente. Al mover la llamada a \includegraphicsuna línea (antes Especially …), la imagen aparece en la primera página, pero con una línea de texto del cuerpo debajo de la imagen y el texto del título.

ACTUALIZACIÓN 3:

La expulsión de la página se realizó al insertar la imagen en figflow.tex. Agregué un \nobreaken un momento (marcado con ^^^) y la expulsión desapareció:

% FIGFLOW:  plain TEX macro by Ian Hutchinson, 21 Oct 95.
% Copyright 1995 Ian Hutchinson.
% You may freely use, modify, and/or distribute this file, without limitation.
% Make text flow round figure.
% Usage: \figflow{<width>}{<height>}{<[Figure+][Caption]>}
% at start of new paragraph. Figure top starts at insert.
% #1 figure width dimen. If negative, fig on right, else left.
% #2 figure height (including caption) dimen. (E.g.: 4 truein)
% #3 \special for figure if desired, then \vfill caption. (Both optional).
% Example: figflow{4 truein}{5 truein}{\epsfbox{figure.ps}\vfill Figure 1.}
% User is responsible for the figure fitting within the space defined.
% If figure won't fit on page, it is moved over the page break.
% If a new figflow starts before the old one is finished, a message is given
% and the second figure is skipped. Fix manually.
% Does not work for Latex.

\newdimen\pageremains\newdimen\pdepth
\newdimen\figwidth
\newdimen\figheight
\newcount\figlines
\newcount\flevel

\def\figflow#1#2#3{
\ifnum\flevel>0
\message{******Figure collision. Ignoring second figure.******}
\else
\figwidth=#1
\figheight=#2
\def\contents{#3}
% Put figure contents in an appropriate box.
\def\figure{\let\temp=\par \let\par=\plainpar
  \line{\overfullrule=0pt%  Avoid black box.
   \ifdim \figwidth<0pt \hsize=-\figwidth \hss\else \hsize=\figwidth\fi
   \advance \hsize by -10pt% Give a little extra hspace.
   \vbox to \figheight{\vfil\noindent\contents}
   \ifdim \figwidth>0pt \hss\fi
  }\nobreak\vskip-\figheight
%  ^^^^^^^^ inserted by MK
  \let\par=\temp%
}
% […] remainder of file is the same

El único problema que existe ahora es que las dos últimas líneas de la página se mueven a la siguiente (incluido el acortamiento). Creo que tiene algo que ver con \widowpenaltyy \clubpenalty, pero modificar esas variables no resolvió el problema.

También se agradece cualquier mejor solución a los problemas antes mencionados.

ACTUALIZACIÓN 4:

Agregar manualmente un \nobreak\̺después de la última palabra en el cuerpo del texto de la primera página (es decir, después de a variety of important) de hecho resuelve el problema mencionado en la actualización 3, pero ahora también está prohibido un salto de línea en este punto, lo que resulta en una línea (demasiado) apretada y separación de palabras innecesaria. ¿Cómo solucionar esto y, por supuesto, cómo automatizarlo?

ACTUALIZACIÓN 5:

Al hacer algún tipo de prueba de estrés me encontré con otro problema. Agregué dos macros \toppicturey \midpictureagregué respectivamente una \ejecto una \parantes de comenzar \includegraphics(no evite este código por su longitud, la mayor parte es texto ficticio):

\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}}

\input figflow
\parskip=0pt \frenchspacing \raggedbottom
\widowpenalty=10000 \clubpenalty=10000
\font\smallrm=cmr8

%\toppicture params:
%  #1 <dimen>  width of picture
%  #2 <dimen>  height of picture
%  #3 <string> file name
%  #4 <string> caption text
\def\toppicture#1#2#3#4{%
   {\parfillskip=0pt\par}\eject%
   \includegraphics{#1}{#2}{#3}{#4}
}

%\midpicture params:
%  #1 <dimen>  width of picture
%  #2 <dimen>  height of picture
%  #3 <string> file name
%  #4 <string> caption text
\def\midpicture#1#2#3#4{%
   {\parfillskip=0pt\par}
   \includegraphics{#1}{#2}{#3}{#4}
}

\def\includegraphics#1#2#3#4{%
   \dimen0=#1 \ifdim#1<0pt \dimen0=-\dimen0 \fi
   \dimen2=#2 
   \dimen4=#1 \advance\dimen4 by \ifdim#1<0pt-\fi 1pc
   \setbox0=\vbox {\XeTeXpicfile #3 width\dimen0 height #2}
   \setbox2=\vbox{\hsize=\dimen0 \baselineskip=9.5pt\noindent\smallrm #4\par} 
   \advance\dimen2 by \ht2
   \divide\dimen2 by \baselineskip
   \multiply\dimen2 by \baselineskip
   \advance\dimen2 by \baselineskip
   \setbox4=\vbox to\dimen2{\vss\box0\vskip2mm\box2}
   \figflow{\dimen4}{\dimen2}{}
   \line{\ifdim#1<0pt\hfill\fi\vtop to0pt{\kern0pt\box4\vss}\hfil}
   \nobreak\vskip-\baselineskip
   \noindent\ignorespaces}

\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\ae\ 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, 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\ae\ 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, 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\ae\ 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
\midpicture{-7cm}{7cm}{greybox.png}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.}
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\ae\ in the current \TeX\ engine's
implementation. These include integral support for
21-bit Unicode,
%\midpicture{7cm}{7cm}{greybox.png}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.}
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 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 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 
\midpicture{7cm}{7cm}{greybox.png}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.}
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.

%\toppicture{7cm}{7cm}{greybox.png}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.}
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\ae\ 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

Primero, comenta la segunda \midpicturesalida (debe estar en la línea 169) y ejecuta XeTeX. De una forma u otra, ahora puedo omitir los cambios que hice en la actualización 3 (agregándolos \nobreaka figflow.tex) y la actualización 4 (agregándolos \nobreak\a la copia fuente) y todo está bien escrito. Esto es muy extraño, ya que no cambié nada más, hasta donde yo sé. El texto fluye correctamente alrededor de la imagen y el título de la misma.

Por favor, ahora descomente la \midpicturellamada que acaba de comentar y ejecute TeX nuevamente. Ahora se queja de insertar un }justo antes de un \endgroup. Eso me suena extraño. ¿Qué pasa aquí?

En tercer lugar, comente esa línea nuevamente y descomente la \midpicturelínea 149. Ahora figflow.tex se quejará de una colisión de figuras, probablemente porque no terminó de procesar las líneas al lado de la primera imagen, aunque llamé a la \midpicturemacro después de la última palabra de la fila. . Esto implica que no se pueden colocar dos imágenes inmediatamente una debajo de la otra (no deberían chocar). ¿Cómo evitar esta colisión?

Cuarto, comente la línea 149 nuevamente y descomente la única \toppicture, en la línea 178. Por extraño que parezca, esta vez TeX no se ahoga en una segunda llamada para \figflowdar me gusta cuando se descomentó la línea 169. El resultado son dos páginas correctamente escritas y una nueva página con la imagen en la parte superior izquierda. Sólo que ahora todo (el texto del cuerpo, la imagen y el título de la imagen) está ligeramente fuera de la red. ¿Qué pasa aquí?

Respuesta1

Sugiero usar el \figflowúnico para crear el espacio apropiado para la imagen y colocar la imagen bajo nuestro control.

\def\includegraphics#1#2#3#4{
{\parfillskip=0pt\par}\dimen0=#1
\dimen1=#2
\advance\dimen0 by 1pc
\setbox0=\vbox to #2{\hsize=#1
\XeTeXpicfile #3 width #1 height #2}
\setbox1=\vbox{\hsize=#1{\noindent\it #4\par}}
\advance\dimen1 by \ht1
\divide\dimen1 by \baselineskip
\multiply\dimen1 by \baselineskip
\advance\dimen1 by 1\baselineskip
\setbox2=\vbox to \dimen1{\vfil\box0\vskip2mm\box1}
   % PO changes in OP's code: 
  \figflow{\dimen0}{\dimen1}{}%
  \vtop to0pt{\kern0pt\box2\vss}\nobreak\vskip-\baselineskip
\noindent\ignorespaces}

Si configura \kern-\baselineskipen lugar de \kern0ptdentro \vtop, la imagen se colocará en una línea.

Editar: considerando el comentario, agregué una segunda versión del código, donde el \baselineskiptexto debajo de la imagen puede ser arbitrario y el primer parámetro de la \includegraphicsmacro puede ser negativo. Luego, el \dimen0valor absoluto de este parámetro y se \dimen2introduce nuevamente como #1más o menos 1pc (agrega el margen dependiendo del signo de #1).

\def\includegraphics#1#2#3#4{%
   {\parfillskip=0pt\par}
   \dimen0=#1 \ifdim#1<0pt \dimen0=-\dimen0 \fi
   \dimen1=#2 
   \dimen2=#1 \advance\dimen2 by \ifdim#1<0pt-\fi 1pc
   \setbox0=\vbox {\XeTeXpicfile #3 width\dimen0 height #2}
   \setbox1=\vbox{\hsize=\dimen0 \noindent\it #4\par} 
   \advance\dimen1 by \ht1
   \divide\dimen1 by \baselineskip
   \multiply\dimen1 by \baselineskip
   \advance\dimen1 by 1\baselineskip
   \setbox2=\vbox to\dimen1{\vss\box0\vskip2mm\box1}
   \figflow{\dimen2}{\dimen1}{}%
   \line{\ifdim#1<0pt\hfill\fi\vtop to0pt{\kern0pt\box2\vss}\hfil}
   \nobreak\vskip-\baselineskip
   \noindent\ignorespaces}

Editar2:Teniendo en cuenta las actualizaciones de tu pregunta, decidí que puedes probar la macro.\oblom de mi libro.TeXbook narubí(páginas 236 y 237). La versión completa en PDF de este libro está disponible pero sólo en checo.

El nombre de la macro \oblomse deriva de la palabra checa "componer algo". Esta macro crea un espacio rectangular en blanco en el siguiente párrafo (o más párrafos). Mi siguiente código aquí usa esta macro (pero cambia el nombre de las palabras separadoras). El uso de esta macro es:

\oblom <width> from <linenum1> indent <linenum2>

donde <width>es el ancho del espacio rectangular, <linenum1>es el número de la primera línea sangrada y <linenum2>es el número de líneas sangradas. Si <width>es negativo, entonces el espacio rectangular estará en el lado derecho. Por ejemplo:

\oblom 5cm from 3 indent 5

significa que cinco líneas tendrán una sangría de 5 cm desde la tercera línea (incluida esta). Las dos primeras líneas no tienen sangría y tienen su ancho normal.

La macro \oblomdebe usarse entre párrafos e influye en la forma del siguiente párrafo o más. La principal ventaja es que no es necesario detener el párrafo exactamente en el lugar donde comienza la sangría. Tenga en cuenta sus ejemplos anteriores donde debe hacer {\parfillskip=0pt\par}lo que trae complicaciones.

Mi siguiente código usa \oblomy define la macro \flowpic:

\flowpic from <linenum> width <width> {<picfile>} {<caption>}

Por ejemplo

\flowpic from 3 width -7cm {greybox.png}
    {Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.}

inserta la imagen greybox.pngcon el título dado de la tercera línea del siguiente párrafo en el lado derecho. El ancho de la imagen será de 7 cm menos 1 pieza porque 1 pieza es el margen entre la imagen y el texto. No es necesario utilizar el paquete figflow.

El código consta de tres partes. La primera parte es la definición de\oblom macro copiada deTeXbook narubí. Esta macro calcula \parshapeparámetros y usos \parshape. La segunda parte define la macro \picpara la inserción de imágenes con un ancho determinado. Las definiciones dependen del hecho de que XeTeX se utilice o no. La tercera parte declara \flowpicqué utiliza \oblomy \pic. La macro flowpic inserta la imagen en la misma página donde se usa si hay suficiente espacio. De lo contrario, flowpic inserta la imagen en la página siguiente, donde terminan los últimos párrafos con la forma modificada.

\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\else \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\flowpic from #1 width #2 #3#4{\par
   \dimen0=#2 \ifdim\dimen0<0pt \dimen0=-\dimen0 \fi
   \advance\dimen0 by -1pc %(margin around picture)
   \picwidth=\dimen0
   \setbox0=\vbox{\hsize\dimen0 \pic{#3}\kern 2mm 
                  \emergencystretch=2em \noindent\it #4}
   \dimen0=\ht0 
   \divide\dimen0 by\baselineskip \advance\dimen0 by1sp
   \oblom #2 from #1 indent \dimen0 
   \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#2<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#2<0pt \hfill\fi 
            \vtop to0pt{\kern-2\baselineskip\kern#1\baselineskip\box\picbox\vss}\hfil}
      \nobreak\vskip-\baselineskip
   \fi
}
\parindent=0pt \raggedbottom % we need the grid

La limitación de esta macro es: no puedes colocar la imagen en el "borde" de la página donde está el salto de página. Sólo antes o después de dicho salto de página. No puede insertar dos imágenes en un párrafo. El siguiente uso de \flowpicse permite solo antes del párrafo donde no hay líneas sangradas por la anterior \flowpic. Si tiene un párrafo muy largo y necesita colocar dos \flowpics aquí, entonces necesita usar el truco conocido {\parfillskip=0pt\par}para cerrar el párrafo "invisible" anterior.

información relacionada