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
|
%%% ====================================================================
%%% @LaTeX-doc-source-file{
%%% filename = "textcmds.dtx",
%%% version = "1.05",
%%% date = "2002/04/16",
%%% time = "08:47:47 EDT",
%%% author = "Michael J Downes",
%%% address = "American Mathematical Society,
%%% Publications Technical Group,
%%% PO Box 6248,
%%% Providence, RI 02940,
%%% USA",
%%% email = "tech-support@ams.org",
%%% URL = "http://www.ams.org/",
%%% abstract = "Short forms for textemdash and the other LaTeX
%%% commands that correspond to ligatures of
%%% convenience.",
%%% checksum = "55773 283 1136 10227",
%%% docstring = "The checksum field, produced by Robert Solovay's
%%% checksum utility, gives CRC-16 checksum, lines,
%%% words, and characters.",
%%% }
%%% ====================================================================
% \iffalse
%<*driver>
\NeedsTeXFormat{LaTeX2e}
\documentclass{amsdtx}
% Undo some things defined by amsdtx.cls
\let\qq=\UnDefined \let\mdash=\UnDefined \let\ndash=\UnDefined
\usepackage{textcmds}
\begin{document}
\title{The \pkg{textcmds} package}
\author{Michael~J. Downes\\American Mathematical Society}
\date{Version \fileversion, \filedate}
\hDocInput{textcmds.dtx}
\end{document}
%</driver>
% \fi
%
% \maketitle
% \section{Introduction}
%
% The \pkg{textcmds} package provides shorthand commands for all the
% text symbols that are traditionally produced in \LaTeX{} documents
% by non-letter ligatures. One of the principal benefits of using
% these commands is that it makes translating your document from
% \LaTeX{} to some other form (e.g., HTML) easier and less bug-prone.
% But it also makes your document less dependent on the use of
% special font metric files having the required ligature information,
% and it makes it far easier to achieve special effects for the
%^^A Either don't use \mdash here, or add textcmds pkg in the driver.
% characters in question\textemdash for example, to add or not to add
% a small amount of extra space around an em-dash character. With the
% ligature method you have to manually add the space for each
% instance, whereas if you use the \verb'\mdash' command, it suffices
% to change the definition of \verb'\mdash' to suit your wishes.
%
% All of these definitions use the preferred
% font-encoding-independent \LaTeX{} commands to obtain the
% characters in question.
% \begin{center}
% \begin{tabular}{lll}
% \textbf{Command}& \textbf{Definition}& \textbf{Result}\\
% \cn{mdash}& \cn{textemdash}& \mdash\\
% \cn{ndash}& \cn{textendash}& \ndash\\
% \cn{qd}& \cn{textquestiondown}& \qd\\
% \cn{xd}& \cn{textexclamdown}& \xd\\
% \cn{ldq}& \cn{textquotedblleft}& \ldq\\
% \cn{rdq}& \cn{textquotedblright}& \rdq\\
% \cn{lq}& \cn{textquoteleft}& \lq\\
% \cn{rq}& \cn{textquoteright}& \rq
% \end{tabular}
% \end{center}
%
% This package also provides short forms for certain text
% symbols whose generic name is too long for convenient entry.
% (The \cn{cwm} command does not produce visible output but marks
% word boundaries in a compound word.)
% \begin{center}
% \begin{tabular}{lll}
% \textbf{Command}& \textbf{Definition}& \textbf{Result}\\
% \cn{bul}& \cn{textbullet}& \bul\\
% \cn{vsp}& \cn{textvisiblespace}& \vsp\\
% \cn{pdc}& \cn{textperiodcentered}& \pdc\\
% \cn{vrt}& \cn{textbar}& \vrt\\
% \cn{cir}& \cn{textasciicircum}& \cir\\
% \cn{til}& \cn{textasciitilde}& \til\\
% \cn{bsl}& \cn{textbackslash}& \bsl\\
% \cn{cwm}& \cn{textcompwordmark}& \cwm
% \end{tabular}
% \end{center}
%
% Finally, a few other miscellaneous commands are provided, including
% a quoting command \cn{qq}. It seems clearly consonant with other
% parts of \LaTeX{} to write \verb'\qq{...}' to quote a word or short
% phrase rather than \verb'\ldq ...\rdq'; and the use of higher-level
% markup is groundwork that must be laid if one should ever want to
% do anything more sophisticated at the boundaries of a quoted
% expression (such as automatically transposing the quote character
% with following punctuation, if traditional rather than logical
% punctuation style is desired).
%
% \begin{center}
% \begin{tabular}{lll}
% \textbf{Example}& \textbf{Definition}& \textbf{Result}\\
% \verb'\qq{some text}'& \verb'\ldq#1\rdq'& \qq{some text}\\
% \verb'\lara{some text}'& \verb'\textlangle#1\textrangle'&
% \lara{some text}\\
% \verb'Jello\tsup{TM}'& \textit{raise .9ex}\verb'{\supsize#1}'&
% Jello\tsup{TM}\\
% \verb'Jello\tsub{TM}'& \textit{lower .6ex}\verb'{\supsize#1}'&
% Jello\tsub{TM}\\
% \verb'a\tprime b'& \verb'\tsup{\textprimechar}'&
% a\tprime b
% \end{tabular}
% \end{center}
%
% \StopEventually{}
%
% \begin{macrocode}
%<*pkg>
% \end{macrocode}
%
% \section{Implementation}
%
% Package name, date, version number.
% \begin{macrocode}
\ProvidesPackage{textcmds}[2002/04/16 v1.05]
% \end{macrocode}
%
% Dashes and inverted beginning-of-sentence punctuation.
% \begin{macrocode}
\providecommand{\mdash}{\textemdash\penalty\exhyphenpenalty}
\providecommand{\ndash}{\textendash\penalty\exhyphenpenalty}
\newcommand{\qd}{\textquestiondown}
\newcommand{\xd}{\textexclamdown}
% \end{macrocode}
%
% Quote commands. Note that \cs{lq} and \cs{rq} are defined in the
% \LaTeX{} kernel to produce functionally different quote characters.
% \begin{macrocode}
\newcommand{\ldq}{\textquotedblleft}
\newcommand{\rdq}{\textquotedblright}
\newcommand{\lsq}{\textquoteleft}
\newcommand{\rsq}{\textquoteright}
% \end{macrocode}
%
% \begin{macrocode}
\newcommand{\bul}{\textbullet}%
\newcommand{\vsp}{\textvisiblespace}%
\newcommand{\pdc}{\textperiodcentered}%
\newcommand{\vrt}{\textbar}%
\newcommand{\cir}{\textasciicircum}%
\newcommand{\til}{\textasciitilde}%
\newcommand{\bsl}{\textbackslash}%
\newcommand{\cwm}{\textcompwordmark}%
% \end{macrocode}
%
% \begin{macrocode}
\providecommand{\qq}[1]{\ldq#1\/\rdq}
% \end{macrocode}
%
% Unlike \cs{textsuperscript} and \cs{textsubscript}, these do not
% use math mode at all. The difference between \cn{scriptsize} and
% \cn{supsize} is that the former is fixed at a single constant size
% regardless of context, whereas the latter adapts to the current
% font size.
% \begin{macrocode}
\newcommand{\supsize}{%
% \end{macrocode}
% Cf \cs{glb@settings}.
% \begin{macrocode}
\expandafter\ifx\csname S@\f@size\endcsname\relax
\calculate@math@sizes
\fi
\csname S@\f@size\endcsname
\fontsize\sf@size\z@\selectfont
}
\DeclareRobustCommand{\tsup}[1]{%
\leavevmode\raise.9ex\hbox{\supsize #1}%
}
\DeclareRobustCommand{\tsub}[1]{%
\leavevmode\lower.6ex\hbox{\supsize #1}%
}
% \end{macrocode}
%
% The \LaTeX{} kernel contains fallback definitions for various
% symbols that traditionally came from the \texttt{cmsy} font:
%\begin{verbatim}
%\DeclareTextSymbolDefault{\textbraceleft}{OMS}
%\end{verbatim}
% But there is no definition of that kind for the cmsy prime
% character that we want to use for \cn{tprime}. So we need to do it
% here.
% \begin{macrocode}
\DeclareTextSymbolDefault{\textprimechar}{OMS}
\DeclareTextSymbol{\textprimechar}{OMS}{48}
\DeclareRobustCommand{\tprime}{\tsup{\textprimechar}}
% \end{macrocode}
%
% And one more pair of symbols that are sometimes useful in text, yet
% do not have suitable text definitions in the \LaTeX{} kernel. (They
% do in the \pkg{textcomp} package.)
%
% If the \pkg{textcmds} package is loaded together with the
% \pkg{textcomp} package, we don't want to clobber the TS1 default.
% \begin{macrocode}
\@ifundefined{textlangle}{%
\DeclareTextSymbolDefault{\textlangle}{OMS}
\DeclareTextSymbolDefault{\textrangle}{OMS}
}{}
\DeclareTextSymbol{\textlangle}{OMS}{"68}
\DeclareTextSymbol{\textrangle}{OMS}{"69}
% \end{macrocode}
% Not sure what's the best name for the angle-brackets analog of the
% \cn{qq} command. How about ``lara'' for ``left-angle right-angle''?
%
% Unlike the quotes case, it is highly unlikely that the font
% contains kern information for the rangle character and the
% character preceding it! So let's put in an italic correction.
% \begin{macrocode}
\DeclareRobustCommand{\lara}[1]{\textlangle#1\/\textrangle}
% \end{macrocode}
%
% \begin{macrocode}
\csname endinput\endcsname
%</pkg>
% \end{macrocode}
%
% Do you want some Emacs code to convert \verb"--" to \cn{ndash} while
% you write? And \verb"``" to \verb'\qq{' ? Try this.
% \begin{macrocode}
<*emacs>
(defvar latex-ndash-command "\\ndash"
"*String to insert for an n-dash in LaTeX mode.")
(defvar latex-mdash-command "\\mdash"
"*String to insert for an m-dash in LaTeX mode.")
(defvar latex-quote-command "\\qq"
"*String to insert for quotes in LaTeX mode.")
(defun latex-maybe-start-quotes (arg)
"Insert the beginning of a \\qq{...} structure if the preceding char is
a left quote."
(interactive "*p")
(if (= (preceding-char) ?\`)
(progn
(delete-backward-char 1)
(insert-and-inherit (concat latex-quote-command "\{")))
(self-insert-command arg)))
(defun latex-maybe-end-quotes (arg)
"Insert the end of a \\qq{...} structure if appropriate."
(interactive "*p")
(if (= (preceding-char) ?\')
(progn
(delete-backward-char 1)
(insert-and-inherit "\}"))
(self-insert-command arg)))
(defun latex-maybe-dash (arg)
"Convert two or three hyphens to \\mdash or \\ndash."
(interactive "*p")
(cond
((re-search-backward
(concat (regexp-quote latex-ndash-command) " *\\=") nil t)
(replace-match (concat (regexp-quote latex-mdash-command) " ")))
((= (preceding-char) ?-)
(delete-backward-char 1)
(insert-and-inherit (concat latex-ndash-command " ")))
(t (self-insert-command arg))))
(add-hook 'TeX-mode-hook
'(lambda
(define-key LaTeX-mode-map "\`" 'latex-maybe-start-quotes)
(define-key LaTeX-mode-map "\'" 'latex-maybe-end-quotes)
(define-key LaTeX-mode-map "-" 'latex-maybe-dash)))
</emacs>
% \end{macrocode}
%
% \CheckSum{133}
% \Finale
|