[comp.text.tex] addbib for bibtex

skdutta@cs.tamu.edu (Saumen K Dutta) (08/11/90)

I am writing a program which works like addbib (in refer) to
insert bibliography for bibtex. I am writing it in the
shell language of UNIX. I am interested to know if there is
any program already available to do the same. It should be
( preferably) written in C, help the user to identify various
types of documents (e.g. manual, inproceedings etc) and also
optional and required fields. Though such a program may look
trivial as bibtex does not need coded field name ( as refer)
but it save lots of typing and errors especially when inserting
long bibliography list.

If anybody is interested to use or comment on my program I will
gladly e-mail it to him/her.

Please send e-mail. If there is interest I will summarize.

Thanks
S.K. Dutta

--
     _                                   ||Internet: skdutta@cssun.tamu.edu  
    (   /_     _ /   --/-/- _            ||Bitnet : skd8107@tamvenus.bitnet 
   __)_/(_____(_/_(_/_(_(__(_/_______    ||Uucp : uunet!cssun.tamu.edu!skdutta
                                 ..      ||Yellnet: (409) 846-8803

kas@cs.aber.ac.uk (Kevin Sharp) (08/17/90)

I use set of simple emacs functions to do this. I believe there are
other similar ones around.
Essentially all they do is give you a proforma for the various bibtex
entry types, and provide a facility to fill them in interactively.
It has the added facility of inserting a blank entry for a manditory
field if a null reply is entered in response to the prompt, but
leaving that field out if the field is not required.

--
--
Kevin Sharp,                      UUCP : {WALES}!ukc!aber-cs!kas
AI and Robotics Research Group,   JANET: kas@uk.ac.aber.cs
Department of Computer Science,   PHONE: +44 970  622450
University College of Wales, Aberystwyth, Dyfed, UK. SY23 3BZ

skdutta@cs.tamu.edu (Saumen K Dutta) (08/18/90)

Hi !

Sometime back I posted an article on this net <7342@helios.TAMU.EDU> 

-> I am writing a program which works like addbib (in refer) to
-> insert bibliography for bibtex. I am writing it in the
-> shell language of UNIX. I am interested to know if there is
-> any program already available to do the same.

I got the following responses from various people:
-------------------------------------------------------------
From John Eaton (jwe@emx.utexas.edu)

About a year ago I picked up a set of programs to do this.  They are
written in C and include a library of routines meant to read, write,
and search BibTeX database files.

Here's part of the man page:

     NAME
          bibtools
            bibc  - Create BibTeX and scribe style bibliographies
            bibv  - Verify a series of BibTeX style bibliographies for
                    citation conflicts
            shbib - Display one or more records from the specified bib files
            rmbib - Delete one or more records from the specified bib files

     DESCRIPTION
          bibc (mnemonic for BIB-Creator) is a prompt based tool for
          creating bibliographies in the BibTeX format.  bibc first
          queries the user for the kind of record they wish to create.
          bibc understands the various fields required for the kind of
          record specified, and will query the user for the values for
          each of these fields.  bibc can distinguish between required
          and optional fields, and will, by default insist once on the
          user specifying the required fields.

     AUTHOR
          Kannan Varadhan  - kannan@osc.edu

--------------------------------------------------------------------
From Lucien Van Elsen (lwvanels@mit.edu)

There's already a set of programs that do that already, with some added
functionality.  They were posted to comp.sources.misc a while back:

comp.sources.misc:bibtools   v09i046: bibtools:  tools for BibTeX

They're written in C, and available for anonymous ftp from uunet.uu.net
and other archive sites.

---------------------------------------------------------------------

From B. A. Lotto  (lotto@bosco.berkeley.edu)

There is a bibtex mode for emacs which I use and like.  It does all the
things you seem to want such an object to do, but it requires emacs.

------------------------------------------------------------------
From Sanjiv K. Bhatia (sanjiv@fergvax.unl.edu)


Here is a shellscript.  It uses another file called bibtypes that contains the
definitions of fields.  bibtypes is appended after the first file.

TOO BIG TO INCLUDE HERE. THOSE WHO ARE INTERESTED WRITE TO SANJIV AT THE
ADDRESS GIVEN ABOVE.

IT WORKS, IT DOES NOT LET YOU TO EDIT THE DATABASE WITHIN THE PROGRAM AND
DOES NOT CHECK FOR DUPLICATE KEY REFERENCES. 

-----------------------------------------------------------------------


FEW MORE REPLIES ........ BUT THEY DID NOT SAY ANYTHING DIFFERENT.

---------------------------------------------------------------------

Finally I rewrote my shell script and added few more functions to
it. I think it is complete now . If you like to give it a try please copy
it from my next posting.




--
     _                                   ||Internet: skdutta@cssun.tamu.edu  
    (   /_     _ /   --/-/- _            ||Bitnet : skd8107@tamvenus.bitnet 
   __)_/(_____(_/_(_/_(_(__(_/_______    ||Uucp : uunet!cssun.tamu.edu!skdutta
                                 ..      ||Yellnet: (409) 846-8803

skdutta@cs.tamu.edu (Saumen K Dutta) (08/18/90)

HI!

I have written this program to insert bibliography in bibtex. Please
try it out yourself and let me know what are the shortcomings. 
I could write it in C but I thought that writing it in this  
way is inexpensive. Also the source is not compiled and can be
changed very easily to suit individual requirements. 

Note: Before you execute it, copy it in a file and make the file executable.
      Be sure that you are working with the BSD version of UNIX. If you
      are working with system V unix you need to change the "echo"          
      statements in the shell script. If you have any problems write to me.


------------> CUT HERE <-----------------------
#! /bin/sh
#
# Written by :
#
#    Saumen K. Dutta
#    Graduate student
#    Computer Science Department
#    Texas A & M university
#    Dated: Aug. 17 1990
#
# contact me at <skdutta@cssun.tamu.edu> for any problems,
# suggestions and criticism.
#
# BUGS : 
#
# 1. Works only with the BSD version of unix. The command echo creates
#    the problem. It can be circumvented by redefining the echo command
#    according to your system.
#

read_Val1() { echo -n $1"(R) => " ; read  $1; 
		x='eval echo $`echo $1`'
		 while  [ -z  "`eval $x`" ]
			do
				echo $1 cannot be blank , Type again
				echo -n $1"(R) => " ; read $1;
			done
			}

read_Val() { echo -n $1"(O) => " ; read  $1; }

write_Val1() { x='eval echo $`echo $1`';
		echo $1 = \"`eval $x`\" ,;}

write_Val() { x='eval echo $`echo $1`';
		if [ "`eval $x`" ]
		then
			echo $1 = \"`eval $x`\" ,
		fi }

write_key() { 
		if [ "$key" ]
		then
			echo " " $key ,
		else
			echo 
		fi }


multi_rd1() { 
		for i in $1
		do
			read_Val1 $i
		done }

multi_rd() { 
		for i in $1
		do
			read_Val $i
		done }

multi_wr1() { 
		for i in $1
		do
			write_Val1 $i
		done }


multi_wr() { 
		for i in $1
		do
			write_Val $i
		done }

confirm() { echo ; echo -n "Are you Sure (y/n):" ; read yes_no;
	if [ -z "$yes_no" ]
	then
		yes_no="N"
	else
	  if [ "$yes_no" = "y" ]||[ "$yes_no" = "yes" ]|| \
		[ "$yes_no" = "Y" ]
	  then
	 	 yes_no="Y" 
	  fi 
	fi }


Entry_bib () {

echo
echo Following are the various codes:
echo
echo ""  1. article
echo ""  2. book
echo ""  3. booklet
echo ""  4. inproceedings / conference
echo ""  5. inbook
echo ""  6. incollection
echo ""  7. manual
echo ""  8. masterthesis
echo ""  9. misc
echo     10. phdthesis
echo     11. proceedings
echo     12. techreport
echo     13. unpublished
echo ""  H. HELP
echo ""  E. Examine or Edit the database
echo ""  C. Search for key clash in the database
echo
echo -n "TYPE the code: "
read type
echo
case $type in
1)	read_Val key ;
	multi_rd1 "author title journal year" ;
	multi_rd "volume number pages month note" ;
	confirm ;
	if [ "$yes_no" = "Y" ]
	then
		echo >> $1
		echo -n @article {  >> $1 ; write_key >> $1 ;
		multi_wr1 "author title journal year"  >> $1 ;
		multi_wr "volume number pages month note"  >> $1 ;
		echo  } >> $1 ; 
	fi
	;;
2)	read_Val key ;
	multi_rd1 "author title publisher year" ;
	multi_rd "volume series address edition month note"
	confirm ;
	if [ "$yes_no" = "Y" ]
	then
		echo >> $1
		echo -n @book {  >> $1 ; write_key  >> $1 ;
		multi_wr1 "author title publisher year"  >> $1 ;
		multi_wr "volume series address edition month note" >> $1 
		echo  } >> $1 ; 
	fi
	;;
3)	read_Val key ;
	read_Val1 title ;
	multi_rd "author howpublished address month year note" ;
	confirm ;
	if [ "$yes_no" = "Y" ]
	then
		echo >> $1
		echo -n @booklet {  >> $1 ; write_key  >> $1 ;
		write_Val1 title  >> $1 ;
		multi_wr "author howpublished address" >> $1 
		multi_wr "month year note"  >> $1 ;
		echo  } >> $1 ; 
	fi
	;;
4)	read_Val key ;
	multi_rd1 "author title booktitle year"
	multi_rd "editor pages organisation publisher address"
	multi_rd "month note"
	confirm ;
	if [ "$yes_no" = "Y" ]
	then
		echo >> $1
		echo -n @inproceedings {  >> $1 ; write_key  >> $1 ;
		multi_wr1 "author title booktitle year" >> $1 
		multi_wr "editor pages organisation publisher" >> $1 
		multi_wr "address month note" >> $1 
		echo  } >> $1 ; 
	fi
	;;
5)	read_Val key ;
	multi_rd1 "author title"
	echo -n "chapter(O) = " ; read chapter;
    echo -n "pages(O) = " ; read pages;
    while [ -z "$chapter" ] && [ -z "$pages" ]
    do
       echo Chapter and Pages both cannot be blank, Type again
       echo -n "chapter(O) = " ; read chapter;
       echo -n "pages(O) = " ; read pages;
    done
	multi_rd1 "publisher year"
	multi_rd "volume series address edition month note"
	confirm ;
	if [ "$yes_no" = "Y" ]
	then
		echo >> $1
		echo -n @inbook {  >> $1 ; write_key  >> $1 ;
		multi_wr1 "author title" >> $1 
        if [  "$chapter" ]
        then
           echo chapter = \"$chapter\", >> $1 
         fi
         if [  "$pages" ]
         then
            echo pages = \"$pages\", >> $1 
          fi
		multi_wr1 "publisher year" >> $1 
		multi_wr "volume series address edition month note" >> $1 
		echo  } >> $1 ; 
	fi
	;;
6)	read_Val key ;
	multi_rd1 "author title booktitle publisher year"
	multi_rd "chapter pages address month note"
	confirm ;
	if [ "$yes_no" = "Y" ]
	then
		echo >> $1
		echo -n @incollection {  >> $1 ; write_key  >> $1 ;
		multi_wr1 "author title booktitle publisher year" >> $1 
		multi_wr "chapter pages address month note" >> $1 
		echo  } >> $1 ; 
	fi
	;;
7)	read_Val key ;
	read_Val1 title ;
	multi_rd "author organization address edition month"
	multi_rd "year note"
	confirm ;
	if [ "$yes_no" = "Y" ]
	then
		echo >> $1
		echo -n @manual {  >> $1 ; write_key  >> $1 ;
		write_Val1 title  >> $1 ;
		multi_wr "author organization address edition month" >> $1 
		multi_wr "year note" >> $1 
		echo  } >> $1 ; 
	fi
	;;
8)	read_Val key ;
	multi_rd1 "author title school year"
	multi_rd "address month note"
	confirm ;
	if [ "$yes_no" = "Y" ]
	then
		echo >> $1
		echo -n @masterthesis {  >> $1 ; write_key  >> $1 ;
		multi_wr1 "author title school year" >> $1 
		multi_wr "address month note" >> $1 
		echo  } >> $1 ; 
	fi
	;;
9)	read_Val key ;
	multi_rd "author title howpublished month year note"
	confirm ;
	if [ "$yes_no" = "Y" ]
	then
		echo >> $1
		echo -n @misc {  >> $1 ; write_key  >> $1 ;
		multi_wr "author title howpublished month year note" >> $1 
		echo  } >> $1 ; 
	fi
	;;
10)	read_Val key ;
	multi_rd1 "author title school year"
	multi_rd "address month note"
	confirm ;
	if [ "$yes_no" = "Y" ]
	then
		echo >> $1
		echo -n @phdthesis {  >> $1 ; write_key  >> $1 ;
		multi_wr1 "author title school year" >> $1 
		multi_wr "address month note" >> $1 
		echo  } >> $1 ; 
	fi
	;;
11) read_Val key ;
	multi_rd1 "title year"
	multi_rd "editor publisher organization address"
	multi_rd "month note"
	confirm ;
	if [ "$yes_no" = "Y" ]
	then
		echo >> $1
		echo -n @proceedings {  >> $1 ; write_key  >> $1 ;
		multi_wr1 "title year" >> $1 
		multi_wr "editor publisher organization address" >> $1 
		multi_wr "month note" >> $1 
		echo  } >> $1 ; 
	fi
	;;
12) read_Val key ;
	multi_rd1 "author title institution year"
	multi_rd "type number address month note"
	confirm ;
	if [ "$yes_no" = "Y" ]
	then
		echo >> $1
		echo -n @techreport {  >> $1 ; write_key  >> $1 ;
		multi_wr1 "author title institution year" >> $1 
		multi_wr "type number address month note" >> $1 
		echo  } >> $1 ;
	fi
	;;
13) read_Val key ;
	multi_rd1 "author title note"
	multi_rd "month year"
	confirm ;
	if [ "$yes_no" = "Y" ]
	then
		echo >> $1
		echo -n @unpublished {  >> $1 ; write_key  >> $1 ;
		multi_wr1 "author title note" >> $1 
		multi_wr "month year" >> $1 
		echo  } >> $1 ;	
	fi
	;;
h|H) cat << EOF | more
--------------------------------------------------------
To skip any entry press <Enter>. Fields are marked as (R)
 or (O) specifying Required or Optional. Double quotes 
 need not be put, they are automatically inserted by the
 software. To insert more than one line for a particular
 field, end the line with a backslash.

