summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/seqsplit/seqsplit.dtx
blob: 7c5b6874db4ccd5333c334cbabe1afae7209b006 (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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
% \iffalse
%<*gobble>
% $Id: seqsplit.dtx,v 1.3 2006/08/08 00:02:08 boris Exp $
%
% Copyright 2006, Boris Veytsman <borisv@lk.net>
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3 of this license or (at your option) any 
% later version.
% The latest version of the license is in
%    http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of
% LaTeX version 2003/06/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Boris Veytsman
%
% This work consists of the file seqsplit.dtx and the
% derived files seqsplit.sty, seqsplit.dtx. 
%
% \fi 
% \CheckSum{50}
%
% \changes{v0.1}{2006/08/07}{The first released version}
%
%% \CharacterTable
%%  {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
%%   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
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~} 
%
%\iffalse
%    \begin{macrocode}
\documentclass{ltxdoc}
\usepackage{array}
\usepackage{url}
\usepackage{seqsplit}
\DoNotIndex{\NeedsTeXFormat, \ProvidesPackage, \def, \hspace}
\DoNotIndex{\futurelet, \@gobble, \ifx, \else, \fi, \relax}
\DoNotIndex{\ifmmode, \fi, \allowbreak}
\PageIndex
\CodelineIndex
\RecordChanges
\EnableCrossrefs
\begin{document}
  \DocInput{seqsplit.dtx}
\end{document}
%    \end{macrocode}
%</gobble> 
% \fi
% \MakeShortVerb{|}
%
%\GetFileInfo{seqsplit.sty}
% \title{Splitting Long Sequences of Letters (DNA, RNA, Proteins,
%   Etc.)\thanks{\copyright Boris Veytsman, 2006}}
% \author{Boris Veytsman}
% \date{\filedate, \fileversion}
% \maketitle
%
% \begin{abstract}
%   Sometimes one needs to typeset long sentences of letters, which
%   should not have spaces between them (like letters in words), but
%   could be split between lines at any point, and without a
%   hyphenation character.  This package provides a command for such
%   sequences. 
% \end{abstract}
%
% \tableofcontents
%
% \clearpage
%
%\section{Introduction}
%\label{sec:intro}
%
% At a recent Practical\TeX{} conference (Practical\TeX-2006, Rutgers,
% New Jersey, USA, \url{http://www.tug.org/practicaltex2006}) Klaus
% H\"oppner asked, how one typesets long sequences like the ones
% related to DNA code.  Usually there is no space between letters, but
% a sequence could be split at any point and continued on the next
% line.   The audience suggested several solutions to this problem.
% One solution, for example, was to define a new language, where
% hyphenation is possible at any point, and hyphenation character is
% empty.  However, this would require regeneration of all \TeX{}
% formats, which might be not practical or even not possible.  Another
% solution, suggested, if my memory is right, by Peter Flynn, was to
% scan the sequence and insert a breaking point after each letter.
% This later approach is implemented in this package.
%
%
%
%\section{User Interface}
%\label{sec:interface}
%
%
%\subsection{Main Command}
%\label{sec:command}
%
% \DescribeMacro{\seqsplit}
% The main (and actually the only) command in this package is
% |\seqsplit|.  Its usage is very simple, for example to typeset the
% gene HBB, related to sickle cell anaemia (actually, the
% corresponding mRNA Reference Sequence), we use the following:
% \begin{verbatim}
% \seqsplit{%
% acatttgcttctgacacaactgtgttcactagcaacctcaaacagacaccatggtgcatc%
% tgactcctgaggagaagtctgccgttactgccctgtggggcaaggtgaacgtggatgaag%
% ttggtggtgaggccctgggcaggctgctggtggtctacccttggacccagaggttctttg%
% agtcctttggggatctgtccactcctgatgctgttatgggcaaccctaaggtgaaggctc%
% atggcaagaaagtgctcggtgcctttagtgatggcctggctcacctggacaacctcaagg%
% gcacctttgccacactgagtgagctgcactgtgacaagctgcacgtggatcctgagaact%
% tcaggctcctgggcaacgtgctggtctgtgtgctggcccatcactttggcaaagaattca%
% ccccaccagtgcaggctgcctatcagaaagtggtggctggtgtggctaatgccctggccc%
% acaagtatcactaagctcgctttcttgctgtccaatttctattaaaggttcctttgttcc%
% ctaagtccaactactaaactgggggatattatgaagggccttgagcatctggattctgcc%
% taataaaaaacatttattttcattgc}.
% \end{verbatim}
% which produces
% \begin{quote}
% \seqsplit{%
% acatttgcttctgacacaactgtgttcactagcaacctcaaacagacaccatggtgcatc%
% tgactcctgaggagaagtctgccgttactgccctgtggggcaaggtgaacgtggatgaag%
% ttggtggtgaggccctgggcaggctgctggtggtctacccttggacccagaggttctttg%
% agtcctttggggatctgtccactcctgatgctgttatgggcaaccctaaggtgaaggctc%
% atggcaagaaagtgctcggtgcctttagtgatggcctggctcacctggacaacctcaagg%
% gcacctttgccacactgagtgagctgcactgtgacaagctgcacgtggatcctgagaact%
% tcaggctcctgggcaacgtgctggtctgtgtgctggcccatcactttggcaaagaattca%
% ccccaccagtgcaggctgcctatcagaaagtggtggctggtgtggctaatgccctggccc%
% acaagtatcactaagctcgctttcttgctgtccaatttctattaaaggttcctttgttcc%
% ctaagtccaactactaaactgggggatattatgaagggccttgagcatctggattctgcc%
% taataaaaaacatttattttcattgc}.
% \end{quote}
% Note that the breaking points in the code (commented out by \%) have
% nothing to do with the breaking points in the typeset sequence and
% are introduced only for readability of the code.
%
% The corresponding protein sequence ($\beta$-globulin) is shorter:
% \begin{verbatim}
% \seqsplit{%
% mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
% vkahgkkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvlvcvlahhfg%
% keftppvqaayqkvvagvanalahkyh}.
% \end{verbatim}
% \begin{quote}
% \seqsplit{%
% mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
% vkahgkkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvlvcvlahhfg%
% keftppvqaayqkvvagvanalahkyh}.
% \end{quote}
%
% The command works in math mode as well:
% \begin{verbatim}
% $\pi = \seqsplit{%
% 3.
% 1415926535 8979323846 2643383279 5028841971 6939937510
% 5820974944 5923078164 0628620899 8628034825 3421170679
% 8214808651 3282306647 0938446095 5058223172 5359408128
% 4811174502 8410270193 8521105559 6446229489 5493038196
% 4428810975 6659334461 2847564823 3786783165 2712019091
% 4564856692 3460348610 4543266482 1339360726 0249141273
% 7245870066 0631558817 4881520920 9628292540 9171536436
% 7892590360 0113305305 4882046652 1384146951 9415116094
% 3305727036 5759591953 0921861173 8193261179 3105118548
% 0744623799 6274956735 1885752724 8912279381 8301194912
% 9833673362 4406566430 8602139494 6395224737 1907021798
% 6094370277 0539217176 2931767523 8467481846 7669405132
% 0005681271 4526356082 7785771342 7577896091 7363717872
% 1468440901 2249534301 4654958537 1050792279 6892589235}
% \ldots$
% \end{verbatim}
% \begin{quote}
% $\pi = \seqsplit{%
% 3.
% 1415926535 8979323846 2643383279 5028841971 6939937510
% 5820974944 5923078164 0628620899 8628034825 3421170679
% 8214808651 3282306647 0938446095 5058223172 5359408128
% 4811174502 8410270193 8521105559 6446229489 5493038196
% 4428810975 6659334461 2847564823 3786783165 2712019091
% 4564856692 3460348610 4543266482 1339360726 0249141273
% 7245870066 0631558817 4881520920 9628292540 9171536436
% 7892590360 0113305305 4882046652 1384146951 9415116094
% 3305727036 5759591953 0921861173 8193261179 3105118548
% 0744623799 6274956735 1885752724 8912279381 8301194912
% 9833673362 4406566430 8602139494 6395224737 1907021798
% 6094370277 0539217176 2931767523 8467481846 7669405132
% 0005681271 4526356082 7785771342 7577896091 7363717872
% 1468440901 2249534301 4654958537 1050792279 6892589235}
% \ldots$
% \end{quote}
%
%\subsection{Customization}
%\label{sec:customization}
%
% \DescribeMacro{\seqinsert} The command |\seqsplit| can be customized
% by redefining the command |\seqinsert|, which is the macro that is
% inserted between the letters of the sequence.  By default it is
% defined as |\allowbreak| in math mode and |\hspace{0pt plus 0.02em}|
% in text mode: a slightly stretchable glue of zero length.  This
% definition gives \TeX{} a chance to justify the lines.  However,
% there might be other definitions.  For example, if we want hyphens
% at the breakpoints in text mode, we can use:
% \begin{quote}
%   |\renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi}|
% \end{quote}
% which produces for the $\beta$-globulin protein from the previous
% section the following:
% \begin{quote}
%   \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi}
% \seqsplit{%
% mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
% vkahgkkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvlvcvlahhfg%
% keftppvqaayqkvvagvanalahkyh}.
% \end{quote}
% Another redefinition,
% \begin{quote}
%   |\renewcommand{\seqinsert}{\ifmmode\allowbreak\else{} \fi}|,
% \end{quote}
% produces an output with spaces between letters.  Note that there is
% no space between the last letter and the dot: the package takes care
% of this:
% \begin{quote}
%   \renewcommand{\seqinsert}{\ifmmode\allowbreak\else{} \fi}
% \seqsplit{%
% mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
% vkahgkkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvlvcvlahhfg%
% keftppvqaayqkvvagvanalahkyh}.
% \end{quote}
% 
%
%
%\subsection{Grouping and Commands}
%\label{sec:grouping}
%
% The command |\seqsplit| does not insert breakpoints between the
% letters inside braces |{...}|.  Compare the typesetting of
% $\beta$-globulin in Section~\ref{sec:command} and the following
% example:
% \begin{verbatim}
% \seqsplit{%
% mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
% v{kahg}kkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvlvcvlahhfg%
% keftppvqaayqkvvagvanalahkyh}.
% \end{verbatim}
% \begin{quote}
% \seqsplit{%
% mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
% v{kahg}kkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvlvcvlahhfg%
% keftppvqaayqkvvagvanalahkyh}.
% \end{quote}
% The braces around |{kahg}| prevented a splitting of this group.
% This effect can be used for typesetting special substrings inside
% sequences.
%
% The way |\seqsplit| works interferes with formatting commands like
% |\textit|.  Therefore the sequence |{kahg}| is \emph{not} italicized
% in the following example:
% \begin{verbatim}
% \seqsplit{%
% mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
% v\textit{kahg}kkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvl%
% vcvlahhfgkeftppvqaayqkvvagvanalahkyh}.
% \end{verbatim}
% \begin{quote}
% \seqsplit{%
% mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
% v\textit{kahg}kkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvl%
% vcvlahhfgkeftppvqaayqkvvagvanalahkyh}.
% \end{quote}
%
% Using grouping |{\textit{kahg}}| we can save the situation:
% \begin{verbatim}
% \seqsplit{%
% mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
% v{\textit{kahg}}kkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvl%
% vcvlahhfgkeftppvqaayqkvvagvanalahkyh}.
% \end{verbatim}
% \begin{quote}
% \seqsplit{%
% mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
% v{\textit{kahg}}kkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvl%
% vcvlahhfgkeftppvqaayqkvvagvanalahkyh}.
% \end{quote}
%
% If we want the italicized sequence to be splittable as well, we can
% use \emph{nested} |\seqsplit|:
% \begin{verbatim}
% \seqsplit{%
% mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
% v{\textit{\seqsplit{kahg}}}kkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvl%
% vcvlahhfgkeftppvqaayqkvvagvanalahkyh}.
% \end{verbatim}
% \begin{quote}
% \seqsplit{%
% mvhltpeeksavtalwgkvnvdevggealgrllvvypwtqrffesfgdlstpdavmgnpk%
% v{\textit{\seqsplit{kahg}}}kkvlgafsdglahldnlkgtfatlselhcdklhvdpenfrllgnvl%
% vcvlahhfgkeftppvqaayqkvvagvanalahkyh}.
% \end{quote}
%
% These tricks allow one to produce splittable sequences with a rather
% complex formatting.
%
%
%\StopEventually{}
%
% \clearpage
% 
% \section{Implementation}
% \label{sec:implementation}
% 
%
%\subsection{Declarations}
%\label{sec:decl}
% 
%  We start with declaration, who we are:
%
%
%    \begin{macrocode}
%<*style>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{seqsplit}
[2006/08/07 v0.1 Splitting long sequences (DNA, RNA, proteins, etc.) ]
%    \end{macrocode}
%
%
%
%
%\subsection{Inserted Text}
%\label{sec:insertion}
%
% 
% \begin{macro}{\seqinsert}
%   This is the macro we insert between letters:
%    \begin{macrocode}
\def\seqinsert{\ifmmode\allowbreak\else\hspace{0pt plus 0.02em}\fi}
%    \end{macrocode}
% \end{macro}
% 
% 
%
%\subsection{Scanner}
%\label{sec:scanner}
%
% The scanner code is not too trivial.  Here we describe it in detail.
%
% \begin{macro}{\seqsplit}
%   The main (actually, the only) user-space macro just starts the
%   scanner.
%    \begin{macrocode}
\def\seqsplit#1{\SQSPL@scan#1\SQSPL@end}
%    \end{macrocode}
% \end{macro}
%
% The macro |\SQSPL@end| is never expanded, it is just a marker.  
% \begin{macro}{\SQSPL@scan}
%   The macro |\SQSPL@scan| saves the next token in the special
%   register |\SQSPL@next|, so we can decide what to do with it:
%    \begin{macrocode}
\def\SQSPL@scan{\futurelet\SQSPL@next\SQSPL@scani}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\SQSPL@scani}
%   Now since we know the next token, we can decide to either stop the
%   expansion if we met the end, or continue it if we did not.
%    \begin{macrocode}
\def\SQSPL@scani#1{%
  \ifx \SQSPL@end \SQSPL@next \def\SQSPL@process{\@gobble}%
  \else \def\SQSPL@process{\SQSPL@doprocess}\fi%
  \SQSPL@process{#1}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\SQSPL@doprocess}
%   The processing of a letter depends on what is the next letter.  If
%   the sequence is finished, we should not insert anything after the
%   last letter: we do not want to break the line between the sequence
%   and, say, a comma.  Therefore we insert a special smart macro:
%    \begin{macrocode}
\def\SQSPL@doprocess#1{#1\SQSPL@insert}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\SQSPL@insert}
%   The macro |\SQSPL@insert| uses |\futurelet| to check whether the
%   processed letter is the last one in the sentence:
%    \begin{macrocode}
\def\SQSPL@insert{\futurelet\SQSPL@next\SQSPL@doinsert}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\SQSPL@doinsert}
%   And this is the macro that inserts |\seqinsert| and continues
%   scanning:
%    \begin{macrocode}
\def\SQSPL@doinsert{%
  \ifx \SQSPL@end \SQSPL@next \relax%
  \else \seqinsert \fi%
  \SQSPL@scan}
%    \end{macrocode}
% \end{macro}
%
%
%\subsection{The Last Words}
%\label{sec:last}
%
%
%
%    \begin{macrocode}
%</style>
%    \end{macrocode}
%\Finale
%\clearpage
%
%\PrintChanges
%\clearpage
%\PrintIndex
%
\endinput