## Wednesday, March 14, 2012

### Latex in OpenOffice/LibreOffice

Latex equations can be inserted in Impress (powerpoint of OpenOffice/LibreOffice) via OOolatex. In this article I will talk on how to install and config OOolatex in linux and windows, pitfalls and a few tips.

# Installation and config in linux

## Install openoffice

It's probably a good idea to download and install openoffice from openoffice website. The latex extension works with 3.3. After download run the following commands:
tar -zxvf OOo_3.3.0_Linux_x86_install-deb_en-US.tar.gz
cd OOO330_m20_native_packed-1_en-US.9567/DEBS/
sudo dpkg -i *.deb
cd desktop-integration
sudo dpkg -i *.deb


## Dependencies

Install the dependencies
sudo apt-get install texlive-latex-base dvipng


## Font installation

Download the fonts and copy paste the *.ttf and *.otf files in
/usr/local/share/fonts/openoffice/

directory as root and then run the command
sudo fc-cache -fv


## Config of OOolatex

After installation, reopen Impress. Click on the Config" button on the toolbar and fill in the paths. Change them according to your installation.
Latex: /usr/bin/
Ghostscript: /usr/bin/


## Bug

### Png output format is working, but not emf

In ubuntu if png output format is working, but not emf, then run impress from the command line and then try using OOolatex with emf selected. If the command line shows that it cannot find libstdc++5, then download the library file libstdc++5_x.y.z-w_i386.deb from here where x.y.z-w is the version number. Latest ubuntu repositories only provide libstdc++6, so one has to manually download and install this library.
For some reason OOolatex specifically requires the i386 version. So even if you have amd64 bit machine with amd64 ubuntu installed, you will still need the i386 version installed. After downloading the file from the above website install it with the following command:
sudo dpkg --force-architecture -i libstdc++5_x.y.z-w_i386.deb

Reopen impress and try again.

# Installation and config in Windows

## Install dependencies

Download and install miktex, ghostscript, openoffice and minsys from their respective websites. For minsys, use mingw-get-inst-xxxxxxxx.exe to install msys.

## Font installation

Download the fonts and copy paste the *.ttf and *.otf files in C:\Windows\fonts\. Don't worry if it says bad font.

## Config of OOolatex

After installation, reopen Impress. Click on the Config" button on the toolbar and fill in the paths. Change them according to your installation.
Latex: C:\Program Files (x86)\MiKTeX 2.8\miktex\bin\
Ghostscript: C:\Program Files (x86)\gs\gs9.02\bin\
MinSYS: C:\MinGW\msys\1.0\bin\


# Tips

• If one wants to re-edit the equations after the file is re-opened, then the impress file needs to saved in odp" format rather than ppt" format.
• For output format it is better to use emf format rather than png format.
• Use Expand" button for inline equations and Equation" button for equations on a line of their own.
• Example of writing multi-line equation
\begin{array}{ccc}
\mathcal{L} &=& T - V \\[0.2cm]
\mathcal{H} &=& T + V
\end{array}


## Monday, March 12, 2012

### Bengali input in Windows/Linux

This probably will be one of very few times that I will talk about configuring windows os. Mostly because some of my friends use windows and also want to type bengali.

If one uses openoffice/libreoffice along with this method of typing bengali, then it won't matter if the person is using windows or linux since the files will be compatible with each other.

## Windows

Download the Ekushey probhat" bengali layout from here. This layout is a phonetic layout and is very intuitive. Don't forget to download the Unicode Keyboard Conjunction list given in the above website. After downloading the Ekushey probhat" layout, unzip the file and double click on "Setup" and install it.
To easily switch between Bengali and English,
• For Windows XP
• Control Panel >Regional and Language Options >Languages > Text services and input languages >Details >Settings >Preferences >Language Bar. Tick mark both
• Show the Language bar on the desktop
• For Windows 7,
• Control Panel >Change keyboards or other input methods >Keyboards and Languages >Change keyboards >Language Bar >
• Language Bar >Docked in the taskbar
• Show text labels on the Language bar

## Linux (Ubuntu)

IBus (Intelligent Input Bus) helps in inputting various languages in linux. For ubuntu install the packages ibus", ibus-m17n", m17n-db" and m17n-contrib". To start up ibus for every login, System >Preferences >Startup Applications >Add
 Name IBus Daemon Command ibus-daemon -rd Comment Input Method System
