Thursday, October 27, 2011

Add "Edit with Vim" item to context-menu in Windows for Vim

This post shows how to add "Edit with Vim" and "Tab Edit with Vim" items to context menu (pop out when you right click a file) in Windows.

Run regedit.exe, go to HKEY_LOCAL_MACHINE/SOFTWARE/Classes/*/shell/

  1. Create new key "Tab Edit with &Vim" (Right click parent entry -> New -> Key)
  2. Create new key "Edit with Vim"
  3. Create new key "command" under "Tab Edit with &Vim"
  4. Edit the entry with name "(Default)", change its data to
    <vim_dir>\gvim.exe" -p --remote-tab-silent "%1" "%*"
  5. Create new key "command" under "Edit with Vim".
  6. Edit the entry with name "(Default)", change its data to
    <vim_dir>\gvim.exe "%1"

It seems that latest versions of vim automatically create the registry entry:

  • HKEY_LOCAL_MACHINE\SOFTWARE\Vim\Gvim and the data of entry path points to the vim executable.
  • HKEY_CLASSES_ROOT\*\shellex\ContextmenuHandlers\gvim. Data of the entry "(Default)" is the CLSID (51EEE242-AD87-11d3-9C1E-0090278BBD99).
    You can delete this entry because we have already added menu item "Edit with Vim".
  • HKEY_CLASSES_ROOT\Applications\gvim.exe\shell\edit\command. Data of the entry "(Default)" is "<vim_dir>\gvim.exe" "%1"
  • HKEY_CLASSES_ROOT\CLSID\{51EEE242-AD87-11d3-9C1E-0090278BBD99}
    It has a key named InProcServer32. The data of "(Default)" is <vim_dir>\gvimext.dll
  • Some other keys

Monday, October 17, 2011

Logging in Hadoop

Hadoop uses log4j via Apache common logging.  The config file is conf/log4j.properties.

Some important variables are set in the command line.  Following is a snippet cut from the whole command line used to launch HDFS name node.

-Dhadoop.root.logger=INFO,DRFA
-Dhadoop.log.dir=/N/u/hdfs/programs/hadoop-0.21.0/bin/../logs
-Dhadoop.log.file=hadoop-hdfs-namenode-b009.log
-Dhadoop.home.dir=/N/u/hdfs/programs/hadoop-0.21.0/bin/..
-Dhadoop.id.str=hdfs

You can see that log dir, log file, log level, logger are set.  DRFA is defined in conf/log4j.properties.

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.