Microtype 在 varwidth 内不起作用

Microtype 在 varwidth 内不起作用

我为不同的文本制作了一个模板,我需要使用 varwidth。但似乎 microtype 在此环境中不起作用。有什么方法可以让它工作吗?

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

minipage 和 varwidth 内的微类型

答案1

varwidth逐行拆解并重新组合vboxes,在此过程中,边距字距会丢失。补救措施是使用\leftmarginkern\rightmarginkern来记录并重新插入边距字距。这需要对 进行两处更改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}

然后:

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

相关内容