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

Extension installation

Download the linux version of the extension from the download section of the OOolatex website. To install, open the extension via Openoffice.


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.


Extension installation

Download the windows version of the extension from the download section of the OOolatex website. To install open the extension via Openoffice.


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
      • Show additional Language bar icons in the taskbar
  • 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 additional Language bar icons 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

Installation of script

Download the script from here and rename it ``thunar-terminal.sh". Installation of script is as in installation of most shell script. Make the script executable and move it to your $PATH.
chmod +x thunar-terminal.sh
mkdir -p ~/bin/
mv thunar-terminal.sh ~/bin/

Window manager configuration

This configuration sets ``F4" as the global shortcut. However, the shortcut works only if Thunar window is active. Otherwise, nothing happens.
I work in Openbox window manager with Thunar as file-manager. So I can only talk about keyboard configuration of openbox. However, any window/desktop manager worth it's salt usually allows its users to configure global keyboard shortcuts.
The keyboard configuration for openbox is as follows. Open the file ~/.config/openbox/rc.xml and copy these lines under
<!-- Keybindings for running applications -->
<keybind key="F4">
      <action name="execute">
        <execute>thunar-terminal.sh</execute>
      </action>
    </keybind>
Now logout and login.

Thunar configuration

Thunar also requires a bit of configuration. I have noticed that the script works best if ``Location Selector" of thunar is in ``Toolbar Style". To select the ``Toolbar Style" of Thunar $ >$ View $ >$ Location Selector $ >$ Toolbar Style.
Now press ``F4" and watch as the xfce4-terminal opens in the working directory of Thunar.

Wednesday, October 12, 2011

Multi-document project in Kile+Okular

This is a continuation of my last post on synctex via kile and okular. In this post I will discuss how to handle multi-project documents while still having synctex facility.

Required scripts

For multi-document project one can do the following: First download the scripts latexmk and the script makelatex2. If the names of the downloaded scripts have extensions, then remove those extensions such that the name of the scripts are ``latexmk" and ``makelatex2". Make the scripts executable and copy them to your $HOME/bin. Create this directory if you don't have it and then log out and login back.

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'
    Advanced:
        Type: Run Outside of Kile
        Class: Compile
        Targe extension: pdf
        State: Editor
    Menu:
        Add tool to Build menu: Compile

  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'
        Advanced:
            Run Outside of Kile
            ForwardDVI
            Source extension: pdf
            Target extension: pdf
            State: Editor
        Menu:
            Add tool to Build menu: View
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 
    "Reload document on file change"
    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
    Insert spaces instead of tabulators
    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.

Friday, September 23, 2011

Synctex with GVim and Okular

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.
After downloading the file, rename it CommentLines.vim and copy the file to $HOME/.vim/plugin/. Now open any programming file (c, perl, tex, python, html, shellscript etc) in gvim. To comment lines select multiple lines and press ctrl+k. To uncomment select multiple commented out lines and press ctrl+l.
The script already has support for various types of programming language as mentioned. Support for other languages can be easily added.

ColorComment

Commented out text in gvim by default appears as blue, which IMHO grabs too much attention. So I wrote the ColorComment plugin. Grab it from here. After downloading it rename and copy it in the $HOME/.vim/plugin/ directory. Now if you open any programming file the commented out text appears in gray color. If you want to (un)highlight your comments, press Esc and then press ctrl+g. Ctrl+g is a toggle switch via which you can toggle between highlighted and un-highlighted comments.

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
 %
 \begin{equation}
 ${1}
 \end{equation}
 %
Now open any tex file and type ``beq" and press ``tab". ``beq" will get expanded to
%
\begin{equation}

\end{equation}
%
with the cursor blinking in-between \begin{equation} and \end{equation}. This is but a small example of what you can do with snipMate. Use the command
:help snipmate
in gvim to learn more.

LatexParFormat

Before I started using this script, I used to often find myself trying to manually resize paragraphs in latex after adding some text in-between paragraphs, so that the tex file would look nicely formatted. Meaning the lines would break off at column 72. Now with LatexParFormat, I can do just that with a shortcut key.
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.

That's all for now. If I write any more vim plugins or find other useful scripts, then I will definitely share them with you.

 In my next post I plan to talk about synctex using GVim and Okular. If you are wondering what synctex is all about, then a video in this blog post makes it clear.