By default the algorithmic package indents 2 em. It can be reduced or increased using a simple command.
Just place
\algrenewcommand\algorithmicindent{0.5em} % or any other value as you wish
before
\begin{document}
This will reduce or increase the indentation as you prefer.
Showing posts with label Latex. Show all posts
Showing posts with label Latex. Show all posts
Thursday, January 5, 2017
Tuesday, January 5, 2016
Creating .ps from tex
I did not know that creating a postscript file from the latex sources can be time consuming. The commonest option is to convert tex -> dvi using latex, and then dvi -> ps using a comment such as,
$ dvips -y 1200 -o main.ps -p 5 -n 3 main.dvi
In fact, traditionally it has always been tex -> dvi -> pdf. However, latex command often gives errors and issues in including the images, such as the below:
! LaTeX Error: Cannot determine size of graphic in deployments.png (no Bounding
Box).
Box).
See here.
Using pdflatex package avoids the issue with the images in tex to PDF conversion. However, I could not find a way yet to create a dvi or ps using pdflatex.
So for now, I am left with the option of tex -> pdf -> ps, using pdflatex and pdftops (I know it does not sound smart).
$ pdftops -level3 main.pdf main.ps
produced 18.2 MB of ps for a pdf of 863.6 kB.
For the same pdf,
$ pdftops -binary -level3 main.pdf main.ps
produced a ps output of 14.6 MB.
This was the smallest size I was able to go, without making the ps unreadable. The output ps is still not perfect, and the other packages and options provided an even worse ps.
Monday, January 4, 2016
ShareLatex - Life of a PhD Researcher..
Seriously. I am addicted to sharelatex.com. YouTube comes second (overtaking Facebook, since my deactivate last year). I even noticed when the ShareLatex servers went down for maintenance, which is not something that happens frequently.
![]() |
| Emergency Maintenance at ShareLatex |
Tuesday, December 22, 2015
Pretty Printing Algorithms and Pseudocodes in Latex
Latex is a very useful tool for the researchers in making research publications. In this post we will see writing algorithms/pseudocodes in Latex, through an example.
\documentclass{article}
\usepackage[utf8]{inputenc}
\title{Sample}
\author{Pradeeban Kathiravelu}
\date{December 2015}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{xcolor}
\begin{document}
\maketitle
\section{Introduction}
\begin{algorithm}[ht]
\fontsize{9}{9}\selectfont
\caption{\textit{$\partial$u$\partial$u} Initialization}
\label{alg:init}
\begin{algorithmic}[1]
\Procedure{\textit{$initialize$}}{$nodes$, $policy$}
\State \colorbox{blue!10}{$blockingKeySet$ $\gets$ $policy.getBlockingKeySet()$}
\ForAll { \colorbox{red!10}{($node$ \textbf{in} $nodes$)}}
\par \Comment {Let all the nodes join the coordinator cluster.}
\State \colorbox{green!10}{$joinCluster(node,coordinator)$}
\EndFor
\State \colorbox{green!10}{$adaptiveScale(blockingKeySet, policy)$}
\par \Comment {Monitors the health and scale the clusters accordingly.}
\ForAll { \colorbox{red!10}{($blockingKey$ \textbf{in} $blockingKeySet$})}
\State \colorbox{blue!10}{$index$ $\gets$ $generateIndex(nodes.count())$}
\par \Comment {At least one node joins a cluster.}
\State \colorbox{green!10}{$joinCluster(nodes.get(index),blockingKey)$}
\EndFor
\State \colorbox{green!10}{$initDataSourcesIntegrator()$}
\State \colorbox{green!10}{$initDataWarehouseIntegrator()$}
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}
The outcome will look as below:
Green background denotes executions. Blue background denotes data and data structure initializations. Red indicates a condition. The above code segment also includes the line numbers and comments.
The above Latex code segment and the respective algorithm are borrowed from the publication:
"Kathiravelu,
Pradeeban; Galhardas, Helena; Veiga, Luís; ",∂u∂u Multi-Tenanted
Framework: Distributed Near Duplicate Detection for Big Data,On the Move
to Meaningful Internet Systems: OTM 2015
Conferences,,,237-256,2015,Springer International Publishing. link.springer.com/chapter/10.1007/978-3-319-26148-5_14
Wednesday, September 2, 2015
ShareLatex and local compilation of Latex
ShareLatex is good at swallowing the compilation errors and still producing the correct PDF. However, when locally compiling, the local errors often prevent the compilation. For example, TexStudio often fails for similar or same errors. Typing "Enter" upon encountering such errors will make the compilation proceed, regardless of such error reports.
! Missing $ inserted.
> Check empty or blank lines between the \begin{equation} and \end{equation} tags.
! You can't use `\eqno' in horizontal mode.
> Check the closing braces in the equations.
! Missing $ inserted.
$
l.112 $\forall$ n $\in$ $\mathbb{Z}$^{+}: $C_
{Nn}$ represents the coordinato...
> Changing
$\forall$ n $\in$ $\mathbb{Z}$^{+}: $C_
into
$\forall$ n $\in$ $\mathbb{Z} ^{+}$: $C_
fixed this.
Tuesday, June 3, 2014
Working with LaTeX
While working with LaTeX for my master thesis, I found so many useful packages and commands in making the paper more attractive. I am listing some of them here. Please reply in comments, if you have some other suggestions on these.
1. Labelled Matrix.
![]() | ||||
| 1. Labelled Matrix |
\bordermatrix{\text{}&Exp_1&Exp_2& Exp_3 &Exp_4 & Exp_5 & Exp_6\cr
Node_1& S+C & I & 0 & 0 & 0 & 0\cr
Node_2& S+C & I & 2I & 0 & 0 & 0\cr
Node_3& I & 0 & S & I & 0 & 0\cr
Node_4& 0 & 0 & I & 0 & 0 & 0 \cr
Node_5& 0 & 0 & 0 & S+I & 0 & 0\cr
Node_6& 0 & 0 & 0 & 0 & I & I}
2. Code Segments
Java, C++, pseudo codes, or whatever that you would like to highlight and pretty print.
![]() |
| 2. Code Segments |
In the definitions,
\usepackage{listings}
\usepackage{color}
\usepackage{textcomp}
\definecolor{listinggray}{gray}{0.98}
\definecolor{lbcolor}{rgb}{0.98,0.98,0.98}
\lstset{
backgroundcolor=\color{lbcolor},
tabsize=4,
rulecolor=,
language=java,
basicstyle=\scriptsize,
upquote=true,
aboveskip={1.5\baselineskip},
columns=fixed,
showstringspaces=false,
extendedchars=true,
breaklines=true,
showtabs=false,
showspaces=false,
showstringspaces=false,
identifierstyle=\ttfamily,
keywordstyle=\color[rgb]{0,0,1},
commentstyle=\color[rgb]{0.133,0.545,0.133},
stringstyle=\color[rgb]{0.627,0.126,0.941},
}
Then, wherever you want it,
\begin{lstlisting}
String clusterGroup = HzConstants.MAIN_HZ_CLUSTER + id;
// Initialize the CloudSim library
HzCloudSim.init(ConfigReader.getNoOfUsers(), calendar, trace_flag, clusterGroup);
\end{lstlisting}
3. Equations
Use the Equations package, to include some equations or formulae. It is much convenient.
| 3. Equations |
\begin{equation} \label{eq:iequation}
T_{p} = \frac{k.T_{1}}{n} + (1-k).T_{1} + f(n) + S + F
\end{equation}
Speedup,
\begin{equation} \label{eq:baseequation}
S_{p} = \frac{T_{1}}{T_{p}}
\end{equation}
From equations \ref{eq:iequation} and \ref{eq:baseequation},
\begin{equation} \label{eq:finalequation}
S_{p} = \frac{T_{1}}{\frac{k.T_{1}}{n} + (1-k).T_{1} + f(n) + S + F}
\end{equation}
Having difficulty in generating the equations in LaTeX form? Don't worry. Use this web service, and pick LaTeX as the output format. Have a look at this guide, for an introduction to LaTeX Math. Have problems with the location of images in the output PDF? Have a look at this. Also if you have problems with Unicode characters, take a look at this. Specifically, the below error message is common with Unicode characters such as accented letters (e.g: é).
! Package inputenc Error: Unicode char \u8:�cn not set up for use with LaTeX.
Also consider using utf8x instead of utf8, as below, in the preamble, for Unicode characters.
\usepackage[utf8x]{inputenc}
Hope this post was useful. Will add more in a later post, probably. If you are looking for how to install LaTeX, have a look at this post.
Saturday, April 5, 2014
Installing Latex/PdfLatex on Ubuntu
PdfLatex is a tool that converts Latex sources into PDF. This is specifically very important for researchers, as they use it to publish their findings. It could be installed very quickly using Linux terminal, though this seems an annoying task on Windows. Installation commands are given below.
* Install the TexLive base
$ sudo apt-get install texlive-latex-base
* Also install the recommended and extra fonts to avoid running into the error [1], when trying to use pdflatex on latex files with more fonts.
$ sudo apt-get install texlive-fonts-recommended
$ sudo apt-get install texlive-fonts-extra
* Install the extra packages,
$ sudo apt-get install texlive-latex-extra
Once installed as above, you may be able to create PDF files from latex sources using PdfLatex as below.
$ pdflatex latex_source_name.tex
Also install texlive-publishers, to build with citations using BibTeX (to avoid error 2).
$ sudo apt-get install texlive-publishers
Once installed, you may compile with sources, using bibtex and latex.
$ latex latex_source_name.tex
$ bibtex latex_source_name
$ latex latex_source_name.tex
$ latex latex_source_name
Error 1:
grep: ptmr7t.log: No such file or directory
mktextfm: `mf-nowin -progname=mf \mode:=ljfour; mag:=1; nonstopmode; input ptmr7t' failed to make ptmr7t.tfm.
kpathsea: Appending font creation commands to missfont.log.
! Font OT1/ptm/m/n/10=ptmr7t at 10.0pt not loadable: Metric (TFM) file not found.
relax l.373 \normalfont
\selectfont
Error 2:
$ bibtex main
This is BibTeX, Version 0.99d (TeX Live 2013/Debian)
The top-level auxiliary file: main.aux
I couldn't open style file IEEEtran.bst
---line 2 of file main.aux
: \bibstyle{IEEEtran
: }
I'm skipping whatever remains of this command
I found no style file---while reading file main.aux
(There were 2 error messages)
Alternatively, you may just install the entire bundle:
$ sudo apt-get install texlive-full
Subscribe to:
Posts (Atom)





