dna-demo代码实现如下:

%作者:李清
%链接:https://www.zhihu.com/question/51062435/answer/124466547
%来源:知乎
%著作权归作者所有,转载请联系作者获得授权。

\documentclass{article} 
\usepackage{xparse}
\usepackage{marvosym}
\usepackage{environ}

\ExplSyntaxOn
\makeatletter

%% 可选参数 #1 指定行宽
\NewEnviron { dnaseq } [1] [ \linewidth ]
  { \exp_args:Nno \@@_dna_seq:nn {#1} { \BODY } }

\cs_new_protected_nopar:Npn \@@_dna_seq:nn #1#2
  {
    \vbox:n
      {
        \scriptsize \ttfamily
        \offinterlineskip
        \skip_set:Nn \lineskip { 2pt }
        \hbox_set:Nn \l_tmpa_box { T }
        \dim_set:Nn \l_tmpa_dim { \box_wd:N \l_tmpa_box }
        \int_set:Nn \l_@@_line_int
          { \dim_ratio:nn {#1} { \l_tmpa_dim } - 5 }
        \dim_set:Nn \linewidth { \l_@@_line_int \l_tmpa_dim }
        \dim_set:Nn \l_tmpa_dim
          { ( \box_ht:N \l_tmpa_box + \lineskip ) / 2 }
        \hbox_set:Nn \l_@@_lmark_box
          {
            \smash
              {
                \box_move_down:nn { \l_tmpa_dim }
                  { \hbox_overlap_left:n { \LeftTorque \, } }
              }
          }
        \hbox_set:Nn \l_@@_rmark_box
          {
            \smash
              {
                \box_move_down:nn { \l_tmpa_dim }
                  { \hbox_overlap_right:n { \, \RightTorque } }
              }
          }
        \@@_dna_seq:n {#2}
      }
  }
\int_new:N \l_@@_line_int
\box_new:N \l_@@_lmark_box
\box_new:N \l_@@_rmark_box
\cs_new_protected_nopar:Npn \@@_dna_seq:n #1
  {
    \int_zero:N \l_tmpa_int
    \@@_normal:w #1 \q_recursion_tail \q_recursion_stop
  }
\cs_new_protected_nopar:Npn \@@_normal:w
  {
    \tex_hbox:D \c_group_begin_token
    \@@_normal_line:w
  }
\cs_new_protected_nopar:Npn \@@_normal_line:w #1
  {
    \quark_if_recursion_tail_stop_do:Nn #1
      { \c_group_end_token }
    #1
    \int_incr:N \l_tmpa_int
    \int_compare:nNnTF \l_tmpa_int < \l_@@_line_int
      { \@@_normal_line:w }
      { \@@_normal_line_stop:w }
  }
\cs_new_protected_nopar:Npn \@@_normal_line_stop:w #1
  {
    \quark_if_recursion_tail_stop_do:Nn #1
      { \c_group_end_token }
    \box_use:N \l_@@_rmark_box
    \c_group_end_token
    \@@_reverse:w #1
  }
\cs_new_protected_nopar:Npn \@@_reverse:w
  {
    \tex_hbox:D \c_group_begin_token
    \@@_reverse_line:w \q_mark
  }
\cs_new_protected_nopar:Npn \@@_reverse_line:w #1 \q_mark #2
  {
    \quark_if_recursion_tail_stop_do:Nn #2
      { \@@_reverse_stop:n {#1} }
    \int_incr:N \l_tmpa_int
    \int_compare:nNnTF \l_tmpa_int < \l_@@_line_int
      { \@@_reverse_line:w }
      { \@@_reverse_line_stop:w }
    #2#1 \q_mark
  }
\cs_new_protected_nopar:Npn \@@_reverse_line_stop:w #1 \q_mark #2
  {
    \quark_if_recursion_tail_stop_do:Nn #2
      { \@@_reverse_stop:n {#1} }
    \box_use:N \l_@@_lmark_box
    #1
    \c_group_end_token
    \@@_normal:w #2
  }
\cs_new_protected_nopar:Npn \@@_reverse_stop:n #1
  {
    \hbox_to_wd:nn { \linewidth } { \tex_hfil:D #1 }
    \c_group_end_token
  }

\makeatother
\ExplSyntaxOff

\begin{document}

\begin{dnaseq}
CCGTCAGGATTGACACCCTCCCAATTGTATGTTTTCATGCCTCCAAATCTTGGAGGCTTTTTTATGGTTCGT
TCTTATTACCCTTCTGAATGTCACGCTGATTATTTTGACTTTGAGCGTATCGAGGCTCTTAAACCTGCTATT
GAGGCTTGTGGCATTTCTACTCTTTCTCAATCCCCAATGCTTGGCTTCCATAAGCAGATGGATAACCGCATC
AAGCTCTTGGAAGAGATTCTGTCTTTTCGTATGCAGCCCGTTGAGTTCGATAATGGTGATATGTATGTTGAC
GGCCATAAGGCTGCTTCTGACGTTCGTGATGAGTTTGTATCTGTTACTGAGAAGTTAATGGATGAATTGGCA
CAATGCTACAATGTGCTCCCCCAACTTGATATTAATAACACTATAGACCACCGCCCCGAAGGGGACGAAAAA
TGGTTTTTAGAGAACGAGAAGACGGTTACGCAGTTTTGCCGCAAGCTGGCTGCTGAACGCCCTCTTAAGGAT
ATTCGCGATGAGTATAATAACCCCAAAAAGAAAGGTATTAAGGATGAGTGTTCAAGATTGCTGGAGGCCTCC
ACTAAGATATCGCGTAGAGGCTTTGCTATTCAGCGTTTGATGAATGCAATGCGACAGGCTCATGCTGATGGT
TGGTTTATCGTTTTTGACACTCTCACGTTGGCTGACGACCGATTAGAGGCGTTTTATGATAATCCCAATGCT
TTGCGTGACTATTTTCGTGATATTGGTCGTATGGTTCTTGCTGCCGAGGGTCGCAAGGCTAATGATTCACAC
GCCGACTCCTATCAGTATTTTTGTGTGCCTGAGTATGGTACAGCTAATGGCCGTCTTCATTTCCATGCGGTG
CACTTTATGCGGACACTTCCTACAGGTAGCGTTGACCCTAATTTTGGTCGTCGGATACGCAATCGCCGCCAG
TTAAATAGCTTGCAAAATACGTGGCCTTATGGTTACAGTATGCCCATCCCAGTTCGCTACACGCAGGACGCT
TTTTCACCTTCTGGTTGGTTGTGGCCTGTTGATGCTAAAGGTGAGCCGCTTAAAGCTACCAGTTATATGGCT
GTTGGTTTCTATGTGCCTAAATACGTTAACAAAAAGTCAGATATGGACCTTGCTGCTAAAGGTCTAGGAGCT
AAAGAATGGAACAACTCACTAAAAACCAAGCTGTCGCTACTTCCCAAGAAGCTGTTCAGAATCAGAATGAGC
CGCAACTTCGGGATGAAAATGCTCACAATGACAAATCTGTCCACGGAGTGCTTAATCCAACTTACCAAGCTG
GGTTACGACGCGACGCCGTTCAACCAGATATTGAAGCAGAACGCAAAAAGAGAGATGAGATTGAGGCTGGGA
AAAGTTACTGTAGCCGACGTTTTGGCGGCGCAACCTGTGACGACAAATCTGCTCAAATTTATGCGCGCTTCG
ATAAAAATGATTGGCGTATCCAACCTGCAGAGTTTTATCGCTTCCATGACGCAGAAGTTAACACTTTCGGAT
ATTTCTGATGAGTCGAAAAATTATCTTGATAAAGCAGGAATTACTACTGCTTGTTTACGAATTAAATCGAAG
TGGACTGCTGGCGGAAAATGAGAAAATTCGACCTATCCTTGCGCAGCTCGAGAAGCTCTTACTTTGCGACCT
TTCGCCATCAACTAACGATTCTGTCAAAAACTGACGCGTTGGATGAGGAGAAGTGGCTTAATATGCTTGGCA
CGTTCGTCAAGGACTGGTTTAGATATGAGTCACATTTTGTTCATGGTAGAGATTCTCTTGTTGACATTTTAA
AAGAGCGTGGATTACTATCTGAGTCCGATGCTGTTCAACCACTAATAGGTAAGAAATCATGAGTCAAGTTAC
CGAACAATCCGTACGTTTCCAGACCGCTTTGGCCTCTATTAAGCTCATTCAGGGTTCTGCCGTTTTGGATTT
AACCGAAGATGATTTCGATTTTCTGACGAGTAACAAAGTTTGGATTGCTACTGACCGCTCTCGTGCTCGTCG
CTGCGTTGAGGCTTGCGTTTATGGTACGCTGGACTTTGTAGGATACCCTCGCTTTCCTGCTCCTGTTGAGTT
TATTGCTGCCGTCATTGCTTATTATGTTCATCCCGTCAACATTCAAACGGCCTGTCTCATCATGGAAGGCGC
TGAATTTACGGAAAACATTATTAATGGCGTCGAGCGTCCGGTTAAAGCCGCTGAATTGTTCGCGTTTACCTT
GCGTGTACGCGCAGGAAACACTGACGTTCTTACTGACGCAGAAGAAAACGTGCGTCAAAAATTACGTGCGGA
AGGAGTGATGTAATGTCTAAAGGTAAAAAACGTTCTGGCGCTCGCCCTGGTCGTCCGCAGCCGTTGCGAGGT
ACTAAAGGCAAGCGTAAAGGCGCTCGTCTTTGGTATGTAGGTGGTCAACAATTTTAATTGCAGGGGCTTCGG
CCCCTTACTTGAGGATAAATTATGTCTAATATTCAAACTGGCGCCGAGCGTATGCCGCATGACCTTTCCCAT
CTTGGCTTCCTTGCTGGTCAGATTGGTCGTCTTATTACCATTTCAACTACTCCGGTTATCGCTGGCGACTCC
TTCGAGATGGACGCCGTTGGCGCTCTCCGTCTTTCTCCATTGCGTCGTGGCCTTGCTATTGACTCTACTGTA
GACATTTTTACTTTTTATGTCCCTCATCGTCACGTTTATGGTGAACAGTGGATTAAGTTCATGAAGGATGGT
GTTAATGCCACTCCTCTCCCGACTGTTAACACTACTGGTTATATTGACCATGCCGCTTTTCTTGGCACGATT
AACCCTGATACCAATAAAATCCCTAAGCATTTGTTTCAGGGTTATTTGAATATCTATAACAACTATTTTAAA
GCGCCGTGGATGCCTGACCGTACCGAGGCTAACCCTAATGAGCTTAATCAAGATGATGCTCGTTATGGTTTC
CGTTGCTGCCATCTCAAAAACATTTGGACTGCTCCGCTTCCTCCTGAGACTGAGCTTTCTCGCCAAATGACG
ACTTCTACCACATCTATTGACATTATGGGTCTGCAAGCTGCTTATGCTAATTTGCATACTGACCAAGAACGT
GATTACTTCATGCAGCGTTACCATGATGTTATTTCTTCATTTGGAGGTAAAACCTCATATGACGCTGACAAC
CGTCCTTTACTTGTCATGCGCTCTAATCTCTGGGCATCTGGCTATGATGTTGATGGAACTGACCAAACGTCG
TTAGGCCAGTTTTCTGGTCGTGTTCAACAGACCTATAAACATTCTGTGCCGCGTTTCTTTGTTCCTGAGCAT
GGCACTATGTTTACTCTTGCGCTTGTTCGTTTTCCGCCTACTGCGACTAAAGAGATTCAGTACCTTAACGCT
AAAGGTGCTTTGACTTATACCGATATTGCTGGCGACCCTGTTTTGTATGGCAACTTGCCGCCGCGTGAAATT
TCTATGAAGGATGTTTTCCGTTCTGGTGATTCGTCTAAGAAGTTTAAGATTGCTGAGGGTCAGTGGTATCGT
TATGCGCCTTCGTATGTTTCTCCTGCTTATCACCTTCTTGAAGGCTTCCCATTCATTCAGGAACCGCCTTCT
GGTGATTTGCAAGAACGCGTACTTATTCGCAACCATGATTATGACCAGTGTTTCAGTCGTTCAGTTGTTGCA
GTGGATAGTCTTACCTCATGTGACGTTTATCGCAATCTGCCGACCACTCGCGATTCAATCATGACTTCGTGA
TAAAAGATTGAGTGTGAGGTTATAACCGAAGCGGTAAAAATTTTAATTTTTGCCGCTGAGGGGTTGACCAAG
CGAAGCGCGGTAGGTTTTCTGCTTAGGAGTTTAATCATGTTTCAGACTTTTATTTCTCGCCACAATTCAAAC
TTTTTTTCTGATAAGCTGGTTCTCACTTCTGTTACTCCAGCTTCTTCGGCACCTGTTTTACAGACACCTAAA
GCTACATCGTCAACGTTATATTTTGATAGTTTGACGGTTAATGCTGGTAATGGTGGTTTTCTTCATTGCATT
CAGATGGATACATCTGTCAACGCCGCTAATCAGGTTGTTTCAGTTGGTGCTGATATTGCTTTTGATGCCGAC
CCTAAATTTTTTGCCTGTTTGGTTCGCTTTGAGTCTTCTTCGGTTCCGACTACCCTCCCGACTGCCTATGAT
GTTTATCCTTTGGATGGTCGCCATGATGGTGGTTATTATACCGTCAAGGACTGTGTGACTATTGACGTCCTT
CCCCGTACGCCCGGCAATAACGTCTACGTTGGTTTCATGGTTTGGTCTAACTTTACCGCTACTAAATGCCGC
GGATTGGTTTCGCTGAATCAGGTTATTAAAGAGATTATTTGTCTCCAGCCACTTAAGTGAGGTGATTTATGT
TTGGTGCTATTGCTGGCGGTATTGCTTCTGCTCTTGCTGGTGGCGCCATGTCTAAATTGTTTGGAGGCGGTC
AAAAAGCCGCCTCCGGTGGCATTCAAGGTGATGTGCTTGCTACCGATAACAATACTGTAGGCATGGGTGATG
CTGGTATTAAATCTGCCATTCAAGGCTCTAATGTTCCTAACCCTGATGAGGCCGCCCCTAGTTTTGTTTCTG
GTGCTATGGCTAAAGCTGGTAAAGGACTTCTTGAAGGTACGTTGCAGGCTGGCACTTCTGCCGTTTCTGATA
AGTTGCTTGATTTGGTTGGACTTGGTGGCAAGTCTGCCGCTGATAAAGGAAAGGATACTCGTGATTATCTTG
CTGCTGCATTTCCTGAGCTTAATGCTTGGGAGCGTGCTGGTGCTGATGCTTCCTCTGCTGGTATGGTTGACG
CCGGATTTGAGAATCAAAAAGAGCTTACTAAAATGCAACTGGACAATCAGAAAGAGATTGCCGAGATGCAAA
ATGAGACTCAAAAAGAGATTGCTGCCATTCAGTCGGCGACTTCACGCCAGAATACGAAAGACCAGGTATATG
CACAAAATGAGATGCTTGCTTATCAACAGAAGGAGTCTACTGCTCGCGTTGCGTCTATTATGGAAAACACCA
ATCTTTCCAAGCAACAGCAGGTTTCCGAGATTATGCGCCAAATGCTTACTCAAGCTCAAACGGCTGGTCAGT
ATTTTACCAATGACCAAATCAAAGAAATGACTCGCAAGGTTAGTGCTGAGGTTGACTTAGTTCATCAGCAAA
CGCAGAATCAGCGGTATGGCTCTTCTCATATTGGCGCTACTGCAAAGGATATTTCTAATGTCGTCACTGATG
CTGCTTCTGGTGTGGTTGATATTTTTCATGGTATTGATAAAGCTGTTGCCGATACTTGGAACAATTTCTGGA
AAGACGGTAAAGCTGATGGTATTGGCTCTAATTTGTCTAGGAAATAA
\end{dnaseq}

\end{document}

选自:https://www.zhihu.com/question/51062435

点赞(0)

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部