Showing posts with label latex. Show all posts
Showing posts with label latex. Show all posts

Thursday, May 03, 2012

Vim Latex Suite Reference Card

Found a great reference card at http://michaelgoerz.net/refcards/vimlatexqrc.pdf. I made a picture out of it so that you can direct read it.

vimlatex_ref_card

Sunday, April 29, 2012

Wrap acronyms with \ac in Vim

:s/\(\W\)\(\u\{2,10\}\)\(\W\)/\1\\ac{\2}\3/g
:s/\(\W\)\(\u\{2,10\}\)$/\1\\ac{\2}/g
:s/^\(\u\{2,10\}\)\(\W\)/\\ac{\1}\2/g
:s/^\(\u\{2,10\}\)$/\\ac{\1}/g

Sunday, October 09, 2011

pdf to eps conversion

Currently, I need to convert pdf files to eps so that they can be included in latex files.

  1. Use Acrobat Pro open the pdf file. 
    Click File -> export -> PostScript -> Encapsulated PostScript or use "Save As" and change "Save As Type"
    However, the bounding box is NOT correctly calculated.
    You can use gsview to correct it.  Use gsview open the eps file, click "File -> PS to EPS", select "Automatically calculate Bounding Box" and save the output file.

  2. Use ghostscript.  Execute following command:
    gswin32 -sDEVICE=epswrite -sOutputFile=<filename>.eps <filename>.pdf
    This works well and bounding box is correctly calculated.

  3. Use Xpdf (http://www.foolabs.com/xpdf/download.html)
    pdftops -eps <filename>.pdf <filename>.eps
    However, the bounding box is NOT correctly calculated.

Brief Latex notes for equations

In-line: $…$

Single line, without equation number: \[ … \] or \begin{equation*} … \end{equation*}

Single line, with equation number: \begin{equation} … \end{equation}

Multi-line, without equation number: \begin{align*} ... \end{align*}

Multi-line, with equation number: \begin{align} ... \end{align}

"a double backslash (\\) is used to separate the lines, and an ampersand symbol (&) is used to indicate the place at which the formulas should be aligned."

For align, \label must be put in front of each equation. For equation, it does not matter you put it in front or in the end.

Saturday, October 08, 2011

Make vim-latex to generate output in a specified directory

Recently I started to use latex to write papers.  I want to edit latex in my favorite editor - vim. I found the project vim-latex: http://vim-latex.sourceforge.net/.  It is powerful and convenient to use. 

However, one feature I want is to generate output files (.div, .ps, .log, etc) into a separate directory rather than the same directory as tex files.  It turns out that vim-latex does not support it natively.  So I hacked into the source code to make it work on Windows.

  1. Edit file ~/vimfiles/ftplugin/tex.vim

    Add following config:

      set iskeyword+=: 
      let g:Tex_Outdir='out' 
      let g:Tex_ViewRule_pdf='"Foxit Reader.exe" ' 
      let g:Tex_CompileRule_dvi='mkdir '.g:Tex_Outdir.' & latex -output-directory='.g:Tex_Outdir.' -src-specials --interaction=nonstopmode $*' 
      let g:Tex_CompileRule_pdf=g:Tex_CompileRule_dvi.' & cd '.g:Tex_Outdir.' & dvipdfm $*.dvi'

    Basically above config specifies

    1. output directory of latex compilation
    2. How to view PDF files (if you don't give full path, the command needs to be in env variable PATH)
    3. How to compile dvi: create the output directory and put output there
    4. How to compile pdf: first compile tex to dvi, and then call dvipdfm to generate pdf
  2. Change ~/vimfiles/ftplugin/latex-suite/compiler.vim

    Change line 252 to (this line adds the full path of output directory):
      let execString = 'start '.s:viewer.' "'.expand('%:p:h').'/'.g:Tex_Outdir.'/$*.'.s:target.'"'

    Change line 405 to (this line adds the full path of output directory):
    let execString = 'silent! !'.viewer.' "'.expand('%:p:h').'/'.g:Tex_Outdir.'/'.mainfnameRoot.'.'.s:target.'" '.line('.').' "'.expand('%').'"'

    Note: the text in blue is what I added (diff against the original code)
Use command 'TTarget' to switch amont dvi, ps, pdf, etc.