Skip to content

Instantly share code, notes, and snippets.

@dbaynard
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbaynard/8807189 to your computer and use it in GitHub Desktop.
Save dbaynard/8807189 to your computer and use it in GitHub Desktop.
Convert an RTF from ApE to LaTeX using vim

RTF (ApE) -> LaTeX

Eventually, this will become a script. Until then…

Mostly automated

First, find all strings of bases (except the last)

/\v([0-9]*1) .{-} ([0-9]*0)/e

Then go to start

gg

and record the macro

na<CR><esc>

before running it to the end of the file.

Delete everything after the last number, then strip everything before the numbers with

:%s/\v^.{-}([0-9]*1 .{-} [0-9]+)/\1/g

and the last line, if necerssary

Gdd

At the start of the file

gg

delete until after \colortbl;

d/colortbl;/e

Find all references to the colour table,

/\v\\chshdng.{-}\\chcbpat([0-9]+)\\cb\1

Return to the start

gg^

and run the macro

df;nsWr gg^

before deleting the rest of that first line

dd

Get rid of all line numbers, sticking a | at the end of each line

:%s/\v^[0-9]+ *(.{-}) *[0-9]+$/\1|/

Join all lines (without spaces)

ggVGgJ

and then split lines by colour groups

:%s/\v\}\{/\r/g

which should also delete all braces.

Manual

Manually, highlight the first colour code in visual mode, and search with *.

Then delete all but the first and last in each section

:%s/<C-R>///gc

Change the first item in each list (now the odd items) to a latex colour code, e.g.

ggncW'{pink}

Repeat for each colour code

Then, replace the remaining colour codes with white (no highlight)

:%s/\v^\\red[0-9]+\\green[0-9]+\\blue[0-9]+ (.{-})$/\1 '{white}/g

Automatic again

Strip all whitespace at the starts of lines

:%s/\v^ +//g

then rejoin all lines

ggVGgJ

ensure spacing around colour codes

:%s/\v *(\'\{.{-}\}) */ \1 /g

before wrapping the whole thing in \DNA! and !

I|<esc>yss!<esc>I\DNA 

Finally, split at |

:%s/\v\|/\r/g

Standalone file

Paste

\documentclass[a4paper,11pt,oneside,fleqn,final]{article}

\usepackage[usenames,svgnames]{xcolor}

\usepackage{geometry}

\usepackage{dnaseq}
\renewcommand{\DNAblock}{10}% 10 bases per block
\renewcommand{\DNAreserve}{0000}% Four digit numbering

\begin{document}

and

\end{document

afterwards.

Bits taken out

Delete all superfluous codes

:%s/\v\{\\red[0-9]+\\green[0-9]+\\blue[0-9]+\|\}//g

And braces, too

:%s/\v[{}]//g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment