El microtipo no funciona dentro de varwidth

El microtipo no funciona dentro de varwidth

Hago una plantilla para diferentes textos y necesito usar varwidth. Pero parece que el microtipo no funciona en este entorno. ¿Hay alguna manera de hacer que funcione?

\documentclass{book}
\usepackage[showframe]{geometry}

\pagenumbering{gobble}

\usepackage{varwidth}

\usepackage{microtype}

\begin{document}

\hfill
\begin{minipage}{.5\textwidth}
\raggedleft
A letter, however, had lately reached me in a distant part of the country~--- a letter from him~--- which, in its wildly importunate nature, had admitted of no other than a personal reply. The MS. gave evidence of nervous agitation.
\end{minipage}

\vspace{\baselineskip}

\hfill
\begin{varwidth}{.5\textwidth}
\raggedleft
A letter, however, had lately reached me in a distant part of the country~--- a letter from him~--- which, in its wildly importunate nature, had admitted of no other than a personal reply. The MS. gave evidence of nervous agitation.
\end{varwidth}

\end{document}

Microtipo dentro de minipágina y varwidth

Respuesta1

varwidthdesmonta y vuelve a montar los vboxes línea por línea, en el transcurso del cual se pierden los núcleos marginales. La solución sería utilizar \leftmarginkerny \rightmarginkernpara registrar y volver a insertar los núcleos de margen. Esto requiere dos cambios en varwidth.sty:

% --- new dimens ---
\newdimen\@vwid@leftmargin
\newdimen\@vwid@rightmargin

\def\@vwid@sift{%
  \skip@\lastskip\unskip
  \dimen@\lastkern\unkern
  \count@\lastpenalty\unpenalty
  \setbox\z@\lastbox
%{\showoutput\showbox\z@}%
  \ifvoid\z@ \advance\sift@deathcycles\@ne \else
  % --- record left/right margin kerning ---
  \@vwid@leftmargin \leftmarginkern \z@  % <--
  \@vwid@rightmargin\rightmarginkern\z@  % <--
  \sift@deathcycles\z@ \fi
  \ifnum\sift@deathcycles>33
    \let\@vwid@sift\relax
    \PackageWarning{varwidth}{Failed to reprocess entire contents}%
  \fi
%\message{\the\sift@deathcycles: skip \the\skip@; kern \the\dimen@; penalty \the\count@. }%
%\ifhbox\z@\setbox99\hbox to0pt{\unhcopy\z@}\fi  % = message
  \ifnum\count@=\@vwid@preeqp \@vwid@eqmodefalse\fi
%\ifnum\count@=\@vwid@preeqp \message{End equation mode. }\fi
  \ifnum\count@=\@vwid@posteqp \@vwid@eqmodetrue\fi
%\ifnum\count@=\@vwid@posteqp\message{Begin equation mode. }\fi
%\if@vwid@eqmode {\showoutput\showbox\z@}\fi
  \ifnum\count@=\@vwid@toppen % finished
    \let\@vwid@sift\relax
  \else\ifnum\count@=\@vwid@offsets
    \@vwid@setoffsets
  \else
    \ifnum\count@=\@vwid@postw
    \else
      \@vwid@resetb % reset box \z@ or measure it
    \fi
    \@vwid@append
  \fi\fi
  \@vwid@sift}

y luego más tarde:

\def\@vwid@resetb{%
  \setbox\z@\vbox\bgroup
    \ifvoid\z@
    \else
       \ifvbox\z@
         \box\z@
       \else % \hbox
         \@tempdima\hsize
         \advance\@tempdima-\@vwid@roff
         \advance\@tempdima-\@vwid@loff
         \advance\@tempdima-\p@
%\message{Test if \the\wd\z@ > \the\@tempdima, }%
         \ifdim\wd\z@>\@tempdima % full-width line; rebox it
%\message{An ordinary line or alignment. (\the\wd\z@ > \the\@tempdima) }%
            \hbox to\hsize
              {\kern\@vwid@loff
               % --- reinsert margin kerning ---
               \ifdim\@vwid@leftmargin=\z@\else\kern\@vwid@leftmargin\fi % <--
               \unhbox\z@
               \ifdim\@vwid@rightmargin=\z@\else\kern\@vwid@rightmargin\fi % <--
               \kern\@vwid@roff}%
         \else % an equation or direct \hbox
           \if@vwid@eqmode % re-center unnumbered equations
%\message{A centered equation hsize=\the\hsize. }%
              \hbox to\hsize
                {\hskip\@vwid@loff\@plus1fil
                 \unhbox\z@ \hskip\@vwid@roff\@plus1fil}%
           \else % plain narrow \hbox; leave it as-is
%\message{Plain narrow box}%
              \box\z@
    \fi\fi\fi\fi
  \egroup}

\def\@vwid@measure{%
  \ifvoid\z@
  \else
    % numbered equations not part of alignments can't be reset,
    % so force retention of full width.
    \ifnum\count@=\@vwid@postnump \ifdim\wd\z@<\linewidth
      \ifdim\@tempdima<\linewidth \@tempdima\linewidth \fi
    \fi\fi
    \ifhbox\z@
      \setbox\z@=\hbox
        {\kern\@vwid@loff 
         \ifdim\@vwid@leftmargin=\z@\else\kern\@vwid@leftmargin\fi % <--
         \unhbox\z@ 
         \ifdim\@vwid@rightmargin=\z@\else\kern\@vwid@rightmargin\fi % <--
         \kern\@vwid@roff}%
    \fi
    \ifdim\wd\z@>\@tempdima \@tempdima\wd\z@ \fi
  \fi}

información relacionada