Debian Codegraph @

texmf-dist/source/latex/amsrefs/textcmds.dtx

raw
1 % \def\filename{textcmds.dtx}
2 % \def\fileversion{2.00}
3 % \def\filedate{2012/08/02}
4 %
5 % \iffalse meta-comment
6 %
7 % American Mathematical Society
8 % Technical Support
9 % Publications Technical Group
10 % 201 Charles Street
11 % Providence, RI 02904
12 % USA
13 % tel: (401) 455-4080
14 % (800) 321-4267 (USA and Canada only)
15 % fax: (401) 331-3842
16 % email: [email protected]
17 %
18 % Copyright 2001, 2010 American Mathematical Society.
19 %
20 % This work may be distributed and/or modified under the
21 % conditions of the LaTeX Project Public License, either version 1.3c
22 % of this license or (at your option) any later version.
23 % The latest version of this license is in
24 % http://www.latex-project.org/lppl.txt
25 % and version 1.3c or later is part of all distributions of LaTeX
26 % version 2005/12/01 or later.
27 %
28 % This work has the LPPL maintenance status `maintained'.
29 %
30 % The Current Maintainer of this work is the American Mathematical
31 % Society.
32 %
33 % \fi
34 %
35 % \iffalse
36 %<*driver>
37 \NeedsTeXFormat{LaTeX2e}
38 \documentclass{amsdtx}
39 % Undo some things defined by amsdtx.cls
40 \let\qq=\UnDefined \let\mdash=\UnDefined \let\ndash=\UnDefined
41 \usepackage{textcmds}
42 \begin{document}
43 \title{The \pkg{textcmds} package}
44 \author{Michael~J. Downes\\American Mathematical Society}
45 \date{Version \fileversion, \filedate}
46 \DocInput{textcmds.dtx}
47 \end{document}
48 %</driver>
49 % \fi
50 %
51 % \maketitle
52 % \section{Introduction}
53 %
54 % The \pkg{textcmds} package provides shorthand commands for all the
55 % text symbols that are traditionally produced in \LaTeX{} documents
56 % by non-letter ligatures. One of the principal benefits of using
57 % these commands is that it makes translating your document from
58 % \LaTeX{} to some other form (e.g., HTML) easier and less bug-prone.
59 % But it also makes your document less dependent on the use of
60 % special font metric files having the required ligature information,
61 % and it makes it far easier to achieve special effects for the
62 %^^A Either don't use \mdash here, or add textcmds pkg in the driver.
63 % characters in question\textemdash for example, to add or not to add
64 % a small amount of extra space around an em-dash character. With the
65 % ligature method you have to manually add the space for each
66 % instance, whereas if you use the \verb'\mdash' command, it suffices
67 % to change the definition of \verb'\mdash' to suit your wishes.
68 %
69 % All of these definitions use the preferred
70 % font-encoding-independent \LaTeX{} commands to obtain the
71 % characters in question.
72 % \begin{center}
73 % \begin{tabular}{lll}
74 % \textbf{Command}& \textbf{Definition}& \textbf{Result}\\
75 % \cn{mdash}& \cn{textemdash}& \mdash\\
76 % \cn{ndash}& \cn{textendash}& \ndash\\
77 % \cn{qd}& \cn{textquestiondown}& \qd\\
78 % \cn{xd}& \cn{textexclamdown}& \xd\\
79 % \cn{ldq}& \cn{textquotedblleft}& \ldq\\
80 % \cn{rdq}& \cn{textquotedblright}& \rdq\\
81 % \cn{lq}& \cn{textquoteleft}& \lq\\
82 % \cn{rq}& \cn{textquoteright}& \rq
83 % \end{tabular}
84 % \end{center}
85 %
86 % This package also provides short forms for certain text
87 % symbols whose generic name is too long for convenient entry.
88 % (The \cn{cwm} command does not produce visible output but marks
89 % word boundaries in a compound word.)
90 % \begin{center}
91 % \begin{tabular}{lll}
92 % \textbf{Command}& \textbf{Definition}& \textbf{Result}\\
93 % \cn{bul}& \cn{textbullet}& \bul\\
94 % \cn{vsp}& \cn{textvisiblespace}& \vsp\\
95 % \cn{pdc}& \cn{textperiodcentered}& \pdc\\
96 % \cn{vrt}& \cn{textbar}& \vrt\\
97 % \cn{cir}& \cn{textasciicircum}& \cir\\
98 % \cn{til}& \cn{textasciitilde}& \til\\
99 % \cn{bsl}& \cn{textbackslash}& \bsl\\
100 % \cn{cwm}& \cn{textcompwordmark}& \cwm
101 % \end{tabular}
102 % \end{center}
103 %
104 % Finally, a few other miscellaneous commands are provided, including
105 % a quoting command \cn{qq}. It seems clearly consonant with other
106 % parts of \LaTeX{} to write \verb'\qq{...}' to quote a word or short
107 % phrase rather than \verb'\ldq ...\rdq'; and the use of higher-level
108 % markup is groundwork that must be laid if one should ever want to
109 % do anything more sophisticated at the boundaries of a quoted
110 % expression (such as automatically transposing the quote character
111 % with following punctuation, if traditional rather than logical
112 % punctuation style is desired).
113 %
114 % \begin{center}
115 % \begin{tabular}{lll}
116 % \textbf{Example}& \textbf{Definition}& \textbf{Result}\\
117 % \verb'\qq{some text}'& \verb'\ldq#1\/\rdq'& \qq{some text}\\
118 % \verb'\q{some text}'& \verb'\lq#1\/\rq'& \q{some text}\\
119 % \verb'\lara{some text}'& \verb'\textlangle#1\textrangle'&
120 % \lara{some text}\\
121 % \verb'Jello\tsup{TM}'& \textit{raise .9ex}\verb'{\supsize#1}'&
122 % Jello\tsup{TM}\\
123 % \verb'Jello\tsub{TM}'& \textit{lower .6ex}\verb'{\supsize#1}'&
124 % Jello\tsub{TM}\\
125 % \verb'a\tprime b'& \verb'\tsup{\textprimechar}'&
126 % a\tprime b
127 % \end{tabular}
128 % \end{center}
129 %
130 % \StopEventually{}
131 %
132 % \begin{macrocode}
133 %<*pkg>
134 % \end{macrocode}
135 %
136 % \section{Implementation}
137 %
138 % Package name, date, version number.
139 % \begin{macrocode}
140 \ProvidesPackage{textcmds}[2012/08/02 v2.00]
141 % \end{macrocode}
142 %
143 % Dashes and inverted beginning-of-sentence punctuation.
144 % \begin{macrocode}
145 \providecommand{\mdash}{\textemdash\penalty\exhyphenpenalty}
146 \providecommand{\ndash}{\textendash\penalty\exhyphenpenalty}
147 \providecommand{\qd}{\textquestiondown}
148 \providecommand{\xd}{\textexclamdown}
149 % \end{macrocode}
150 %
151 % Quote commands. Note that \cs{lq} and \cs{rq} are defined in the
152 % \LaTeX{} kernel to produce functionally different quote characters.
153 % \begin{macrocode}
154 \providecommand{\ldq}{\textquotedblleft}
155 \providecommand{\rdq}{\textquotedblright}
156 \providecommand{\lsq}{\textquoteleft}
157 \providecommand{\rsq}{\textquoteright}
158 % \end{macrocode}
159 %
160 % \begin{macrocode}
161 \providecommand{\bul}{\textbullet}%
162 \providecommand{\vsp}{\textvisiblespace}%
163 \providecommand{\pdc}{\textperiodcentered}%
164 \providecommand{\vrt}{\textbar}%
165 \providecommand{\cir}{\textasciicircum}%
166 \providecommand{\til}{\textasciitilde}%
167 \providecommand{\bsl}{\textbackslash}%
168 \providecommand{\cwm}{\textcompwordmark}%
169 % \end{macrocode}
170 %
171 % \begin{macrocode}
172 \providecommand{\qq}[1]{\ldq#1\/\rdq}
173 % \end{macrocode}
174 %
175 %
176 % \begin{macrocode}
177 \providecommand{\q}[1]{\lq#1\/\rq}
178 % \end{macrocode}
179 %
180 % Unlike \cs{textsuperscript} and \cs{textsubscript}, these do not
181 % use math mode at all. The difference between \cn{scriptsize} and
182 % \cn{supsize} is that the former is fixed at a single constant size
183 % regardless of context, whereas the latter adapts to the current
184 % font size.
185 % \begin{macrocode}
186 \newcommand{\supsize}{%
187 % \end{macrocode}
188 % Cf \cs{glb@settings}.
189 % \begin{macrocode}
190 \expandafter\ifx\csname S@\f@size\endcsname\relax
191 \calculate@math@sizes
192 \fi
193 \csname S@\f@size\endcsname
194 \fontsize\sf@size\z@\selectfont
195 }
196 \DeclareRobustCommand{\tsup}[1]{%
197 \leavevmode\raise.9ex\hbox{\supsize #1}%
198 }
199 \DeclareRobustCommand{\tsub}[1]{%
200 \leavevmode\lower.6ex\hbox{\supsize #1}%
201 }
202 % \end{macrocode}
203 %
204 % The \LaTeX{} kernel contains fallback definitions for various
205 % symbols that traditionally came from the \texttt{cmsy} font:
206 %\begin{verbatim}
207 %\DeclareTextSymbolDefault{\textbraceleft}{OMS}
208 %\end{verbatim}
209 % But there is no definition of that kind for the cmsy prime
210 % character that we want to use for \cn{tprime}. So we need to do it
211 % here.
212 % \begin{macrocode}
213 \DeclareTextSymbolDefault{\textprimechar}{OMS}
214 \DeclareTextSymbol{\textprimechar}{OMS}{48}
215 \DeclareRobustCommand{\tprime}{\tsup{\textprimechar}}
216 % \end{macrocode}
217 %
218 % And one more pair of symbols that are sometimes useful in text, yet
219 % do not have suitable text definitions in the \LaTeX{} kernel. (They
220 % do in the \pkg{textcomp} package.)
221 %
222 % If the \pkg{textcmds} package is loaded together with the
223 % \pkg{textcomp} package, we don't want to clobber the TS1 default.
224 % \begin{macrocode}
225 \@ifundefined{textlangle}{%
226 \DeclareTextSymbolDefault{\textlangle}{OMS}
227 \DeclareTextSymbolDefault{\textrangle}{OMS}
228 }{}
229 \DeclareTextSymbol{\textlangle}{OMS}{"68}
230 \DeclareTextSymbol{\textrangle}{OMS}{"69}
231 % \end{macrocode}
232 % Not sure what's the best name for the angle-brackets analog of the
233 % \cn{qq} command. How about ``lara'' for ``left-angle right-angle''?
234 %
235 % Unlike the quotes case, it is highly unlikely that the font
236 % contains kern information for the rangle character and the
237 % character preceding it! So let's put in an italic correction.
238 % \begin{macrocode}
239 \DeclareRobustCommand{\lara}[1]{\textlangle#1\/\textrangle}
240 % \end{macrocode}
241 %
242 % \begin{macrocode}
243 \csname endinput\endcsname
244 %</pkg>
245 % \end{macrocode}
246 %
247 % Do you want some Emacs code to convert \verb"--" to \cn{ndash} while
248 % you write? And \verb"``" to \verb'\qq{' ? Try this.
249 % \begin{macrocode}
250 <*emacs>
251 (defvar latex-ndash-command "\\ndash"
252 "*String to insert for an n-dash in LaTeX mode.")
253
254 (defvar latex-mdash-command "\\mdash"
255 "*String to insert for an m-dash in LaTeX mode.")
256
257 (defvar latex-quote-command "\\qq"
258 "*String to insert for quotes in LaTeX mode.")
259
260 (defun latex-maybe-start-quotes (arg)
261 "Insert the beginning of a \\qq{...} structure if the preceding char is
262 a left quote."
263 (interactive "*p")
264 (if (= (preceding-char) ?\`)
265 (progn
266 (delete-backward-char 1)
267 (insert-and-inherit (concat latex-quote-command "\{")))
268 (self-insert-command arg)))
269
270 (defun latex-maybe-end-quotes (arg)
271 "Insert the end of a \\qq{...} structure if appropriate."
272 (interactive "*p")
273 (if (= (preceding-char) ?\')
274 (progn
275 (delete-backward-char 1)
276 (insert-and-inherit "\}"))
277 (self-insert-command arg)))
278
279 (defun latex-maybe-dash (arg)
280 "Convert two or three hyphens to \\mdash or \\ndash."
281 (interactive "*p")
282 (cond
283 ((re-search-backward
284 (concat (regexp-quote latex-ndash-command) " *\\=") nil t)
285 (replace-match (concat (regexp-quote latex-mdash-command) " ")))
286 ((= (preceding-char) ?-)
287 (delete-backward-char 1)
288 (insert-and-inherit (concat latex-ndash-command " ")))
289 (t (self-insert-command arg))))
290
291 (add-hook 'TeX-mode-hook
292 '(lambda
293 (define-key LaTeX-mode-map "\`" 'latex-maybe-start-quotes)
294 (define-key LaTeX-mode-map "\'" 'latex-maybe-end-quotes)
295 (define-key LaTeX-mode-map "-" 'latex-maybe-dash)))
296 </emacs>
297 % \end{macrocode}
298 %
299 % \CheckSum{138}
300 % \Finale