[printer] Configure CUPS based printers

Tags

, , , ,

CUPS = Common UNIX Printing System

In order to search for the CUPS based printers connected to the computer (directly or via a network), use this command in the terminal:
lpstat -a
or type in the address field of a browser:
http://localhost:631/printers.

The following file controls the cups configurations:
/etc/cups/cupsd.conf.

Make sure you configure the file as follows:

1. Tell cupsd to listen broadcasts. This can be done by turning Browsing on
Browsing On.

2. Tell cupsd to listen broadcasts from other than local network as well.
BrowseOrder deny,allow
BrowseAllow ALL
.

[cli] Combine or remove pages from a PDF document using ghostscript

Tags

, , , ,

Combine pdf files:

$ gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=output.pdf pdffile1.pdf pdffile2.pdf

which combines pdffile1.pdf and pdffile2.pdf into a single ouput.pdf.


Delete certain pages of a PDF document:

$ gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -dFirstPage=m -dLastPage=n -sOutputFile=output.pdf input.pdf

where m and n are positive integers (page numbers), i.e. the above command only prints out pages starting from page number m through n of input.pdf into output.pdf.

[latex] Bibliography and citation in latex

Tags

, , , , , , , ,

This is a three part article describing different ways to handle bibliography and citation in LaTeX: (1) using  thebibliography environment, (2) using BibTeX, and (3) controlling BibTeX citations using natbib.

1. Using thebibliography environment to create bibliography:

The easiest way to create a bibliographic references for a scientific article is using thebibliography environment, especially when you have a very few references:

\begin{thebibliography}{99}
\bibitem[label1]{cite_key1} Mead, C. A.; Truhlar, D. G. {\it J. Chem. Phys.} {\bf 1979}, {\it 70}, 2284.
\bibitem[label2]{cite_key2} Mead, C. A.; Truhlar, D. G. {\it J. Chem. Phys.} {\bf 1983}, {\it 78}, 6344.
\end{thebibliography}

Notice that I have formatted the references in accordance with the requirement of the journal where I am going to send the article

Put the above environment in your LaTeX source file somewhere in between \begin{document} and \end{document}, where you want your bibliography to appear. The field with 99 in it indicates the maximum length of your entry labels. If you put 1 in place of 99, the bibligraphy cannot have more than 9 entries (because 10 has two digits, i.e. width=2). 99 is a safe number to use! The optional argument label at the beginning of each bibitem gives you an option to put your own label.

If you want to cite the second one, do it as

I am citing the second reference\cite{cite_key2} here.

Easy, isn’t it?

However, the problem with this is that you have to manually type each entry, and you cannot reuse the list for another journal unless you change the format by explicitly typing again. If you want to use the same bibliographic database again and again you should use BIBTeX (especially if you are going to stay long enough in this business!).

2. Using BibTeX to create bibliography:

A. First, create your bibliographic database.

I generally break it down into two parts: (1) abb.bib, which contains the 3-6 letter abberviations of the journal names and their expansion according to the journal where the article is going to be submitted, and (2) ref.bib, the actual bibliographic database with the 3-6 letter abbreviations in place of the journal names.

A sample of abb.bib:


@String{AnMath="Ann. Math."}
@String{CheRev="Chem. Rev."}
@String{CMP="Commun. Math. Phys."}

and a snippet of ref.bib:

@ARTICLE{agu71,
author = "J. Aguilar and J. M. Combes",
title = "A class of analytic perturbations for one-body {S}chr{\"o}dinger {H}amiltonian",
journal = CMP,
year = "1971",
volume = "22",
pages = "269--279",
}

I use the graphical front-end Jabref package to maintain the ref.bib file (in fact, I used Jabref when I first created the database). Besides editing and entering new references, I can also link individual PDF files of the corresponding entries — thus it’s a PDF organizer as well. However, in order not to have to modify the journal names I always put there the abbreviations (e.g. CMP for Communications in Mathematical Physics above) and expand their names manually in abb.bib in accordance with the requirement of the journal where I am going to send the article. So if I have the same bibliographic database, ref.bib I can use it for all the journals as long as I modify abb.bib correctly.

 