To setup the input method, go to System >Preferences >IBus Preferences >Input Method >Select an input method >Bengali > Probhat >Add.

# Font installation

SutonnyBanglaOMJ", FreeSerif and Free Sans" are good fonts for writing bengali. You can download the SutonnyBanglaOMJ" font from here.
You can also download other bengali unicode fonts from the internet. Just give a google search for Bengali Unicode fonts".

## Windows

Copy the fonts to c:\WINDOWS\fonts\. Done.

## Linux

You probably have the font FreeSerif in your system in
/usr/share/fonts/truetype/freefont/FreeSerif.ttf

If you don't, then install the file via you package manager. For ubuntu the package is ttf-freefont". You will need root access. However, if the font is not installed and you don't have root access, then create the directory $HOME/.fonts/f/. Notice the ." in front of fonts". This makes the folder hidden. Now download the freefont-ttf.tar.gz font from here and copy the *.ttf files to $HOME/.fonts/f/. Open a terminal and run the command
fc-cache -fv


# Default font selection in LibreOffice/OpenOffice

In the instructions below, substitute openoffice where ever I have said libreoffice if you have openoffice instead of libreoffice. However, I found that FreeSerif font has a problem with bengali conjuctions in the ubuntu version of libreoffice/openoffice. Workaround is either to work with FreeSans font or install libreoffice/openoffice downloaded from their respective sites.
To set the default font for bengali do the following. Open libreoffice

• Tools >Options >Language Settings >Languages >Enabled for complex text layout (CTL)". Also under Default languages for documents" >CTL, select Bengali (India)". Click OK.
• Tools >Options >LibreOffice Writer >Basic Fonts (CTL) >
• Choose the fonts as follows:
 Font Size Default FreeSerif 20 Heading FreeSerif 22 List FreeSerif 20 Caption FreeSerif 20 Index FreeSerif 20
• Format >Character >Font >CTL font

 Font Typeface Size Language FreeSerif Regular 20 Bengali (India)
I have seen that sometimes, on some computers, FreeSerif font (windows/linux) won't write the conjuction alphabets correctly. I haven't been able to debug it. If that is the case stick to SutonnyBanglaOMJ" as your default font.

# Input method

## Windows

Click on the EN" icon on the right hand corner of the taskbar. Click Show the language bar". A bar appears on the top right hand. Open libreoffice-writer and click on English" to select Bengali (India)". The default keyboard shortcut to switch between input languages is Left Alt+Shift".

## Linux

Open libreoffice-writer. To toggle between ibus input and default language, the keyboard shortcut is Ctrl+Space".

## Friday, November 25, 2011

### Keyboard shortcut for open terminal here in thunar

