[texworks] JabRef Bibtex and php MySql insert \cite[]{}

Paul A Norman paul.a.norman at gmail.com
Fri Jul 16 08:50:24 CEST 2010


Hi all,

Here is a thing of interest, that others might adapt and use.

If you use JabRef ( http://jabref.sourceforge.net/ )  to maintain your
biblios, and have MySql and php (CLI)  then here is a system I
personally use.

JabRef lets me set up an MySql database very simply.

  (i)  Just use your MySql management tool of choice, and make a
database called jabref (no tables neeeded)
 (ii)  In Jab Ref open your biblio
(iii)  File/Connect to External SQL database
(iv)  File/Export to External Database

(I use this with then a latter JabRef  File/ Import From External
Database to mainatain my references through other interfaces as well.)

With that done,  you can use these twoi scripts, one a Qt TwScript,
the other a php script stored in the same directory under your Tw
Scripts folder.

And the normal sort of thing (don't forget to run BibTex in Tw after
your first pdflatex and then two more pdflatex(s)

\bibliographystyle{unsrt}
\bibliography{../../bibliographies/myBiblio}

Hope it helps/inspires someone,

Paul

Script One  - php called -    getCiteKeys.php

<?php
// Connecting, selecting database
$link = mysql_connect('localhost', 'root', '')
   or die('Could not connect: ' . mysql_error());
// echo 'Connected successfully';
mysql_select_db('jabref') or die('Could not select database');

// Performing SQL query
$query = 'SELECT cite_key FROM entries';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

 $build = "";

while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {

   foreach ($line as $col_value) {
      $build .=  $col_value .  "\n";
   }
}

// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);

echo $build;
?>

And now a Qt TwScript I use as -       insertCitation.js

//TeXworksScript
//Title: \cite from JabRef -> MySql
//Description: Make other Scripts
//Author: Paul A. Norman
//Version: 0.3
//Date: 2010-16-07
//Script-Type: standalone
//Context: TeXDocument
//Shortcut: Alt+B, Alt+C

var phpScript = __FILE__.substr(0,__FILE__.lastIndexOf("/") +1) +
'getCiteKeys.php';

// Non-windows OS-es won't need the cmd /c
var citeKeys = TW.app.system('cmd /c php ' + phpScript).split("\n");

var chosenCitation = TW.getItem( null, "Insert Citation", "Please
Choose A Citation Key: ", citeKeys , 0, true ) ;

  if (chosenCitation != undefined)
	 {
	
	    var pageRange = TW.getText( null, "Page Range", "Please enter A
Page Range etc.\n\nE.g.>  123-127", "");
		   if (pageRange == undefined)
			     {
			              pageRange = "";
			        }
			        else
			       {
			       pageRange = '[P.~'+ pageRange + ']';
			       }	
		
		 TW.target.insertText('\\cite'+pageRange+'{'+chosenCitation+'}');
				
		} // /End. IF chosenCitation != undefined
null;


More information about the texworks mailing list