Generaldnaseq | Change a predefined Value for a Counter

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
flyingbike
Posts: 3
Joined: Thu Feb 16, 2012 6:31 pm

dnaseq | Change a predefined Value for a Counter

Post by flyingbike »

Hello,

I am trying to use the dnaseq package. Basically, it takes whatever you put between \DNA!…!, organizes it in blocks of customizable length, and displays the text with a numbering on the left, starting from 1.

This package is useful for displaying easy-to-read DNA sequences, but for any reason, I would like it to start numbering from a negative number (actually my starting reference is in the middle of my sequence).

So I have to redefine the starting number to something negative. I'm not new to LaTeX but I never tried to customize packages, this is why I request some help to:
  • localize in code the variable to change (I think it's \@tempcntb=0)
  • write a command to redefine this variable from my preamble (something like \def, not used to its syntax)
This package is relatively simple so I hope somebody will help me out.

Thank you anyway !

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

dnaseq | Change a predefined Value for a Counter

Post by cgnieder »

Hi,

you're right, it is \@tempcntb. The following code works. It patches the \DNA command using etoolbox's facilities and defines a new command \DNAseqstart with which the starting value for the following sequence can be set and \defaultDNAseqstart which sets the default starting number:

Code: Select all

\documentclass{article}
\usepackage{dnaseq}
\usepackage{etoolbox}

\makeatletter
% new counts:
\newcount\@DNA@seq@start
\newcount\@DNA@seq@start@default
\@DNA@seq@start@default=0
\@DNA@seq@start=\@DNA@seq@start@default

% patch \DNA:
\patchcmd{\DNA}{\@tempcntb=0}{%
  \@tempcntb=\numexpr\@DNA@seq@start-1\relax}
  {}{\ERROR}
\patchcmd{\DNA}{\llap 1}{%
  \llap{\the\@DNA@seq@start}%
  \@DNA@seq@start=\@DNA@seq@start@default}
  {}{\ERROR}

% new user commands:
\newcommand*\DNAseqstart[1]{\@DNA@seq@start=#1\relax}
\newcommand*\defaultDNAseqstart[1]{%
  \@DNA@seq@start@default=#1\relax
  \@DNA@seq@start=#1\relax}
\makeatother

\begin{document}

\noindent\begin{minipage}{100pt}
\noindent\rule{\textwidth}{.5pt}
\DNA! ACGT'{red}A CGT'{white}TGCA'{green}x s df'{white}FJKD SLAF
DSAIOFDSA ACGT'{red}ACGT'{white}TGCA'{green}x sdf '{white}FJKDSLAF
DSAIOFDSA AC GT'{red}ACGT'{white}TG CA'{green}xsdf'{white}FJKD SLAF
DSAIOFDSA ACGT'{red}ACGT'{white}T GCA'{green} xs df'{white}FJKDSLA
FDSAIOFDSA ACGT'{red}AC GT'{white}TGCA'{green}xsdf'{white}FJK DSLA
FDSAIOFDSA !
\end{minipage}

\noindent\begin{minipage}{200pt}
\noindent\rule{\textwidth}{.5pt}\DNAseqstart{-7}
\DNA! ACGT'{red}A CGT'{white}TGCA'{green}x s df'{white}FJKD SLAF
DSAIOFDSA ACGT'{red}ACGT'{white}TGCA'{green}x sdf '{white}FJKDSLAF
DSAIOFDSA AC GT'{red}ACGT'{white}TG CA'{green}xsdf'{white}FJKD SLAF
DSAIOFDSA ACGT'{red}ACGT'{white}T GCA'{green} xs df'{white}FJKDSLA
FDSAIOFDSA ACGT'{red}AC GT'{white}TGCA'{green}xsdf'{white}FJK DSLA
FDSAIOFDSA !
\end{minipage}

\defaultDNAseqstart{3}

\noindent\begin{minipage}{\textwidth}
\noindent\rule{\textwidth}{.5pt}
\DNA! ACGT'{red}A CGT'{white}TGCA'{green}x s df'{white}FJKD SLAF
DSAIOFDSA ACGT'{red}ACGT'{white}TGCA'{green}x sdf '{white}FJKDSLAF
DSAIOFDSA AC GT'{red}ACGT'{white}TG CA'{green}xsdf'{white}FJKD SLAF
DSAIOFDSA ACGT'{red}ACGT'{white}T GCA'{green} xs df'{white}FJKDSLA
FDSAIOFDSA ACGT'{red}AC GT'{white}TGCA'{green}xsdf'{white}FJK DSLA
FDSAIOFDSA !
\end{minipage}

\end{document}
Regards
site moderator & package author
Post Reply