Thunar has a right-click custom action, where one open a terminal in the same directory in which one is working. However, I personally miss the option of assigning a keyboard shortcut for the above job (as in pressing F4" in konqueror). Work regarding this has already started as said here.
However, until this is implemented directly within thunar, I have written a shell script to do the above job. In other words, keyboard shortcut for opening a terminal in the working directory of thunar is possible now.

# Requirements

The following are the requirements which the script depends upon. Install them in ubuntu via apt-get or synaptic.
sudo apt-get install xdotool xclip thunar xfce4-terminal

# Kile Configuration

Open kile and do the following configuration
Kile > Settings > Configure Kile > Tools > Build
New
Tool Name: makelatex2
Class: LaTeX
General:
Command: makelatex2
Options: -e- -w- -b- '%source'
Type: Run Outside of Kile
Class: Compile
Targe extension: pdf
State: Editor

Quick Build
General:
makelatex2

Now for any sub-documents in the multi-document project include a line
%!TeX root=master.tex

within the first 5 lines. Here master.tex is your main latex file. The makelatex2 script sees the above line and compiles the master.tex file.

# Changing the default typesetting command

Default compilation command is pdflatex. However if you want to change the compilation command, then you can do it from the document itself without changing any configuration. Just include the line
%!TeX program=latex+dvipdf

Other compilation commands supported by the makelatex2 script are
pdflatex
latex
latex+dvips
latex+dvipdf
latex+dvips+ps2pdf
xelatex

Note that
• Forward and reverse search however doesn't work with ps file, i.e. with latex+dvips.
• For multi-document the typesetting comment %!TeX program has to be specified only in the master tex file.

## Wednesday, September 28, 2011

### Synctex in Kile and Okular

In my last post I had discussed about configuring gvim and okular with synctex. In this post I will discuss configuring kile and okular with synctex.

# Configuration of Kile for pdflatex

Add the option -synctex=1 for building via pdflatex.

Kile > Settings > Configure Kile > Tools > Build
PDFLaTeX
General:
Command: pdflatex
Options: -interaction=nonstopmode -synctex=1 '%source'

One can do the same configuration for latex as opposed to pdflatex. The ForwardPDF build config should already be present. If not then do the following:
Kile > Settings > Configure Kile > Tools > Build
ForwardPDF
General:
Command: okular
Options: --unique '%absolute_target'
Run Outside of Kile
ForwardDVI
Source extension: pdf
Target extension: pdf
State: Editor

Finally configure the Quick build option.
Kile > Settings > Configure Kile > Tools > Build
Quick Build
General:
PDFLaTeX
ForwardPDF


# Configuration of Okular

Okular > Settings > Configure Okular >
General > Program Features > Uncheck
Editor > Editor: Kile

# Usage

Open or create a new tex file in kile. Press QuickBuild (Shortcut: Alt+1) to compile via pdflatex. Okular automatically opens the pdf file in the exact page where your cursor is in kile.
For forward search (kile to okular), put your cursor in any text part of your tex file and click on ForwardPDF". Okular opens the file to the exact page of your text.
For reverse search (okular to kile), Shift+click" on any part of your pdf file in okular. Kile scrolls the file in the exact location.

# Other kile configs

Couple of other kile configs which I found useful.
Kile > Settings > Configure Kile > Editor > Editing > General
# Tabs configuration
Highlight tabulators
Tab Width 4 characters

# For word wrap (static)
# To avoid a long line and also to justify text
Enable static word wrap
Show static word wrap marker (if applicable)
Word wraps at 80 characters

This post however doesn't deal with multi-document projects (Eg: thesis). In my next post I will talk about how to implement handling multi-document projects in Kile + Okular with synctex.
This file was generated via LATEX2html.

# What is synctex?

Synctex is the method of synchronization of your latex editor with the pdf/dvi output. Forward synchronization is where you jump from any line in your latex editor to the corresponding line in pdf/dvi output. Reverse synchronization is where you jump any line in your pdf/dvi output to the corresponding line in your tex editor. Synctex has been around since TeXLive 2008. Many latex editors and pdf/dvi viewer support synctex. Some of these are texworks texmaker, gedit with latex plugin. All of the above can be installed in ubuntu via synaptic. However, AFAIK the lucid version of gedit latex plugin doesn't support synctex. It's better to install the gedit plugin from it's website. GVim by default doesn't support synctex. I wrote couple of scripts, which, along with okular helps in bringing synctex support in GVim.
Even though I haven't tried implementing synctex in Emacs editor, for those of you who are interested can check this blog post out.

# Requirements

The following are the requirements:
• Vim version 7 or higher.
• Okular with synctex option compiled. Version 0.10.5 works.
• latexmk: Version 4.25 or higher
• Zenity
• (g)awk
In ubuntu install the above softwares (excepting latexmk) via synaptic or apt-get
sudo apt-get install vim-gtk okular zenity gawk

The latexmk package found in Ubuntu lucid (10.04) is an older version. One needs at least version 4.25. Download latexmk from here. Unzip it and copy the file latexmk.pl to your $PATH. mkdir -p$HOME/bin/             ## Creating $HOME/bin/ directory. chmod +x latexmk.pl ## To make the script executable. cp latexmk.pl$HOME/bin/latexmk ## Copying and changing the name
## of the script to latexmk.
Note that if you didn't have a $HOME/bin/ directory, then you have to logout and log back in. # Installation of scripts Download the scripts makelatex2, deljunk and makelatex.vim. After downloading the scripts rename them makelatex2, deljunk and tex_makelatex.vim respectively. Copy the scripts makelatex2, deljunk to $HOME/bin/. To make the scripts executable run the command
chmod +x makelatex2 deljunk
cp makelatex2 $HOME/bin/ cp deljunk$HOME/bin/

Copy the file tex_makelatex.vim to $HOME/.vim/ftplugin/ directory. Create the directory if you don't have it. Notice the dot" in-front of vim". This makes it a hidden directory. Also copy the file editexisting.vim from the runtime/macros directory of vim to your local plugin directory. This is required for reverse search. mkdir -p$HOME/.vim/ftplugin
cp tex_makelatex.vim $HOME/.vim/ftplugin mkdir -p$HOME/.vim/plugin
cp /usr/share/vim/addons/plugin/editexisting.vim $HOME/.vim/plugin/  Create a hidden file $HOME/.vimrc" if you already don't have one and add the following lines.
" For filetype plugins
filetype plugin on

Note that the dot" infront of vimrc. The dot makes the file hidden.

# Okular config

Okular > Settings > Configure Okular >
General > Program Features > Uncheck "Reload document on change"
Editor >
Editor: Custom Text Editor
Command: gvim +%l %f


# Usage

Open or create a new tex file in gvim. Press Esc" and then Alt+1" to compile via pdflatex. Okular automatically opens the pdf file in the exact page where your cursor is in gvim.
For forward search (gvim to okular), put your cursor in any text part of your tex file and press Esc" and then Shift+f". Okular opens the file to the exact page of your text.
For reverse search (okular to gvim), Shift+click" on any part of your pdf file in okular. Gvim scrolls the file in the exact location.

# Multi-document project

For a multi-document project, each sub-document files should have the following magic comment" in the first 5 lines of the tex file
%!TeX root = master.tex

where master.tex" is the main tex file on which compilation ought to be done.

# Selecting type-setting command

Compilation by default is via pdflatex. However to compile via some other typesetting command (eg. latex+dvipdf), specify the typesetting command to be used via the following magic comment in the first 5 lines of the input tex file
%!TeX program = latex+dvipdf

This is compatible with texworks. Typesetting commands can be
pdflatex
latex
latex+dvips
latex+dvipdf
latex+dvips+ps2pdf
xelatex

Custom typesetting commands are also supported. Note that
• Forward and reverse search doesn't work with ps file, i.e. with latex+dvips.
• For multi-document project the typesetting comment %!TeX program" has to be specified only in the master tex file.

# Optional (g)vim configurations

For other useful (g)vim configurations you can check out my last two posts on the topic here and here.

This file was generated via LATEX2html.

## Monday, September 19, 2011

### Vim configurations: Part 2

Continuing from my last post on vim configurations, in this post I will discuss some vim plugins that I have written, along with couple of third-party plugins which I find very useful. If you already haven't installed the full vim (with gui support), then do it. For ubuntu the package is called vim-gtk. Also if you don't have the following directory structure, create them before we start.
mkdir -p ~/.vim/plugin
mkdir -p ~/.vim/ftplugin


# Scripts I have written

There are a couple of vim scripts that I have written over the years. I will discuss two of them now.

## CommentLines

This script was written to (un)comment multiple lines simultaneously. It was inspired by vim tip #271 from the vim tips website, now appropiately called the vim tips wiki. You can download the plugin from here.

# Other useful scripts

There are couple of other scripts, written by other vim users, which I not only find very useful, but also use them on a daily basis.

## editexisting

Ever tried to re-open the same file twice in gvim and seen this message?

What gvim should should have done is jump to the already opened file. With gvim version 7 one can do just that with the plugin editexisting.vim". Copy the script editexisting.vim" to your local plugin directory.
cp /usr/share/vim/addons/plugin/editexisting.vim "$HOME"/.vim/plugin/  Now if you try to re-open a file which is already open in gvim, that particular gvim window will come into focus without showing you the above message. This however only works with gvim, but not console based vim. ## snipMate Often while programming or say writing in latex we reuse the same commands. If we could write these commands via a few keyboard shortcuts then, we could type a bit faster. This is possible via the plugin snipMate. Download the snipMate plugin and follow the instructions given in the website to install it. This plugin has support for lot of programming languages. Now say we want to add support for latex. Open the file $HOME/.vim/snippets/tex.snippets. This file already has a couple of snippets, but adding custom code snippets is quite easy. An example will make this clear. Let' say we type the following code in the tex.snippets file.
# Begin equation
snippet beq
%
$${1}$$
%

Now open any tex file and type beq" and press tab". beq" will get expanded to
%

%

with the cursor blinking in-between and . This is but a small example of what you can do with snipMate. Use the command
:help snipmate

Follow the install instructions in the above website. Open any tex file in gvim and scroll to any paragraph. Press Esc" and then ctrl+j". The paragraph becomes nicely formatted.