% \iffalse
%%
%% File: extdash.dtx Copyright (C) 1998-2005 by Alexander I. Rozhenko
%%
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{extdash}
%<package>      [2005/01/29 v1.2 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}
%
%<*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| occur 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). Some times the line break immediately after
% the dash is inadmissible. To avoid it you can write
% \begin{center}
% |something\Hyphdash* something|\quad or easier\quad
% |something\=/something|
% \end{center}
% (the last case is also shortcut). An example is the word
% \emph{$L$-approximation} which can't be broken at the dash.
%
% \DescribeMacro{\Endash}
% \DescribeMacro{\Endash*}
% Analogously, you can use |\Endash| command (may be with star) to join
% words by \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 unbreakable elastic space. All these commands have
% shortcuts, named
% \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
% typesetting rules. To decrease its length to required one you have
% to use |extdash| package with |cyremdash| option.
%
% \section{The Package Options}
%
% The |extdash| package provides two options, |shortcuts| and
% |cyremdash|:
% \begin{center}
% |\usepackage[shortcuts,cyremdash]{extdash}|
% \end{center}
%
% First 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.
%
% The last option redefines |\Emdash| to be shorter than the standard
% em-dash.
%
% \section{The Shortcuts Table}
%
% \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.}
%
% \StopEventually{}
%
% \section{The Basic Implementation Part}
%
% \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{\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@space}
% and then the basic commands
%    \begin{macrocode}
\def\EXD@dash#1{%
  \nobreak\leavevmode\hbox{#1}\EXD@break\hskip\z@skip \ignorespaces
}
\def\EXD@emd@sh{%
  \ifvmode
    \EXD@emdash\nobreak\hskip.35em
  \else
    \unskip\nobreak\@tempcnta\m@ne
    \EXD@space \EXD@emdash \EXD@break \EXD@space
  \fi \ignorespaces
}
%    \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.
%    \begin{macrocode}
\def\EXD@space{%
  \edef\@tempa{%
    \ifnum\@tempcnta<\z@ .4\else \ifnum \@tempcnta=\z@ .5\else .6\fi\fi
  }%
  \hskip \@tempa\fontdimen2\font \@plus .5\fontdimen3\font
  \@minus \@tempa\fontdimen4\font
  \@tempcnta -\@tempcnta
}
%    \end{macrocode}
% \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 |cyremdash| option.
%    \begin{macrocode}
\def\EXD@emdash{\leavevmode\hbox{---}}
%    \end{macrocode}
% \end{macro}
%
% \section{Shortcuts}
%
%    \begin{macrocode}
\DeclareOption{shortcuts}{%
%    \end{macrocode}
%
% \begin{macro}{\HyphOrDash}
% \begin{macro}{\BarOrDash}
% The commands |\HyphOrDash| and |\BarOrDash| will be called by |\-| and
% |\=| commands. They choose the corresponding shortcut or the original
% commands saved in |\EXD@hyph| and |\EXD@dash|.
%    \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}
%
% \section{Cyrillic Em-dash}
%
%    \begin{macrocode}
\DeclareOption{cyremdash}{%
  \def\EXD@emdash{\leavevmode\hb@xt@.8\fontdimen6\font{--\hss--}}
}
\ProcessOptions\relax
%</package>
%    \end{macrocode}
%
\endinput
