| 1 |
% \iffalse |
| 2 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 |
%% THE XLTXTRA PACKAGE |
| 4 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5 |
%% |
| 6 |
%% Copyright (C) 2006-2018 by Will Robertson <[email protected]> |
| 7 |
%% |
| 8 |
%% Distributable under the LaTeX Project Public License, |
| 9 |
%% version 1.3c or higher (your choice). The latest version of |
| 10 |
%% this license is at: http://www.latex-project.org/lppl.txt |
| 11 |
%% |
| 12 |
%% This work is "maintained" (as per LPPL maintenance status) |
| 13 |
%% by Will Robertson. |
| 14 |
%% |
| 15 |
%% This work consists of the files xltxtra.dtx and xltxtra.ins, |
| 16 |
%% and the derived files xltxtra.sty and xltxtra.pdf. |
| 17 |
%% |
| 18 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 19 |
%<*driver> |
| 20 |
\documentclass{ltxdoc} |
| 21 |
|
| 22 |
\makeatletter |
| 23 |
|
| 24 |
\def\@dotsep{1000} |
| 25 |
\setcounter{tocdepth}{2} |
| 26 |
|
| 27 |
\setcounter{IndexColumns}{2} |
| 28 |
\renewenvironment{theglossary} |
| 29 |
{\small\list{}{} |
| 30 |
\item\relax |
| 31 |
\glossary@prologue\GlossaryParms |
| 32 |
\let\item\@idxitem \ignorespaces |
| 33 |
\def\pfill{\hspace*{\fill}}} |
| 34 |
{\endlist} |
| 35 |
|
| 36 |
\usepackage{array,booktabs,calc,color,enumitem,fancyvrb,graphicx,ifthen,longtable,refstyle,varioref,xltxtra} |
| 37 |
\usepackage[rm]{titlesec} |
| 38 |
\setmainfont{texgyrepagella}[ |
| 39 |
Extension = .otf , |
| 40 |
UprightFont = *-regular , |
| 41 |
ItalicFont = *-italic , |
| 42 |
BoldFont = *-bold , |
| 43 |
BoldItalicFont = *-bolditalic , |
| 44 |
] |
| 45 |
\setsansfont{texgyreheros}[ |
| 46 |
Scale=MatchLowercase , |
| 47 |
Extension = .otf , |
| 48 |
UprightFont = *-regular , |
| 49 |
ItalicFont = *-italic , |
| 50 |
BoldFont = *-bold , |
| 51 |
BoldItalicFont = *-bolditalic , |
| 52 |
] |
| 53 |
\setmonofont{lmmono10}[ |
| 54 |
Extension = .otf , |
| 55 |
UprightFont = *-regular , |
| 56 |
ItalicFont = *-italic , |
| 57 |
] |
| 58 |
|
| 59 |
\linespread{1.05} % A bit more space between lines |
| 60 |
\frenchspacing % Remove space after punctuation |
| 61 |
|
| 62 |
\setlogokern{Xe}{-0.061em} |
| 63 |
\setlogokern{eL}{-0.057em} |
| 64 |
\setlogokern{La}{-0.28em} |
| 65 |
\setlogokern{aT}{-0.10em} |
| 66 |
\setlogokern{Te}{-0.0575em} |
| 67 |
\setlogokern{eX}{-0.072em} |
| 68 |
\setlogokern{eT}{-0.056em} |
| 69 |
\setlogokern{X2}{0.1667em} |
| 70 |
\setlogodrop{0.153em} |
| 71 |
\setLaTeXa{\scshape a} |
| 72 |
\setLaTeXee{\mbox{\fontspec{Times}\itshape ε}} |
| 73 |
\def\eTeX{{\fontspec{Times}\textit{ε}{}}-\TeX} % The eTeX logo is not (yet) covered by metalogo |
| 74 |
|
| 75 |
\definecolor{niceblue}{rgb}{0.2,0.4,0.6} |
| 76 |
\def\theCodelineNo{\textcolor{niceblue}{\sffamily\tiny\arabic{CodelineNo}}} |
| 77 |
|
| 78 |
\newenvironment{example} |
| 79 |
{\VerbatimEnvironment |
| 80 |
\begin{trivlist}\item[] |
| 81 |
\begin{minipage}{\linewidth} |
| 82 |
\par\noindent\hrulefill\par |
| 83 |
\begin{VerbatimOut}[gobble=4]{\examplefilename}} |
| 84 |
{\end{VerbatimOut}\relax |
| 85 |
\begingroup |
| 86 |
\color{niceblue} |
| 87 |
\typesetexample |
| 88 |
\endgroup\par\noindent\hrulefill\par |
| 89 |
\end{minipage}\end{trivlist}} |
| 90 |
|
| 91 |
\let\examplesize\normalsize |
| 92 |
\let\auxwidth\relax |
| 93 |
|
| 94 |
\newlength\examplewidth\newlength\verbatimwidth |
| 95 |
\newlength\exoutdent \newlength\exverbgap |
| 96 |
\setlength\exverbgap{0em} |
| 97 |
\setlength\exoutdent{-0\textwidth} |
| 98 |
\newsavebox\verbatimbox |
| 99 |
\edef\examplefilename{xltxtra.example} |
| 100 |
|
| 101 |
\newcommand\typesetexample{\relax |
| 102 |
\begin{lrbox}{\verbatimbox}\relax |
| 103 |
\BVerbatimInput[fontsize=\small]{\examplefilename}\relax |
| 104 |
\end{lrbox} |
| 105 |
\begin{list}{}{\setlength\itemindent{0pt} |
| 106 |
\setlength\leftmargin\exoutdent |
| 107 |
\setlength\rightmargin{0pt}}\item |
| 108 |
\ifx\auxwidth\relax |
| 109 |
\setlength\verbatimwidth{\wd\verbatimbox}\relax |
| 110 |
\else |
| 111 |
\setlength\verbatimwidth{\auxwidth}\relax |
| 112 |
\fi |
| 113 |
\begin{minipage}[c]{\textwidth-\exoutdent-\verbatimwidth-\exverbgap} |
| 114 |
\catcode`\%=14\centering\examplesize\input\examplefilename\relax |
| 115 |
\end{minipage}\hfill |
| 116 |
\begin{minipage}[c]{\verbatimwidth} |
| 117 |
\usebox\verbatimbox |
| 118 |
\end{minipage} |
| 119 |
\end{list} |
| 120 |
\global\let\examplesize\normalsize} |
| 121 |
|
| 122 |
\newcommand*\setexsize[1]{\let\examplesize#1} |
| 123 |
\newcommand*\setverbwidth[1]{\def\auxwidth{#1}} |
| 124 |
|
| 125 |
\newcommand*\name[1]{{#1}} |
| 126 |
\newcommand*\pkg[1]{\texttt{#1}} |
| 127 |
\newcommand*\pkgopt[1]{\texttt{[#1]} package option} |
| 128 |
|
| 129 |
\newcommand*\acro[1]{\textsc{\MakeLowercase{#1}}} |
| 130 |
|
| 131 |
\newcommand*\note[1]{\unskip\footnote{#1}} |
| 132 |
|
| 133 |
\let\latin\textit |
| 134 |
\def\eg{\latin{e.g.}} |
| 135 |
\def\Eg{\latin{E.g.}} |
| 136 |
\def\ie{\latin{i.e.}} |
| 137 |
\def\etc{\@ifnextchar.{\latin{etc}}{\latin{etc.}\@}} |
| 138 |
|
| 139 |
\newcounter{argument} |
| 140 |
\g@addto@macro\endmacro{\setcounter{argument}{0}} |
| 141 |
\newcommand*\darg[1]{% |
| 142 |
\stepcounter{argument}% |
| 143 |
\noindent{\ttfamily\#\theargument}:~#1\par\nobreak} |
| 144 |
\newcommand*\doarg[1]{% |
| 145 |
\stepcounter{argument}% |
| 146 |
\noindent{\ttfamily\makebox[0pt][r]{[}\#\theargument]}:~#1\par\nobreak} |
| 147 |
|
| 148 |
\newcommand\unichar[2]{\textsc{\MakeLowercase{u+#1: #2}}} |
| 149 |
|
| 150 |
\makeatother |
| 151 |
|
| 152 |
\EnableCrossrefs |
| 153 |
\CodelineIndex |
| 154 |
\begin{document} |
| 155 |
\DocInput{xltxtra.dtx} |
| 156 |
\end{document} |
| 157 |
%</driver> |
| 158 |
% \fi |
| 159 |
% |
| 160 |
% \errorcontextlines=999 |
| 161 |
% \makeatletter |
| 162 |
% |
| 163 |
% \GetFileInfo{xltxtra.sty} |
| 164 |
% |
| 165 |
% \title{The \pkg{xltxtra} package} |
| 166 |
% \author{Will Robertson} |
| 167 |
% \date{\filedate \qquad \fileversion} |
| 168 |
% |
| 169 |
% \maketitle |
| 170 |
% |
| 171 |
% \tableofcontents |
| 172 |
% |
| 173 |
% \section{Introduction} |
| 174 |
% |
| 175 |
% This document describes the \pkg{xltxtra} package. |
| 176 |
% It implements some odds-and-ends features when using the \XeLaTeX\ format. |
| 177 |
% |
| 178 |
% \subsection{Usage} |
| 179 |
% Easy: |\usepackage{xltxtra}|. This package automatically loads the following packages: \pkg{fontspec}, \pkg{realscripts}, \pkg{metalogo}. |
| 180 |
% |
| 181 |
% There are some package options to disable various functionality that could clash with other things: |
| 182 |
% \begin{description}[font=\ttfamily] |
| 183 |
% \item[no-sscript] Swaps the definitions of \cmd\textsubscript\ and \cmd\textsuperscript\ with their respective starred versions, as described in \secref{sscript}. |
| 184 |
% \item[no-logos] Disables the redefinition of \cmd\TeX, etc. described in \secref{logos}, but \emph{does} still define the \cmd\XeTeX\ and \cmd\XeLaTeX\ logo commands. |
| 185 |
% \end{description} |
| 186 |
% |
| 187 |
% \section{Features} |
| 188 |
% |
| 189 |
% \subsection{\cmd\textsuperscript\ and \cmd\textsubscript} |
| 190 |
% \seclabel{sscript} |
| 191 |
% |
| 192 |
% This functionality is achieved through loading the \pkg{realscripts} |
| 193 |
% package. |
| 194 |
% |
| 195 |
% These two macros have been redefined to take advantage, if possible, of actual superior or inferior glyphs in the main document font. This is very important for high-quality typesetting — compare this first example to the third; yes, they are the same font. |
| 196 |
% \begin{quotation}\color{niceblue} |
| 197 |
% \fontspec{Skia} |
| 198 |
% |\textsuperscript | \textsuperscript{abcdefghijklmnopqrstuvwxyz1234567890}\par |
| 199 |
% |\textsubscript | \textsubscript{abcdefghijklmnopqrstuvwxyz1234567890} |
| 200 |
% \end{quotation} |
| 201 |
% But will fall back on `faked' ones if they don't exist: |
| 202 |
% (this is {\fontspec{Didot} Didot}) |
| 203 |
% \begin{quotation}\color{niceblue} |
| 204 |
% \fontspec{Didot} |
| 205 |
% |\textsuperscript | \textsuperscript{abcdefghijklmnopqrstuvwxyz1234567890}\par |
| 206 |
% |\textsubscript | \textsubscript{abcdefghijklmnopqrstuvwxyz1234567890} |
| 207 |
% \end{quotation} |
| 208 |
% The original definitions are available in starred verions of the commands: |
| 209 |
% \begin{quotation}\color{niceblue} |
| 210 |
% \fontspec{Skia} |
| 211 |
% |\textsuperscript* | \textsuperscript*{abcdefghijklmnopqrstuvwxyz1234567890}\par |
| 212 |
% |\textsubscript* | \textsubscript*{abcdefghijklmnopqrstuvwxyz1234567890} |
| 213 |
% \end{quotation} |
| 214 |
% |
| 215 |
% The \pkgopt{no-sscript} will swap the definitions of the starred and non-starred versions of the commands described above if the new definitions are undesirable. |
| 216 |
% |
| 217 |
% The macros |
| 218 |
% \cmd\realsubscript, |
| 219 |
% \cmd\realsuperscript, |
| 220 |
% \cmd\fakesubscript, and |
| 221 |
% \cmd\fakesuperscript\ |
| 222 |
% may be used to access the `new' and `old' functionalities regardless of the \pkgopt{no-sscript}. |
| 223 |
% |
| 224 |
% |
| 225 |
% |
| 226 |
% |
| 227 |
% \subsection{Logos} |
| 228 |
% \seclabel{logos} |
| 229 |
% |
| 230 |
% This part of the package essentially exists to define the \cmd\XeTeX\ and \cmd\XeLaTeX\ logos, |
| 231 |
% which need to be tuned according to the font that is used. Originally I had some hard-coded |
| 232 |
% definitions in here, but Andrew Moschou’s |metalogo| package now provides a much more |
| 233 |
% flexible and useful interface to a variety of \TeX-related logos. |
| 234 |
% |
| 235 |
% Here are some examples. The default: |
| 236 |
% \begingroup |
| 237 |
% \setlogokern{Xe}{default} |
| 238 |
% \setlogokern{eL}{default} |
| 239 |
% \setlogokern{La}{default} |
| 240 |
% \setlogokern{aT}{default} |
| 241 |
% \setlogokern{Te}{default} |
| 242 |
% \setlogokern{eX}{default} |
| 243 |
% \setlogokern{eT}{default} |
| 244 |
% \setlogokern{X2}{default} |
| 245 |
% \setlogodrop{default} |
| 246 |
% \setLaTeXa{default} |
| 247 |
% \setLaTeXee{default} |
| 248 |
% \begin{example} |
| 249 |
% \TeX\ \XeTeX\ \LaTeX\ \XeLaTeX |
| 250 |
% \end{example} |
| 251 |
% \noindent Notice that it's a bit tight when not using Computer Modern, for which the logos were designed: |
| 252 |
% \begin{example} |
| 253 |
% \usefont{OT1}{cmr}{m}{n} |
| 254 |
% \TeX\ \XeTeX\ \LaTeX\ \XeLaTeX |
| 255 |
% \end{example} |
| 256 |
% \endgroup |
| 257 |
% |
| 258 |
% These logos, ideally, should be hand-tuned for each font that they're used in. Please refer to the |metalogo| documentation for more information. |
| 259 |
% |
| 260 |
% The \pkgopt{no-logos} will not redefine \cmd\TeX\ or \cmd\LaTeX\ but will still define \cmd\XeTeX\ and \cmd\XeLaTeX. |
| 261 |
% |
| 262 |
% |
| 263 |
% \subsection{Vulgar fractions} |
| 264 |
% The \cmd\vfrac\ command for setting `vulgar' fractions based on AAT or OpenType font features. Not really recommended for many purposes, depending on your text, but it's a good example of how to program such things using \pkg{fontspec}. |
| 265 |
% \begin{example} |
| 266 |
% \fontspec{LibreCaslonText-Regular.otf} |
| 267 |
% \vfrac{123}{456} |
| 268 |
% \end{example} |
| 269 |
% \noindent (This can also be achieved in regular \LaTeX\ with either the \pkg{nicefrac} or \pkg{xfrac} package.) |
| 270 |
% |
| 271 |
% Only use it when you know it will work; no warnings are given if the font doesn't support the necessary features. |
| 272 |
% |
| 273 |
% \subsection{Named glyphs} |
| 274 |
% Along the way somewhere, \XeTeX\ added support for selecting glyphs from a TrueType-based OpenType font based on their internal glyph name. Jonathan Kew posted the following definition as a nice interface to it. |
| 275 |
% \begin{example} |
| 276 |
% \fontspec{charis} |
| 277 |
% \namedglyph{yen} |
| 278 |
% \namedglyph{smile} |
| 279 |
% \end{example} |
| 280 |
% |
| 281 |
% \subsection{The \cmd\showhyphens\ command} |
| 282 |
% The default definition doesn't work in \XeTeX. |
| 283 |
% A new version, written by Enrico Gregorio, is included in this package that \emph{does} work; note that the syntax now matches plain \TeX's original rather than the comma-list approach taken by an earlier version of this package. |
| 284 |
% \showhyphens{discomedusoid discommodiousness} |
| 285 |
% |
| 286 |
% \newpage |
| 287 |
% \part{The \textsf{xltxtra} package} |
| 288 |
%\iffalse |
| 289 |
%<*package> |
| 290 |
%\fi |
| 291 |
% This is the package implementation. |
| 292 |
% |
| 293 |
% \begin{macrocode} |
| 294 |
\ProvidesPackage{xltxtra} |
| 295 |
[2018/12/31 v0.7 Improvements for the "XeLaTeX" format] |
| 296 |
% \end{macrocode} |
| 297 |
% |
| 298 |
% \paragraph{Not for Lua\TeX} |
| 299 |
% \begin{macrocode} |
| 300 |
\RequirePackage{ifluatex} |
| 301 |
\ifluatex |
| 302 |
\PackageWarningNoLine {xltxtra} {^^J |
| 303 |
XLTXTRA IS TO BE USED ONLY UNDER XETEX. |
| 304 |
LOAD FONTSPEC DIRECTLY, INSTEAD.^^J |
| 305 |
ABORTING LOADING% |
| 306 |
} |
| 307 |
\RequirePackage{fontspec} |
| 308 |
\expandafter \endinput |
| 309 |
\fi |
| 310 |
% \end{macrocode} |
| 311 |
% |
| 312 |
% \paragraph{Required packages} |
| 313 |
% \begin{macrocode} |
| 314 |
\RequirePackage{ifxetex} |
| 315 |
\RequireXeTeX |
| 316 |
\RequirePackage{fontspec} |
| 317 |
\RequirePackage{realscripts} |
| 318 |
% \end{macrocode} |
| 319 |
% |
| 320 |
% \paragraph{Option processing} |
| 321 |
% \begin{macrocode} |
| 322 |
\newif\if@xxt@nosscript@ |
| 323 |
\newif\if@xxt@nologos@ |
| 324 |
\DeclareOption{no-sscript}{\@xxt@nosscript@true} |
| 325 |
\DeclareOption{no-logos}{\@xxt@nologos@true} |
| 326 |
\ProcessOptions* |
| 327 |
% \end{macrocode} |
| 328 |
% |
| 329 |
% |
| 330 |
% \section{Logos} |
| 331 |
% \DescribeMacro{\XeTeX} |
| 332 |
% \DescribeMacro{\XeLaTeX} |
| 333 |
% The \TeX-related logos people insist upon using need to be tuned |
| 334 |
% on a per-font basis. This package calls upon Andrew Moschou's package |
| 335 |
% |metalogo| for this purpose. To tune the logos to each font, |
| 336 |
% use the commands \cmd\setlogokern, \cmd\setlogodrop, etc.\ Refer to |
| 337 |
% |mathspec|’s documentation for further details. |
| 338 |
% |
| 339 |
% \begin{example} |
| 340 |
% \setlogokern{Xe}{-0.061em} |
| 341 |
% \setlogokern{eL}{-0.057em} |
| 342 |
% \setlogokern{La}{-0.265em} |
| 343 |
% \setlogokern{aT}{-0.0585em} |
| 344 |
% \setlogokern{Te}{-0.0575em} |
| 345 |
% \setlogokern{eX}{-0.072em} |
| 346 |
% \setlogokern{eT}{-0.056em} |
| 347 |
% \setlogokern{X2}{0.1667em} |
| 348 |
% \setlogodrop{0.153em} |
| 349 |
% \setLaTeXa{\scshape a} |
| 350 |
% \setLaTeXee{\mbox{\fontspec{Times}\itshape ε}} |
| 351 |
% \TeX\ \XeTeX\ \LaTeX\ \XeLaTeX\ \LaTeXe |
| 352 |
% \end{example} |
| 353 |
% |
| 354 |
% \begin{macrocode} |
| 355 |
\RequirePackage{metalogo} |
| 356 |
% \end{macrocode} |
| 357 |
% |
| 358 |
% The \pkgopt{no-logos} might be in effect, in which case \cmd\TeX, \cmd\LaTeX\ and |
| 359 |
% \cmd\LaTeXe\ should keep their original definitions (which were saved by |metalogo|). |
| 360 |
% |
| 361 |
% \begin{macrocode} |
| 362 |
\if@xxt@nologos@ |
| 363 |
\let\TeX\original@TeX |
| 364 |
\let\LaTeX\original@LaTeX |
| 365 |
\let\LaTeXe\original@LaTeXe |
| 366 |
\fi |
| 367 |
% \end{macrocode} |
| 368 |
% |
| 369 |
% |
| 370 |
% |
| 371 |
% \section{Subscript and superscript} |
| 372 |
% |
| 373 |
% \begin{macro}{\textsubscript} |
| 374 |
% \begin{macro}{\textsubscript*} |
| 375 |
% \begin{macro}{\textsuperscript} |
| 376 |
% \begin{macro}{\textsuperscript*} |
| 377 |
% These commands are either defined to create fake or real sub-/super-scripts if they are starred or not, respectively. This swaps if the \pkgopt{no-sscript} is in effect. |
| 378 |
% Text subscripts: |
| 379 |
% \begin{macrocode} |
| 380 |
\if@xxt@nosscript@ |
| 381 |
\DeclareRobustCommand*\textsubscript{% |
| 382 |
\@ifstar{\realsubscript}{\fakesubscript}} |
| 383 |
\DeclareRobustCommand*\textsuperscript{% |
| 384 |
\@ifstar{\realsuperscript}{\fakesuperscript}} |
| 385 |
\fi |
| 386 |
% \end{macrocode} |
| 387 |
% \end{macro} |
| 388 |
% \end{macro} |
| 389 |
% \end{macro} |
| 390 |
% \end{macro} |
| 391 |
% |
| 392 |
% \section{Assorted commands} |
| 393 |
% |
| 394 |
% \begin{macro}{\vfrac} |
| 395 |
% \darg{Numerator} |
| 396 |
% \darg{Denominator} |
| 397 |
% No error checking is done to ensure that the font actually has the neceessary features. |
| 398 |
% Requires the \pkg{xunicode} package for \cmd\textfractionsolidus. |
| 399 |
% \begin{macrocode} |
| 400 |
\ExplSyntaxOn |
| 401 |
\newcommand*\vfrac[2]{ |
| 402 |
\fontspec_if_fontspec_font:TF |
| 403 |
{ |
| 404 |
\fontspec_if_opentype:TF |
| 405 |
{ |
| 406 |
{\addfontfeature{VerticalPosition=Numerator}#1} |
| 407 |
\textfractionsolidus |
| 408 |
{\addfontfeature{VerticalPosition=Denominator}#2} |
| 409 |
} |
| 410 |
{ |
| 411 |
{\addfontfeature{VerticalPosition=Superior}#1} |
| 412 |
\textfractionsolidus |
| 413 |
{\addfontfeature{VerticalPosition=Inferior}#2} |
| 414 |
} |
| 415 |
} |
| 416 |
{ |
| 417 |
\PackageError {xltxtra} |
| 418 |
{ \string\vfrac\space~can~only~be~used~with~fontspec~fonts } |
| 419 |
{ Nothing~more~to~tell. } |
| 420 |
} |
| 421 |
} |
| 422 |
\ExplSyntaxOff |
| 423 |
% \end{macrocode} |
| 424 |
% \end{macro} |
| 425 |
% |
| 426 |
% \begin{macro}{\namedglyph} |
| 427 |
% \darg{Name of the font glyph to be typeset} |
| 428 |
% \begin{macrocode} |
| 429 |
\newcommand\namedglyph[1]{% |
| 430 |
\@tempcnta=\XeTeXglyphindex "#1"\relax |
| 431 |
\ifnum\@tempcnta>0 |
| 432 |
\XeTeXglyph\@tempcnta |
| 433 |
\else |
| 434 |
\xxt@namedglyph@fallback{#1}% |
| 435 |
\fi} |
| 436 |
% \end{macrocode} |
| 437 |
% \end{macro} |
| 438 |
% |
| 439 |
% \begin{macro}{\xxt@namedglyph@fallback} |
| 440 |
% Redefine this macro to change how glyph names that aren't found get typeset. |
| 441 |
% \begin{macrocode} |
| 442 |
\newcommand\xxt@namedglyph@fallback[1]{[#1]} |
| 443 |
% \end{macrocode} |
| 444 |
% \end{macro} |
| 445 |
% |
| 446 |
% |
| 447 |
% \begin{macro}{\showhyphens} |
| 448 |
% Courtesy egreg. |
| 449 |
% \begin{macrocode} |
| 450 |
\ExplSyntaxOn |
| 451 |
\seq_new:N \l__xetex_showhyphens_seq |
| 452 |
\box_new:N \l__xetex_show_hyphens_wrapping_box |
| 453 |
\box_new:N \l__xetex_show_hyphens_temp_box |
| 454 |
\box_new:N \l__xetex_show_hyphens_final_box |
| 455 |
\box_new:N \g__xetex_show_hyphens_word_box |
| 456 |
|
| 457 |
\cs_new_protected:Npn \xetex_show_hyphens:n #1 |
| 458 |
{ |
| 459 |
\box_clear:N \l__xetex_show_hyphens_final_box |
| 460 |
% split the input into items |
| 461 |
\seq_set_split:Nnn \l__xetex_showhyphens_seq { ~ } { #1 } |
| 462 |
% hyphenate all items |
| 463 |
\seq_map_function:NN \l__xetex_showhyphens_seq \xetex_hyphenate_word:n |
| 464 |
% set a box to the maximum dimension to force a Underfull \hbox warning |
| 465 |
\hbox_set_to_wd:Nnn \l__xetex_show_hyphens_final_box { \c_max_dim } |
| 466 |
{ |
| 467 |
\hbox_unpack_clear:N \l__xetex_show_hyphens_final_box |
| 468 |
} |
| 469 |
} |
| 470 |
|
| 471 |
\cs_new_protected:Npn \xetex_hyphenate_word:n #1 |
| 472 |
{ |
| 473 |
\vbox_set:Nn \l__xetex_show_hyphens_wrapping_box |
| 474 |
{% build a paragraph with the word with a very narrow line width |
| 475 |
\dim_set:Nn \hsize { 1sp } |
| 476 |
% disregard spurious messages |
| 477 |
\hbadness = 10000\relax |
| 478 |
\dim_set:Nn \hfuzz { \c_max_dim } |
| 479 |
% clear possible values of \everypar and other parameters |
| 480 |
\everypar={} |
| 481 |
\skip_set:Nn \leftskip { 0pt } |
| 482 |
\skip_set_eq:NN \rightskip \leftskip |
| 483 |
% skip the first step |
| 484 |
\pretolerance = -1\relax |
| 485 |
% avoid the indentation and add a skip to allow hyphenation |
| 486 |
\noindent |
| 487 |
\skip_horizontal:n { 0pt } |
| 488 |
#1 |
| 489 |
\par |
| 490 |
\hbox_gset:Nn \g__xetex_show_hyphens_word_box {} |
| 491 |
% start a recursion to dismantle the paragraph just built |
| 492 |
\xetex_show_hyphens_split: |
| 493 |
% the result is put into \g__xetex_show_hyphens_word_box |
| 494 |
} |
| 495 |
% add the box to the final container |
| 496 |
\hbox_set:Nn \l__xetex_show_hyphens_final_box |
| 497 |
{ |
| 498 |
\hbox_unpack_clear:N \l__xetex_show_hyphens_final_box |
| 499 |
\hbox_unpack_clear:N \g__xetex_show_hyphens_word_box |
| 500 |
} |
| 501 |
} |
| 502 |
|
| 503 |
\cs_new_protected:Npn \xetex_show_hyphens_split: |
| 504 |
{ |
| 505 |
\unskip % remove the interline glue |
| 506 |
\unpenalty % remove possible penalties |
| 507 |
% get the last line |
| 508 |
\box_set_to_last:N \l__xetex_show_hyphens_temp_box |
| 509 |
\box_if_empty:NF \l__xetex_show_hyphens_temp_box |
| 510 |
{% if there is a last line unpack it into a container |
| 511 |
\hbox_gset:Nn \g__xetex_show_hyphens_word_box |
| 512 |
{% the order is last to first |
| 513 |
\hbox_unpack_clear:N \l__xetex_show_hyphens_temp_box |
| 514 |
\unskip\unskip % remove spaces |
| 515 |
\hbox_unpack_clear:N \g__xetex_show_hyphens_word_box |
| 516 |
} |
| 517 |
% restart the recursion |
| 518 |
\xetex_show_hyphens_split: |
| 519 |
} |
| 520 |
} |
| 521 |
|
| 522 |
\cs_set_eq:NN \showhyphens \xetex_show_hyphens:n |
| 523 |
\ExplSyntaxOff |
| 524 |
% \end{macrocode} |
| 525 |
% \end{macro} |
| 526 |
% |
| 527 |
%\iffalse |
| 528 |
%</package> |
| 529 |
%\fi |
| 530 |
% |
| 531 |
% \Finale |
| 532 |
% |
| 533 |
\endinput |
| 534 |
|