Monday, February 8, 2016

Bibliography or Reference Management in LaTeX using Zotero Standalone

I use LaTeX for writing paper but it can be rather difficult, especially for beginners, to add citations and Bibliography. For this purpose I use Zotero Standalone which is an awesome software for reference management. It has a plugin for MS Word. However, for LaTeX, the citations need to be added manually. There are some automated tools available but I could not find an easy to use or dependable one. So I describe a process that you can use to add citations and bibliography directly in your LaTeX document from Zotero.

Adding Citations

Adding citations manually in LaTeX from Zotero is a pain. However, the process described below will make it a breeze for you. It contains the following steps:


  • Installing bibtex-citep.js

Download the bibtex-citep.js translator from here (http://pastebin.com/UNVexqKc). Great work by these guys! This translator will allow you to easily cite the paper using a simple drag-drop procedure in your LaTeX file. However, first we need to install it. Place the downloaded file in the "translators" folder in Zotero standalone.  You can access this folder by opening Zotero Standalone and navigating as (see image below): Tools > Preferences > Advanced (tab) > File and Folders (sub tab) > Show Data Directory. This data directory contains the "translators" folder.




  • Restart Zotero
  • For exporting citations as \cite{...} from Zotero, you would need to set the export mode of Zotero to bibtex-citep. You can do this as follows: In Zotero, Go to Tools > Preferences > Export (tab) > Select Export Format (drop down menu), select "bibtext-citep" and click OK.
  • Now you can add citations from Zotero directly. To do this you can select a paper in Zotero and drag-drop it in your opened LaTeX file in a text editor and it will create a \citep{...} citation automatically. If you want \cite{...} or \citet{...} you can manually edit the name of the field in your text editor. An alternative way is to click on the paper in Zotero to select it and then press Ctrl+shift+C to export the citation to the clipboard which can then be pasted anywhere you like.

Adding Bibliography

Adding bibliography requires a simple export of the Zotero Library as BibLaTeX. This can be easily accomplished by Clicking on File > Export Library. An "export" dialog will appear and you can simply select "BibLateX" as the format and click OK.It will ask you where to save the bib file and what name to give it. You can choose any name (say, "mybib.bib") for it and save it in the directory containing your LaTeX sources. You can then simply add "\bibliography{mybib}" to your LaTeX file and compile your LaTeX source.

If you do not want to export your whole Zotero library, you can choose to create a collection or add specific tags in Zotero to the papers that you cite or use in your LaTeX document and then export only that collection by right clicking on the collection in the left pane of Zotero Standalone. You can read more about Collections and tags hereAlternatively you can use the following python script to get a cleaned up bib file containing the bib entries for the citations you have in your paper. It takes the zotero exported bib file and a bbl file generated by LaTeX from the zotero bib file to create another bib file containing only the cited entries. This output file can then be used in your LaTeX document.

Enjoy!


# -*- coding: utf-8 -*-
"""
Created on Sun Jan 18 12:23:36 2015

@author: Afsar
"""
from pyparsing import nestedExpr
import re

bbl = '.\paper.bbl' #input bbl file
bibin = '.\mybib.bib' #zotero bib file 
bibout = 'outbib.bib' #output file containing only the citations used

B = []
with open(bbl,'r') as fbbl:
    for ln in fbbl:
        if 'bibitem' in ln:
            B.append(ln[ln.find('{')+1:-2])

fields = []
i=-1
with open(bibin,'r') as fbibin:
    for ln in fbibin:
        if ln and ln[0] == '@':
            i+=1
            fields.append('')
        if i<0:
            continue
        fields[i]+=ln

entries = {}       
for f in fields:
    hdr = f.split(',')[0].split('{')[1]
    entries[hdr]= f

with open(bibout,'w') as fout:
    for b in B:
        try:
            fout.write(entries[b])
        except KeyError as e:

            print e,':',b



Sunday, December 20, 2015

Tie your destiny to a star. Even if you fall, people will look up to you!

-F

Friday, December 18, 2015

Salar Aghili / Hafez Poem : Magic Eyes





Until your hair falls through the fingers of the breeze
My yearning heart lies torn apart with grief
Black as sorcery, your magic eyes
Render this existence an illusion
The dusky mole encircled by your curls
Is like the ink-drop falling in the curve of the jeem (ج)
And wafting tresses in the perfect garden of your face,
Drop like a peacock falling into paradise
My soul searches for the comfort of a glance
Light as the dust arising from your path
Unlike the dust, this earthly body stumbles,
Falling at your threshold, falling fast
Your shadow falls across my frame
Like the breath of Jesus over withered bones
And those who turn to the Ka’aba as their sanctuary
Now with the knowledge of your lips, tumble at the tavern door
O precious love, the suffering of your absence and lost Hafez
Fell and fused together with the ancient past

"Grandiosity" by Robert Bly!

Poems in Three Parts

1

Oh on an early morning I think I shall live forever!
I am wrapped in my joyful flesh
As the grass is wrapped in its clouds of green.

2

Rising from a bed where I dreamt
Of long rides past castles and hot coals
The sun lies happily on my knees;
I have suffered and survived the night
Bathed in dark water like any blade of grass.

3

The strong leaves of the box-elder tree
Plunging in the wind call us to disappear
Into the wilds of the universe
Where we shall sit at the foot of a plant
And live forever like the dust.

Monday, December 7, 2015

Salar Aghili- Hazaran sal ba fitrat nishastam(Farsi Kalam-e-Iqbal with U...

Armand Amar Poem Of The Atoms




ای روز برا که ذره ها رقص کنند
آن کس که از او چرخ و هوا رقص کنند
جانها ز خوشی بی سر و پا رقص کنند
در گوش تو گویم که کجا رقص کنند
هر ذره که در هوا یا در هامون است
نیکو نگرش که همچو ما مفتون است
هر ذره اگر خوش است اگر محذون است
سرگشته خورشید خوش بی چون است

O’ day, arise!

Shine your light, the atoms are dancing.

Thanks to Him the universe is dancing.

overcome with ecstasy,



Free from body and mind

I’ll whisper in your ear where their dance is leading them.

All the atoms in the air and in the desert are dancing,

puzzled and drunken to the ray of light,

they seem insane.



All these atoms are not so different than we are,

happy or miserable,

perplexed and bewildered,

we are all beings in the ray of light from the beloved,

nothing can be said!

Tuesday, November 17, 2015

Iqbal

فطرت کو خرد کے روبرو کر
تسخیر مقام ِ رنگ بو کر
بے ذوق نہیں اگرچہ فطرت
جو اس سے نہ ہو سکا وہ تو کر

یہ کائنات ابھی نا تمام ہے شائد
کہ آرہی ہے دمادم صدائے کن فیکون

خون رگ معمار کی گرمی سے ہے تعمیر
میخانہ حافظ ہو کہ بت خانہ بہزاد
بے محنت پیہم کوئی جوہر نہیں کھلتا
روشن شرر تیشہ سے ہے خانہ فرہاد

رنگ ہو یا خشت و سنگ ، چنگ ہو یا حرف و صوت
معجزہ فن کی ہے خون جگر سے نمود
نقش ہیں سب ناتمام خونِ جگر کے بغیر
نغمہ ہے سودائے خام خونِ جگر کے بغیر