| 1 |
% \iffalse |
| 2 |
%% |
| 3 |
%% File: extdash.dtx Copyright (C) 1998-2018 by Alexander I. Rozhenko |
| 4 |
%% |
| 5 |
%<package>\NeedsTeXFormat{LaTeX2e} |
| 6 |
%<package>\ProvidesPackage{extdash} |
| 7 |
%<package> [2018/06/24 v1.3 Extended Dash Package (NCC)] |
| 8 |
% |
| 9 |
% \changes{v1.0}{1998/12/20}{Initial version} |
| 10 |
% \changes{v1.1}{2004/11/23}{Minor corrections of the documentation} |
| 11 |
% \changes{v1.2}{2005/01/29}{Change spaces surround em-dash} |
| 12 |
% \changes{v1.3){2018/06/24}{Add more em-dash configuring options by request from Frank Mittelbach} |
| 13 |
% |
| 14 |
%<*driver> |
| 15 |
\let\makeindex\relax |
| 16 |
\documentclass{ltxdoc} |
| 17 |
\usepackage{extdash} |
| 18 |
\GetFileInfo{extdash.sty} |
| 19 |
\begin{document} |
| 20 |
\title{The \textsf{extdash} package\thanks{This file |
| 21 |
has version number \fileversion, last |
| 22 |
revised \filedate.}} |
| 23 |
\author{Alexander I. Rozhenko\\[email protected]} |
| 24 |
\date{\filedate} |
| 25 |
\maketitle |
| 26 |
\DocInput{extdash.dtx} |
| 27 |
\end{document} |
| 28 |
%</driver> |
| 29 |
% \fi |
| 30 |
% The package implements the commands, |\Hyphdash|, |\Endash|, and |
| 31 |
% |\Emdash|, to control hyphenation of compound words and ordinary |
| 32 |
% words dashed by \emph{em-dash}. Some additional commands and |
| 33 |
% shortcuts are also introduced. |
| 34 |
% |
| 35 |
% \tableofcontents |
| 36 |
% |
| 37 |
% \section{User Interface} |
| 38 |
% |
| 39 |
% \DescribeMacro{\Hyphdash} |
| 40 |
% \DescribeMacro{\Hyphdash*} |
| 41 |
% The main purpose of the |extdash| package is to allow hyphenation |
| 42 |
% of compound words. When the word |something-something| occurs, the only |
| 43 |
% hyphenation point after the dash is available. To allow hyphenation |
| 44 |
% of both words joint by dash you can write |
| 45 |
% \begin{center} |
| 46 |
% |something\Hyphdash something|\quad or easier\quad |
| 47 |
% |something\-/something| |
| 48 |
% \end{center} |
| 49 |
% (the last case is available if\/ you use the package |extdash| |
| 50 |
% with |shortcuts| option). Sometimes the line break immediately after |
| 51 |
% the dash is inadmissible. To avoid this, you can write |
| 52 |
% \begin{center} |
| 53 |
% |something\Hyphdash* something|\quad or easier\quad |
| 54 |
% |something\=/something| |
| 55 |
% \end{center} |
| 56 |
% (the last case is also a shortcut). An example is the word |
| 57 |
% \emph{$L$-approximation} which can't be broken at the dash.\pagebreak |
| 58 |
% |
| 59 |
% \DescribeMacro{\Endash} |
| 60 |
% \DescribeMacro{\Endash*} |
| 61 |
% Analogously, you can use |\Endash| command (and its star version) to join |
| 62 |
% words with \emph{en-dash}. Shortcuts for it are |\--| and |\==|. |
| 63 |
% |
| 64 |
% \DescribeMacro{\Emdash} |
| 65 |
% \DescribeMacro{\Emdash*} |
| 66 |
% The last case is the use of \emph{em-dash} when some glue |
| 67 |
% before and after em-dash have to be added. The command |\Emdash| adds |
| 68 |
% this glue, named |\Halfspace|, which natural width is equal to the |
| 69 |
% \DescribeMacro{\Halfspace} |
| 70 |
% \DescribeMacro{\Halfspace*} |
| 71 |
% half of the ordinary interword space. The |\Halfspace| command |
| 72 |
% produces the \emph{elastic} horizontal space and its |*|-form |
| 73 |
% produces the nonbreakable elastic space. All these commands have |
| 74 |
% shortcuts |
| 75 |
% \begin{center} |
| 76 |
% |\---|\qquad |\===|\qquad |\-,|\qquad |\=,| |
| 77 |
% \end{center} |
| 78 |
% Note, that |\Emdash| command removes extra space before and after it. |
| 79 |
% When |\Emdash| appears at the beginning of a paragraph (the direct |
| 80 |
% speech) the space after it will be rigid and unbreakable. |
| 81 |
% |
| 82 |
% The standard em-dash is longer that it is required by Russian and German |
| 83 |
% typesetting rules. To decrease its length to the required one, you can |
| 84 |
% use this package with |shortemdash| option |
| 85 |
% (the |cyremdash| option is also supported for compatibility with the previous |
| 86 |
% version). |
| 87 |
% |
| 88 |
% Note: Some more options are available from the version 1.3. They control |
| 89 |
% the spacing around |\Emdash| and the breaking strategy to be applied |
| 90 |
% before it. |
| 91 |
% |
| 92 |
% \section{Package Options} |
| 93 |
% |
| 94 |
% \subsection{Shortcuts} |
| 95 |
% |
| 96 |
% \begin{center} |
| 97 |
% |\usepackage[shortcuts]{extdash}| |
| 98 |
% \end{center} |
| 99 |
% |
| 100 |
% The |shortcuts| option redefines \LaTeX{} commands |\-| and |\=| in |
| 101 |
% such a way to recognize shortcut sequences. If\/ no shortcut |
| 102 |
% recognized, the corresponding original command will be called. |
| 103 |
% In other words, when no shortcut recognized, the command |\-| |
| 104 |
% sets extra hyphenation point and |\=| means the accent command. |
| 105 |
% |
| 106 |
% \begin{center} |
| 107 |
% \begin{tabular}{l@{\qquad}l@{\qquad\qquad}l@{\qquad}l} |
| 108 |
% Command & Shortcut & Command & Shortcut \\ |
| 109 |
% \cs{Hyphdash} & \cs{-/} & \cs{Hyphdash*} & \cs{=/} \\ |
| 110 |
% \cs{Endash} & \cs{--} & \cs{Endash*} & \cs{==} \\ |
| 111 |
% \cs{Emdash} & \cs{---} & \cs{Emdash*} & \cs{===} \\ |
| 112 |
% \cs{Halfspace}& \cs{-,} & \cs{Halfspace*}& \cs{=,} |
| 113 |
% \end{tabular} |
| 114 |
% \end{center} |
| 115 |
% |
| 116 |
% \emph{All described commands and shortcuts are robust.} |
| 117 |
% |
| 118 |
% \subsection{Breaks before em-dash} |
| 119 |
% |
| 120 |
% All dash commands defined in this package disallow line breaks before a dash. |
| 121 |
% For em-dash this rule can be changed. To allow breaks before a em-dash, please |
| 122 |
% use the option |
| 123 |
% |
| 124 |
% \begin{center} |
| 125 |
% |\usepackage[allowbreakbefore]{extdash}| |
| 126 |
% \end{center} |
| 127 |
% |
| 128 |
% \subsection{Shorter em-dash} |
| 129 |
% |
| 130 |
% \begin{center} |
| 131 |
% |\usepackage[shortemdash]{extdash}| |
| 132 |
% \end{center} |
| 133 |
% |
| 134 |
% This option redefines |\Emdash| to be shorter than the standard |
| 135 |
% em-dash (0.8~em). |
| 136 |
% |
| 137 |
% \subsection{Spaces around em-dash} |
| 138 |
% |
| 139 |
% By default, the half-space is inserted before and after em-dash. |
| 140 |
% This behavior can be changed with option |
| 141 |
% |
| 142 |
% \begin{center} |
| 143 |
% |\usepackage[wordspacearound]{extdash}| |
| 144 |
% \end{center} |
| 145 |
% |
| 146 |
% \noindent or |
| 147 |
% |
| 148 |
% \begin{center} |
| 149 |
% |\usepackage[nospacearound]{extdash}| |
| 150 |
% \end{center} |
| 151 |
% |
| 152 |
% The first option provides interword spaces around em-dash and the |
| 153 |
% last one removes spaces around em-dash. Of course, these two |
| 154 |
% options are mutually exclusive. |
| 155 |
% |
| 156 |
% \StopEventually{} |
| 157 |
% |
| 158 |
% \section{The Implementation} |
| 159 |
% |
| 160 |
% \begin{macro}{\EXD@test} |
| 161 |
% \begin{macro}{\EXD@break} |
| 162 |
% First we implement the command, |\EXD@test|. It recognizes the |
| 163 |
% star after the command, sets |\EXD@break| command to be equal |
| 164 |
% to |\nobreak| if\/ star is found or |\@empty| if\/ not, and calls |
| 165 |
% its parameter. |
| 166 |
% \begin{macrocode} |
| 167 |
%<*package> |
| 168 |
\def\EXD@test#1{% |
| 169 |
\@ifstar{\let\EXD@break\nobreak #1}{\let\EXD@break\@empty #1}% |
| 170 |
} |
| 171 |
% \end{macrocode} |
| 172 |
% \end{macro} |
| 173 |
% \end{macro} |
| 174 |
% |
| 175 |
% \begin{macro}{\Hyphdash} |
| 176 |
% \begin{macro}{\Endash} |
| 177 |
% \begin{macro}{\Emdash} |
| 178 |
% \begin{macro}{\Halfspace} |
| 179 |
% Now we declare user's level commands |
| 180 |
% \begin{macrocode} |
| 181 |
\DeclareRobustCommand{\Hyphdash}{\EXD@test{\EXD@dash-}} |
| 182 |
\DeclareRobustCommand{\Endash}{\EXD@test{\EXD@dash{--}}} |
| 183 |
\DeclareRobustCommand{\Emdash}{\EXD@test{\EXD@emd@sh}} |
| 184 |
\DeclareRobustCommand{\Halfspace}{\@tempcnta\z@ |
| 185 |
\@ifstar{\EXD@nobreak\EXD@space\ignorespaces}{\EXD@space\ignorespaces}% |
| 186 |
} |
| 187 |
% \end{macrocode} |
| 188 |
% \end{macro} |
| 189 |
% \end{macro} |
| 190 |
% \end{macro} |
| 191 |
% \end{macro} |
| 192 |
% \begin{macro}{\EXD@dash} |
| 193 |
% \begin{macro}{\EXD@emd@sh} |
| 194 |
% \begin{macro}{\EXD@nobreak} |
| 195 |
% \begin{macro}{\EXD@embreakbefore} |
| 196 |
% \begin{macro}{\EXD@spacecalc} |
| 197 |
% \begin{macro}{\EXD@space} |
| 198 |
% and then the basic commands |
| 199 |
% \begin{macrocode} |
| 200 |
\def\EXD@nobreak{\ifvmode\leavevmode\else\nobreak\fi} |
| 201 |
\def\EXD@dash#1{% |
| 202 |
\EXD@nobreak\hbox{#1}\EXD@break\hskip\z@skip \ignorespaces |
| 203 |
} |
| 204 |
\def\EXD@emnobreak{\nobreak} |
| 205 |
\def\EXD@emd@sh{% |
| 206 |
\ifvmode |
| 207 |
\leavevmode\EXD@emdash\nobreak\hskip.35em |
| 208 |
\else |
| 209 |
\unskip\EXD@emnobreak \@tempcnta\m@ne |
| 210 |
\EXD@space \EXD@emdash \EXD@break \EXD@space |
| 211 |
\fi \ignorespaces |
| 212 |
} |
| 213 |
\DeclareOption{allowbreakbefore}{% |
| 214 |
\let\EXD@emnobreak\@empty |
| 215 |
} |
| 216 |
% \end{macrocode} |
| 217 |
% The |\@tempcnta| specifies the width of half-space. It can have |
| 218 |
% the following values: |-1|, |0|, or |+1|. The negative value |
| 219 |
% means using the space before em-dash (the space is narrow at this point), |
| 220 |
% zero value means an ordinary half space, and the positive value |
| 221 |
% means a half-space after em-dash (the space is wider at this point). |
| 222 |
% This trick compensates a visual effect of wider space before an em-dash |
| 223 |
% especially if the punctuation mark goes before. |
| 224 |
% |
| 225 |
% The meaning of negative and positive values of |\@tempcnta| |
| 226 |
% is redefined with |wordspacearound| and |nospacearound| options. |
| 227 |
% \begin{macrocode} |
| 228 |
\def\EXD@spacecalc{% |
| 229 |
\edef\@tempa{% |
| 230 |
\ifnum\@tempcnta<\z@ .4\else \ifnum \@tempcnta=\z@ .5\else .6\fi\fi |
| 231 |
}% |
| 232 |
\def\@tempb{.5}% |
| 233 |
} |
| 234 |
\def\EXD@space{% |
| 235 |
\EXD@spacecalc |
| 236 |
\hskip \@tempa\fontdimen2\font \@plus \@tempb\fontdimen3\font |
| 237 |
\@minus \@tempa\fontdimen4\font |
| 238 |
\@tempcnta -\@tempcnta |
| 239 |
} |
| 240 |
\DeclareOption{wordspacearound}{% |
| 241 |
\def\EXD@spacecalc{% |
| 242 |
\edef\@tempa{\ifnum \@tempcnta=\z@ .5\fi}% |
| 243 |
\let\@tempb\@tempa |
| 244 |
} |
| 245 |
} |
| 246 |
\DeclareOption{nospacearound}{% |
| 247 |
\def\EXD@spacecalc{% |
| 248 |
\edef\@tempa{\ifnum \@tempcnta=\z@ .5\else0\fi}% |
| 249 |
\let\@tempb\@tempa |
| 250 |
} |
| 251 |
} |
| 252 |
% \end{macrocode} |
| 253 |
% \end{macro} |
| 254 |
% \end{macro} |
| 255 |
% \end{macro} |
| 256 |
% \end{macro} |
| 257 |
% \end{macro} |
| 258 |
% \end{macro} |
| 259 |
% |
| 260 |
% \begin{macro}{\EXD@emdash} |
| 261 |
% The last basic command is the default \emph{em-dash}. It could be |
| 262 |
% redefined later in |shortemdash| option. |
| 263 |
% \begin{macrocode} |
| 264 |
\def\EXD@emdash{\hbox{---}} |
| 265 |
% \end{macrocode} |
| 266 |
% \end{macro} |
| 267 |
% |
| 268 |
% \begin{macrocode} |
| 269 |
\DeclareOption{shortcuts}{% |
| 270 |
% \end{macrocode} |
| 271 |
% |
| 272 |
% \begin{macro}{\HyphOrDash} |
| 273 |
% \begin{macro}{\BarOrDash} |
| 274 |
% The commands |\HyphOrDash| and |\BarOrDash| are called by |\-| and |\=| commands |
| 275 |
% and can appear in aux file. They choose the corresponding shortcut or the original |
| 276 |
% command saved in |\EXD@hyph| and |\EXD@bar|. |
| 277 |
% \begin{macrocode} |
| 278 |
\DeclareRobustCommand{\HyphOrDash}{% |
| 279 |
\let\EXD@break\@empty |
| 280 |
\@ifnextchar/{\EXD@d@sh}{% |
| 281 |
\@ifnextchar-{\EXD@hdash}{% |
| 282 |
\@ifnextchar,{\EXD@sp@ce}{\EXD@hyph}% |
| 283 |
}% |
| 284 |
}% |
| 285 |
} |
| 286 |
\DeclareRobustCommand{\BarOrDash}{% |
| 287 |
\let\EXD@break\nobreak |
| 288 |
\@ifnextchar/{\EXD@d@sh}{% |
| 289 |
\@ifnextchar={\EXD@bdash}{% |
| 290 |
\@ifnextchar,{\nobreak\EXD@sp@ce}{\EXD@bar}% |
| 291 |
}% |
| 292 |
}% |
| 293 |
} |
| 294 |
% \end{macrocode} |
| 295 |
% \end{macro} |
| 296 |
% \end{macro} |
| 297 |
% |
| 298 |
% Shortcuts: |
| 299 |
% \begin{macrocode} |
| 300 |
\def\EXD@d@sh/{\EXD@dash-} |
| 301 |
\def\EXD@sp@ce,{\EXD@space} |
| 302 |
\def\EXD@hdash-{\@ifnextchar-{\EXD@hhdash}{\EXD@dash{--}}} |
| 303 |
\def\EXD@bdash={\@ifnextchar={\EXD@bbdash}{\EXD@dash{--}}} |
| 304 |
\def\EXD@hhdash-{\EXD@emd@sh} |
| 305 |
\def\EXD@bbdash={\EXD@emd@sh} |
| 306 |
% \end{macrocode} |
| 307 |
% |
| 308 |
% We turn on the shortcuts mechanism at the beginning of the document to |
| 309 |
% avoid conflict with |fontenc| package which redefines accents. |
| 310 |
% \begin{macrocode} |
| 311 |
\AtBeginDocument{% |
| 312 |
\let\EXD@hyph\- \let\@dischyph\HyphOrDash \let\-\@dischyph |
| 313 |
\let\EXD@bar\= \let\@acciii\BarOrDash \let\=\@acciii |
| 314 |
} |
| 315 |
} |
| 316 |
% \end{macrocode} |
| 317 |
% |
| 318 |
% \begin{macrocode} |
| 319 |
\DeclareOption{shortemdash}{% |
| 320 |
\def\EXD@emdash{\hb@[email protected]\fontdimen6\font{--\hss--}} |
| 321 |
} |
| 322 |
\DeclareOption{cyremdash}{% |
| 323 |
\def\EXD@emdash{\hb@[email protected]\fontdimen6\font{--\hss--}} |
| 324 |
} |
| 325 |
\ProcessOptions\relax |
| 326 |
%</package> |
| 327 |
% \end{macrocode} |
| 328 |
% |
| 329 |
\endinput |