Debian Codegraph @

texmf-dist/source/latex/seqsplit/seqsplit.dtx

raw
1 % \iffalse
2 %<*gobble>
3 % $Id: seqsplit.dtx,v 1.3 2006/08/08 00:02:08 boris Exp $
4 %
5 % Copyright 2006, Boris Veytsman <[email protected]>
6 % This work may be distributed and/or modified under the
7 % conditions of the LaTeX Project Public License, either
8 % version 1.3 of this license or (at your option) any
9 % later version.
10 % The latest version of the license is in
11 % http://www.latex-project.org/lppl.txt
12 % and version 1.3 or later is part of all distributions of
13 % LaTeX version 2003/06/01 or later.
14 %
15 % This work has the LPPL maintenance status `maintained'.
16 %
17 % The Current Maintainer of this work is Boris Veytsman
18 %
19 % This work consists of the file seqsplit.dtx and the
20 % derived files seqsplit.sty, seqsplit.dtx.
21 %
22 % \fi
23 % \CheckSum{50}
24 %
25 % \changes{v0.1}{2006/08/07}{The first released version}
26 %
27 %% \CharacterTable
28 %% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
29 %% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
30 %% Digits \0\1\2\3\4\5\6\7\8\9
31 %% Exclamation \! Double quote \" Hash (number) \#
32 %% Dollar \$ Percent \% Ampersand \&
33 %% Acute accent \' Left paren \( Right paren \)
34 %% Asterisk \* Plus \+ Comma \,
35 %% Minus \- Point \. Solidus \/
36 %% Colon \: Semicolon \; Less than \<
37 %% Equals \= Greater than \> Question mark \?
38 %% Commercial at \@ Left bracket \[ Backslash \\
39 %% Right bracket \] Circumflex \^ Underscore \_
40 %% Grave accent \` Left brace \{ Vertical bar \|
41 %% Right brace \} Tilde \~}
42 %
43 %\iffalse
44 % \begin{macrocode}
45 \documentclass{ltxdoc}
46 \usepackage{array}
47 \usepackage{url}
48 \usepackage{seqsplit}
49 \DoNotIndex{\NeedsTeXFormat, \ProvidesPackage, \def, \hspace}
50 \DoNotIndex{\futurelet, \@gobble, \ifx, \else, \fi, \relax}
51 \DoNotIndex{\ifmmode, \fi, \allowbreak}
52 \PageIndex
53 \CodelineIndex
54 \RecordChanges
55 \EnableCrossrefs
56 \begin{document}
57 \DocInput{seqsplit.dtx}
58 \end{document}
59 % \end{macrocode}
60 %</gobble>
61 % \fi
62 % \MakeShortVerb{|}
63 %
64 %\GetFileInfo{seqsplit.sty}
65 % \title{Splitting Long Sequences of Letters (DNA, RNA, Proteins,
66 % Etc.)\thanks{\copyright Boris Veytsman, 2006}}
67 % \author{Boris Veytsman}
68 % \date{\filedate, \fileversion}
69 % \maketitle
70 %
71 % \begin{abstract}
72 % Sometimes one needs to typeset long sentences of letters, which
73 % should not have spaces between them (like letters in words), but
74 % could be split between lines at any point, and without a
75 % hyphenation character. This package provides a command for such
76 % sequences.
77 % \end{abstract}
78 %
79 % \tableofcontents
80 %
81 % \clearpage
82 %
83 %\section{Introduction}
84 %\label{sec:intro}
85 %
86 % At a recent Practical\TeX{} conference (Practical\TeX-2006, Rutgers,
87 % New Jersey, USA, \url{http://www.tug.org/practicaltex2006}) Klaus
88 % H\"oppner asked, how one typesets long sequences like the ones
89 % related to DNA code. Usually there is no space between letters, but
90 % a sequence could be split at any point and continued on the next
91 % line. The audience suggested several solutions to this problem.
92 % One solution, for example, was to define a new language, where
93 % hyphenation is possible at any point, and hyphenation character is
94 % empty. However, this would require regeneration of all \TeX{}
95 % formats, which might be not practical or even not possible. Another
96 % solution, suggested, if my memory is right, by Peter Flynn, was to
97 % scan the sequence and insert a breaking point after each letter.
98 % This later approach is implemented in this package.
99 %
100 %
101 %
102 %\section{User Interface}
103 %\label{sec:interface}
104 %
105 %
106 %\subsection{Main Command}
107 %\label{sec:command}
108 %
109 % \DescribeMacro{\seqsplit}
110 % The main (and actually the only) command in this package is
111 % |\seqsplit|. Its usage is very simple, for example to typeset the
112 % gene HBB, related to sickle cell anaemia (actually, the
113 % corresponding mRNA Reference Sequence), we use the following:
114 % \begin{verbatim}
115 % \seqsplit{%
116 % acatttgcttctgacacaactgtgttcactagcaacctcaaacagacaccatggtgcatc%
117 % tgactcctgaggagaagtctgccgttactgccctgtggggcaaggtgaacgtggatgaag%
118 % ttggtggtgaggccctgggcaggctgctggtggtctacccttggacccagaggttctttg%
119 % agtcctttggggatctgtccactcctgatgctgttatgggcaaccctaaggtgaaggctc%
120 % atggcaagaaagtgctcggtgcctttagtgatggcctggctcacctggacaacctcaagg%
121 % gcacctttgccacactgagtgagctgcactgtgacaagctgcacgtggatcctgagaact%
122 % tcaggctcctgggcaacgtgctggtctgtgtgctggcccatcactttggcaaagaattca%
123 % ccccaccagtgcaggctgcctatcagaaagtggtggctggtgtggctaatgccctggccc%
124 % acaagtatcactaagctcgctttcttgctgtccaatttctattaaaggttcctttgttcc%
125 % ctaagtccaactactaaactgggggatattatgaagggccttgagcatctggattctgcc%
126 % taataaaaaacatttattttcattgc}.
127 % \end{verbatim}
128 % which produces
129 % \begin{quote}
130 % \seqsplit{%
131 % acatttgcttctgacacaactgtgttcactagcaacctcaaacagacaccatggtgcatc%
132 % tgactcctgaggagaagtctgccgttactgccctgtggggcaaggtgaacgtggatgaag%
133 % ttggtggtgaggccctgggcaggctgctggtggtctacccttggacccagaggttctttg%
134 % agtcctttggggatctgtccactcctgatgctgttatgggcaaccctaaggtgaaggctc%
135 % atggcaagaaagtgctcggtgcctttagtgatggcctggctcacctggacaacctcaagg%
136 % gcacctttgccacactgagtgagctgcactgtgacaagctgcacgtggatcctgagaact%
137 % tcaggctcctgggcaacgtgctggtctgtgtgctggcccatcactttggcaaagaattca%
138 % ccccaccagtgcaggctgcctatcagaaagtggtggctggtgtggctaatgccctggccc%
139 % acaagtatcactaagctcgctttcttgctgtccaatttctattaaaggttcctttgttcc%
140 % ctaagtccaactactaaactgggggatattatgaagggccttgagcatctggattctgcc%
141 % taataaaaaacatttattttcattgc}.
142 % \end{quote}
143 % Note that the breaking points in the code (commented out by \%) have
144 % nothing to do with the breaking points in the typeset sequence and
145 % are introduced only for readability of the code.
146 %
147 % The corresponding protein sequence ($\beta$-globulin) is shorter:
148 % \begin{verbatim}
149 % \seqsplit{%
150 % mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
151 % vkahgkkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvlvcvlahhfg%
152 % keftppvqaayqkvvagvanalahkyh}.
153 % \end{verbatim}
154 % \begin{quote}
155 % \seqsplit{%
156 % mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
157 % vkahgkkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvlvcvlahhfg%
158 % keftppvqaayqkvvagvanalahkyh}.
159 % \end{quote}
160 %
161 % The command works in math mode as well:
162 % \begin{verbatim}
163 % $\pi = \seqsplit{%
164 % 3.
165 % 1415926535 8979323846 2643383279 5028841971 6939937510
166 % 5820974944 5923078164 0628620899 8628034825 3421170679
167 % 8214808651 3282306647 0938446095 5058223172 5359408128
168 % 4811174502 8410270193 8521105559 6446229489 5493038196
169 % 4428810975 6659334461 2847564823 3786783165 2712019091
170 % 4564856692 3460348610 4543266482 1339360726 0249141273
171 % 7245870066 0631558817 4881520920 9628292540 9171536436
172 % 7892590360 0113305305 4882046652 1384146951 9415116094
173 % 3305727036 5759591953 0921861173 8193261179 3105118548
174 % 0744623799 6274956735 1885752724 8912279381 8301194912
175 % 9833673362 4406566430 8602139494 6395224737 1907021798
176 % 6094370277 0539217176 2931767523 8467481846 7669405132
177 % 0005681271 4526356082 7785771342 7577896091 7363717872
178 % 1468440901 2249534301 4654958537 1050792279 6892589235}
179 % \ldots$
180 % \end{verbatim}
181 % \begin{quote}
182 % $\pi = \seqsplit{%
183 % 3.
184 % 1415926535 8979323846 2643383279 5028841971 6939937510
185 % 5820974944 5923078164 0628620899 8628034825 3421170679
186 % 8214808651 3282306647 0938446095 5058223172 5359408128
187 % 4811174502 8410270193 8521105559 6446229489 5493038196
188 % 4428810975 6659334461 2847564823 3786783165 2712019091
189 % 4564856692 3460348610 4543266482 1339360726 0249141273
190 % 7245870066 0631558817 4881520920 9628292540 9171536436
191 % 7892590360 0113305305 4882046652 1384146951 9415116094
192 % 3305727036 5759591953 0921861173 8193261179 3105118548
193 % 0744623799 6274956735 1885752724 8912279381 8301194912
194 % 9833673362 4406566430 8602139494 6395224737 1907021798
195 % 6094370277 0539217176 2931767523 8467481846 7669405132
196 % 0005681271 4526356082 7785771342 7577896091 7363717872
197 % 1468440901 2249534301 4654958537 1050792279 6892589235}
198 % \ldots$
199 % \end{quote}
200 %
201 %\subsection{Customization}
202 %\label{sec:customization}
203 %
204 % \DescribeMacro{\seqinsert} The command |\seqsplit| can be customized
205 % by redefining the command |\seqinsert|, which is the macro that is
206 % inserted between the letters of the sequence. By default it is
207 % defined as |\allowbreak| in math mode and |\hspace{0pt plus 0.02em}|
208 % in text mode: a slightly stretchable glue of zero length. This
209 % definition gives \TeX{} a chance to justify the lines. However,
210 % there might be other definitions. For example, if we want hyphens
211 % at the breakpoints in text mode, we can use:
212 % \begin{quote}
213 % |\renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi}|
214 % \end{quote}
215 % which produces for the $\beta$-globulin protein from the previous
216 % section the following:
217 % \begin{quote}
218 % \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi}
219 % \seqsplit{%
220 % mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
221 % vkahgkkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvlvcvlahhfg%
222 % keftppvqaayqkvvagvanalahkyh}.
223 % \end{quote}
224 % Another redefinition,
225 % \begin{quote}
226 % |\renewcommand{\seqinsert}{\ifmmode\allowbreak\else{} \fi}|,
227 % \end{quote}
228 % produces an output with spaces between letters. Note that there is
229 % no space between the last letter and the dot: the package takes care
230 % of this:
231 % \begin{quote}
232 % \renewcommand{\seqinsert}{\ifmmode\allowbreak\else{} \fi}
233 % \seqsplit{%
234 % mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
235 % vkahgkkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvlvcvlahhfg%
236 % keftppvqaayqkvvagvanalahkyh}.
237 % \end{quote}
238 %
239 %
240 %
241 %\subsection{Grouping and Commands}
242 %\label{sec:grouping}
243 %
244 % The command |\seqsplit| does not insert breakpoints between the
245 % letters inside braces |{...}|. Compare the typesetting of
246 % $\beta$-globulin in Section~\ref{sec:command} and the following
247 % example:
248 % \begin{verbatim}
249 % \seqsplit{%
250 % mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
251 % v{kahg}kkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvlvcvlahhfg%
252 % keftppvqaayqkvvagvanalahkyh}.
253 % \end{verbatim}
254 % \begin{quote}
255 % \seqsplit{%
256 % mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
257 % v{kahg}kkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvlvcvlahhfg%
258 % keftppvqaayqkvvagvanalahkyh}.
259 % \end{quote}
260 % The braces around |{kahg}| prevented a splitting of this group.
261 % This effect can be used for typesetting special substrings inside
262 % sequences.
263 %
264 % The way |\seqsplit| works interferes with formatting commands like
265 % |\textit|. Therefore the sequence |{kahg}| is \emph{not} italicized
266 % in the following example:
267 % \begin{verbatim}
268 % \seqsplit{%
269 % mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
270 % v\textit{kahg}kkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvl%
271 % vcvlahhfgkeftppvqaayqkvvagvanalahkyh}.
272 % \end{verbatim}
273 % \begin{quote}
274 % \seqsplit{%
275 % mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
276 % v\textit{kahg}kkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvl%
277 % vcvlahhfgkeftppvqaayqkvvagvanalahkyh}.
278 % \end{quote}
279 %
280 % Using grouping |{\textit{kahg}}| we can save the situation:
281 % \begin{verbatim}
282 % \seqsplit{%
283 % mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
284 % v{\textit{kahg}}kkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvl%
285 % vcvlahhfgkeftppvqaayqkvvagvanalahkyh}.
286 % \end{verbatim}
287 % \begin{quote}
288 % \seqsplit{%
289 % mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
290 % v{\textit{kahg}}kkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvl%
291 % vcvlahhfgkeftppvqaayqkvvagvanalahkyh}.
292 % \end{quote}
293 %
294 % If we want the italicized sequence to be splittable as well, we can
295 % use \emph{nested} |\seqsplit|:
296 % \begin{verbatim}
297 % \seqsplit{%
298 % mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
299 % v{\textit{\seqsplit{kahg}}}kkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvl%
300 % vcvlahhfgkeftppvqaayqkvvagvanalahkyh}.
301 % \end{verbatim}
302 % \begin{quote}
303 % \seqsplit{%
304 % mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
305 % v{\textit{\seqsplit{kahg}}}kkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvl%
306 % vcvlahhfgkeftppvqaayqkvvagvanalahkyh}.
307 % \end{quote}
308 %
309 % These tricks allow one to produce splittable sequences with a rather
310 % complex formatting.
311 %
312 %
313 %\StopEventually{}
314 %
315 % \clearpage
316 %
317 % \section{Implementation}
318 % \label{sec:implementation}
319 %
320 %
321 %\subsection{Declarations}
322 %\label{sec:decl}
323 %
324 % We start with declaration, who we are:
325 %
326 %
327 % \begin{macrocode}
328 %<*style>
329 \NeedsTeXFormat{LaTeX2e}
330 \ProvidesPackage{seqsplit}
331 [2006/08/07 v0.1 Splitting long sequences (DNA, RNA, proteins, etc.) ]
332 % \end{macrocode}
333 %
334 %
335 %
336 %
337 %\subsection{Inserted Text}
338 %\label{sec:insertion}
339 %
340 %
341 % \begin{macro}{\seqinsert}
342 % This is the macro we insert between letters:
343 % \begin{macrocode}
344 \def\seqinsert{\ifmmode\allowbreak\else\hspace{0pt plus 0.02em}\fi}
345 % \end{macrocode}
346 % \end{macro}
347 %
348 %
349 %
350 %\subsection{Scanner}
351 %\label{sec:scanner}
352 %
353 % The scanner code is not too trivial. Here we describe it in detail.
354 %
355 % \begin{macro}{\seqsplit}
356 % The main (actually, the only) user-space macro just starts the
357 % scanner.
358 % \begin{macrocode}
359 \def\seqsplit#1{\SQSPL@scan#1\SQSPL@end}
360 % \end{macrocode}
361 % \end{macro}
362 %
363 % The macro |\SQSPL@end| is never expanded, it is just a marker.
364 % \begin{macro}{\SQSPL@scan}
365 % The macro |\SQSPL@scan| saves the next token in the special
366 % register |\SQSPL@next|, so we can decide what to do with it:
367 % \begin{macrocode}
368 \def\SQSPL@scan{\futurelet\SQSPL@next\SQSPL@scani}
369 % \end{macrocode}
370 % \end{macro}
371 % \begin{macro}{\SQSPL@scani}
372 % Now since we know the next token, we can decide to either stop the
373 % expansion if we met the end, or continue it if we did not.
374 % \begin{macrocode}
375 \def\SQSPL@scani#1{%
376 \ifx \SQSPL@end \SQSPL@next \def\SQSPL@process{\@gobble}%
377 \else \def\SQSPL@process{\SQSPL@doprocess}\fi%
378 \SQSPL@process{#1}}
379 % \end{macrocode}
380 % \end{macro}
381 % \begin{macro}{\SQSPL@doprocess}
382 % The processing of a letter depends on what is the next letter. If
383 % the sequence is finished, we should not insert anything after the
384 % last letter: we do not want to break the line between the sequence
385 % and, say, a comma. Therefore we insert a special smart macro:
386 % \begin{macrocode}
387 \def\SQSPL@doprocess#1{#1\SQSPL@insert}
388 % \end{macrocode}
389 % \end{macro}
390 % \begin{macro}{\SQSPL@insert}
391 % The macro |\SQSPL@insert| uses |\futurelet| to check whether the
392 % processed letter is the last one in the sentence:
393 % \begin{macrocode}
394 \def\SQSPL@insert{\futurelet\SQSPL@next\SQSPL@doinsert}
395 % \end{macrocode}
396 % \end{macro}
397 % \begin{macro}{\SQSPL@doinsert}
398 % And this is the macro that inserts |\seqinsert| and continues
399 % scanning:
400 % \begin{macrocode}
401 \def\SQSPL@doinsert{%
402 \ifx \SQSPL@end \SQSPL@next \relax%
403 \else \seqinsert \fi%
404 \SQSPL@scan}
405 % \end{macrocode}
406 % \end{macro}
407 %
408 %
409 %\subsection{The Last Words}
410 %\label{sec:last}
411 %
412 %
413 %
414 % \begin{macrocode}
415 %</style>
416 % \end{macrocode}
417 %\Finale
418 %\clearpage
419 %
420 %\PrintChanges
421 %\clearpage
422 %\PrintIndex
423 %
424 \endinput