summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/dnaseq/dnaseq.sty
blob: 70ad2e99a482436807ad78071b45201f43814dc0 (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
%%
%% This is file `dnaseq.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% dnaseq.dtx  (with options: `dnaseq')
%% 
%% IMPORTANT NOTICE:
%% 
%% For the copyright see the source file.
%% 
%% Any modified versions of this file must be renamed
%% with new filenames distinct from dnaseq.sty.
%% 
%% For distribution of the original source see the terms
%% for copying and modification in the file dnaseq.dtx.
%% 
%% This generated file may be distributed as long as the
%% original source files, as listed above, are part of the
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)
%% File: dnaseq.dtx Copyright (C) 2002 Bjoern Pedersen
%% mailto:Bjoern.Pedersen@ch.tum.de
%% This file may be distributed and used freely under
%% the Latex Project Public License
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{dnaseq}[2002/05/20 v0.01 dna sequence setter]
\RequirePackage{color}

\def\DNAblock{10}
\def\DNAreserve{0000}% für 4-stellige Zahlen
%%
%% registers /counters
%%
\newlength\bl@cklen
\newlength\l@neln
\newlength\t@mpln
\newlength\ch@rwd
\newcount{\blocks}
%%
%% calculate blocks per line
%%
\def\DNAc@lcline{%
 \settowidth{\ch@rwd}{A}
 \setlength{\bl@cklen}{\DNAblock\ch@rwd}%
 \settowidth{\t@mpln}{\DNAreserve}
 \setlength{\l@neln}{\textwidth}
 \addtolength{\l@neln}{-\t@mpln}
 \loop%
    \setlength{\t@mpln}{\blocks\bl@cklen}
    \addtolength{\t@mpln}{\blocks\ch@rwd}
    \ifdim\l@neln>\t@mpln\advance\blocks by 1
 \repeat
 \advance\blocks by -1
 \ifnum\blocks<1\errmessage{line too short for 1 block^^J}%
 \else\expandafter\message\expandafter{Blocks per line: \the\blocks^^J}\fi%
}

%% main user macro
\def\DNA#1{%
   \def\@DNA@end{#1}\bgroup\ttfamily\DNAc@lcline
   \settoheight\dimen@{I}\advance\dimen@ by 1pt
   \edef\htst{\the\dimen@}%
   \def\struty{\rule[-.5pt]{\z@}{\htst}}%
   %% dnabase per line counter
   \count@=0
   %% block counter
   \@tempcnta=0
   %% total dnabase counter
   \@tempcntb=0
   \fboxrule=0pt \fboxsep=0pt
   \noindent\phantom{\DNAreserve}\llap 1\
   \@DNA
}

\def\@DNA@color{'}
\def\@DNA@thecolor{white}
\def\@DNA@setcolor#1{\def\@DNA@thecolor{#1}\@DNA}
%% do the blocking/line breaking
\def\@DNA#1{%
%% insert a space after \DNAblock bases
   \ifnum\count@=\DNAblock\count@=0\ %
   \advance\@tempcnta by 1\fi
   \def\@DNA@cmp{#1}%
%% check for end of sequence or color shift
   \ifx\@DNA@cmp\@DNA@end
     \let\next\egroup
   \else
     \ifx\@DNA@cmp\@DNA@color
       \let\next\@DNA@setcolor
     \else
       \advance\count@ by 1
       \advance\@tempcntb by 1
%% line break after calculated number of blocks
       \ifnum\@tempcnta=\blocks \\
         \hskip\z@\phantom{\DNAreserve}\llap {\the\@tempcntb}\ %
         \@tempcnta=0
       \fi
       \colorbox{\@DNA@thecolor}{\struty#1}%
       \penalty0\let\next\@DNA
     \fi
   \fi
   \next
}
\endinput
%%
%% End of file `dnaseq.sty'.