Following are the explanations of various entry types:

article : An article from a journal or magazine.
book : A book with an explicit publisher.
booklet : A work that is printed and bound but without
           a named publisher or sponsoring institution.
conference : The same as inproceedings.
inbook : A part of book, which may be a chapter and/or
          a range of pages.
incollection : A part of book with it's own title.
inproceedings : An article in a conference proceedings.
manual : Technical documentation.
masterthesis : A Master's thesis.
misc : Use this type when nothing else fits.
phdthesis : A Ph.D thesis.
proceedings : The proceedings of a conference.
techreport: A report published by a school or other
             institution, usually numbered within a series.
unpublished : A document with an author and title but not
                formally published.
---------------------------------------------------------
EOF
;;
e|E) vi $1
;;
c|C) echo ; echo "Takes a while....... Hang on"
sed -n '/^[ 	]*@/p' $1 |
awk 'BEGIN {FS="," ; RS="{"} 
	{ print $1 }' | 
awk '{if ( $1 != "" ) print $1}'|
sort |
uniq -d |
more
;;

esac

}

ext_fl="N"
if [ -z "$1" ]
then
	echo "You must specify a bibliography file (database)."
	echo Usage : $0 filename
else
	while [ "$ext_fl" != "Y" ]
	do
		Entry_bib $1
		echo
		echo -n "Do you want to exit (y/n) : " ; read ext_fl;
		if [ -z "$ext_fl" ]
		then
			ext_fl="N"
		fi
		if [ "$ext_fl" = "y" ]||[ "$ext_fl" = "yes" ]|| \
			[ "$ext_fl" = "Y" ]
		then
	 		ext_fl="Y" 
		fi 
	done
