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