Я делаю шаблон для разных текстов и мне нужно использовать 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}
решение1
varwidth
раз- и собирает vbox
es построчно, в ходе чего керны краев теряются. Средством было бы использовать \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}