fi

------------> CUT HERE <-----------------------
--
     _                                   ||Internet: skdutta@cssun.tamu.edu  
    (   /_     _ /   --/-/- _            ||Bitnet : skd8107@tamvenus.bitnet 
   __)_/(_____(_/_(_/_(_(__(_/_______    ||Uucp : uunet!cssun.tamu.edu!skdutta
                                 ..      ||Yellnet: (409) 846-8803

hf@marvin.e17.Physik.TU-Muenchen.DE (Hannes Faestermann) (08/20/90)

I use the bbitex-mode in emacs, provided by loading the file
bibtex.el. I don't know if this is available with the normal emacs
distribution. There maybe another file around named bibtex-mode.el,
but I like the first one better. You just type in 
C-c <letter> 
and in your bib-file appears a mask. You only have to fill in the
information.

This is a really nice thing to work with.

	Hannes

Hannes Faestermann    |   Internet: 
Physik-Department E17 |     H.Faestermann@marvin.e17.physik.tu-muenchen.de
TU Muenchen,          |   or:
8046 Garching         |     hf@marvin[.e17.physik.tu-muenchen.de]
West Germany          |   BitNET  : hf@dgablg5p
--
"Sometimes I think the surest sign that intelligent life exists elsewhere
 in the universe is that none of it has tried to contact us."
				Weirdos from another planet, Watterson

Hannes Faestermann    |   Internet: 
Physik-Department E17 |     H.Faestermann@marvin.e17.physik.tu-muenchen.de
TU Muenchen,          |   or:
8046 Garching         |     hf@marvin[.e17.physik.tu-muenchen.de]

kaul@icarus.eng.ohio-state.edu (Rich Kaul) (08/22/90)

In article <4051@tuminfo1.lan.informatik.tu-muenchen.dbp.de> hf@marvin.e17.Physik.TU-Muenchen.DE (Hannes Faestermann) writes:
   I use the bbitex-mode in emacs, provided by loading the file
   bibtex.el. I don't know if this is available with the normal emacs
   distribution. There maybe another file around named bibtex-mode.el,
   but I like the first one better. You just type in 
   C-c <letter> 
   and in your bib-file appears a mask. You only have to fill in the
   information.

It sounds like you have the VorTeX macro set installed since the
bibtex.el stuff isn't part of standard GNU emacs.  I do like them --
they do a good job of reducing the typing you have to do.  The LaTeX
and TeX modes are also quite good, and they are well documented.  The
macros are available for anonymous ftp on a.cs.uiuc.edu in
pub/TeX/vortex-macros.tar.Z.

-rich
-- 
Rich Kaul                         | It wouldn't be research if we
kaul@icarus.eng.ohio-state.edu    | knew what we were doing.

ralph@laas.fr (Ralph P. Sobek) (08/29/90)

In article <KAUL.90Aug21134748@icarus.eng.ohio-state.edu>
kaul@icarus.eng.ohio-state.edu (Rich Kaul) erroneously writes:
|    It sounds like you have the VorTeX macro set installed since the
|    bibtex.el stuff isn't part of standard GNU emacs.

I believe that bibtex.el *is* part of the GNU Emacs distribution.  At
least, it looks that way in the directory in which it resides.

;;; Simple BibTeX mode for GNU Emacs
;;; Bengt Martensson 87-06-28
;;; changes by Marc Shapiro shapiro@inria.inria.fr 15-oct-1986
;;;  (align long lines nicely; C-c C-o checks for the "OPT" string;
;;;   TAB goes to the end of the string; use lower case; use
;;;   run-hooks)

--
Ralph P. Sobek			  Disclaimer: The above ruminations are my own.
ralph@laas.fr				   Addresses are ordered by importance.
ralph@laas.uucp, or ...!uunet!laas!ralph		
If all else fails, try:				      sobek@eclair.Berkeley.EDU
===============================================================================
Reliable software should kill people reliably! -Andy Mickel, Pascal News #13,78

kaul@icarus.eng.ohio-state.edu (Rich Kaul) (08/30/90)

In article <RALPH.90Aug29161939@orion.laas.fr> ralph@laas.fr (Ralph P. Sobek) writes:
   I believe that bibtex.el *is* part of the GNU Emacs distribution.  At
   least, it looks that way in the directory in which it resides.

Mea culpa.  I rechecked the distribution and it turns out that I
installed the vortex macros over the old bibtex ones.  *sigh* Time to
remove my foot from my mouth.

I still prefer the VorTeX bibtex-mode, however.  It allows you to do
easy drafts, make abbrevs anywhere in the file and even automates the
previewing of the file from within the bibtex window ;-)

-rich
-- 
Rich Kaul                         | It wouldn't be research if we
kaul@icarus.eng.ohio-state.edu    | knew what we were doing.