Note that the quotes in the database may be replaced by braces, but the braces have another very important use, namely to protect the contents within it:  the braces in  “{H}amiltonian” protects the uppercase H even though most bibliography styles  forces the whole title to be typeset as a sentence by lowercasing all letters except the first.

B. Cite!

Cite the reference in the same way as above, e.g.

I'm citing Aguilar and Combes' complex scaling paper.\cite{agu71}

Use the cite command to your heart’s content in the LaTeX source file and then proceed to the next step. Needless to point out, if you use a reference not in the database, ref.bib,  you must enter it in the database (or else don’t cite it at all!).

C. Copy the correct bibliography style (*.bst) file in the working directory.

It’s usually available in the CTAN or TUG websites. For example, for American Chemical Society’s Journals, the achemnat style file may be used [link].

[Update (11/19/2009): The original achemnat.bst file seems to be missing in the above link;  here is a copy from Google’s cache]

If you don’t want to use any style file, that’s OK, too (see below).

D. Link  the bibliographic style file and the database to the LaTeX source code.

Enter these two lines  where you want the bibliography to appear in the LaTeX source file:

\bibliographystyle{achemnat}
\bibliography{abb,ref}

The first one is to specify which style-file (here, achemnat.bst) is going to be used. If you don’t want to use any style file other than the default, just replace achemnat by plain above. Some styles files are in-built which comes with other packages. Some useful style files may be found here.

In the second line, the stuff in the curly brakcets tells LaTeX where to look for the bibliographic database. Here, abb refers to the file abb.bib, and ref to ref.bib [see 2. A above]. You need to copy these two files in your working directory.

E. Lastly, compile!

Compilation  is the trickiest part — you have to compile it twice (maybe, thrice!) with latex:

$ latex source.tex
$ bibtex source
$ latex source
$ latex source

3. Citation using natbib:
More control over citations for BibTeX can be achieved using natbib package [download link]  — include these in the preamble:

\usepackage[super,comma,numbers,sort&compress]{natbib} % First (see below)
\renewcommand\bibname{REFERENCES} % Second (see below)
\renewcommand{\bibnumfmt}[1]{(#1)} % Third (see below)

Let’s try to explain above options one-by-one:

  • First: the terms within the square bracket mean (in respective order) cite as superscripts; separate two citations by a comma; use numbers (not alphabet) for the citations; sort in increasing order and compress, i.e. if the references 1 and 3 through 5 are cited then show the citation as 1,3-5.
  • Second: give the bibliography the title “REFERENCES”.
  • Third: make the number format in the bibliography as (1), (2), etc.

Cite the references in the same way as above [see 2. B above].

See this link (PDF) for more details on natbib.

[vim] Move the line where the cursor is to the top, bottom or center by scrolling the page

Tags

, ,

While working on a file opened using vim I often want to see the line where the cursor is at in the center or at the top (and sometime at the bottom) by scrolling up or down — and I often forget how to do that without using j, k or other cursor movement commands. Here’s how to do it:

  • z. [z followed by a dot (.)] — to put the line with the cursor at the center,
  • zt — to put the line with the cursor at the top
  • zb — to put the line with the cursor at the bottom of the screen.

NOTE: A somewhat related  trick is to move your cursor to the top, middle or bottom of the screen without scrolling the page using H (i.e., shift+h), M and L, respectively.

[osx] Change the hostname in Mac (leopard)

Tags

, , , ,

For a last few days my Macbook “assumed” a weird hostname: kousik-mac(2) — I don’t know what I did that caused it. Here are three ways to change it (I don’t know if these qualify to be “NIX tricks” :D):

1. Click at the Sharing option in System Preferences and then click at Edit. You may change the computer name as well.

2. Use the following commandline-fu:
$ sudo scutil --set HostName your-preferred-hostname

3. Edit the preference file
$ sudo vi /Library/Preferences/SystemConfiguration/preferences.plist
Search for LocalHostname and change the text within the  <string>...</string> just under it. While you’re at it, you may want to change the string under ComputerName (need I say what it does?), as well — this key comes just after the previous one (HostName).

Design a site like this with WordPress.com
Get started