|
Cookbook /
BibtexRefSummary: Integrate bibtex bibliography into PmWiki site, display, manipulate and easily cite references
Version: 2004/12/23
Prerequisites:
Status:
Categories: Layout Publishing
GoalIntegrate your bibtex bibliography into your PmWiki site, display, manipulate and easily cite your references. SolutionThis little script allows you to display your bibtex bibliography into PmWiki in a convenient way and to put references to it. It introduces new markups and works directly over .bib files. Comments, suggestions should go to Alexandre [period] Courbot [snail] lifl [period] fr or Yann [period] Hodique [snail] lifl [period] fr. You can see an example usage of this script at http://www.lifl.fr/POPS/Eng/Publications. It demonstrates the query feature. DiscussionInstallation Get the source packageΔ and untar it inside your cookbook/ directory. You should have the following hierarchy: cookbook/bibtexref/ Then add include 'cookbook/bibtexref/bibtexref2.php'; to your config.php. Alternatively, you could use one of the newer, modified versions posted in the Comments section below. It is not required to install the script in its own "bibtexref" directory. You should also set the Also, you should upload a pdf.gif image file for displaying links to pdfs. New actions This script introduces a new PmWiki action: bibentry, which is used to display a bibtex entry on one page. It requires two additional parameters, bibfile (the file name to take the bibtex entry from) and bibref (the reference of the entry to display). PmWiki tags To make bibliographical references, you must first upload a few .bib files, either using PmWiki upload facility, or by copying them to uploads/Group/. Bibliography files are only usable within the group they are uploaded from. Citations are made with the tags {[...]} with the form: {[bibfile.bib,reference]}. They will expand to a clickable [reference] that will automatically direct you to the whole bibtex entry. You can also cite the entry summary using bibtexsummary:[bibfile.bib,reference]. Or you can quote the complete bibtex entry with bibtexcomplete:[bibfile.bib,reference]. These first tags correspond to my immediate needs, but I'm going to code something different and more generic later. You can also make bibtex queries, using the following syntax: bibtexquery:[bibfile.bib],[select rule][sort rule][limit rule] "select rule", "sort rule" and "limit rule" are directly PHP code. An example is much better than any explanation here: bibtexquery:[bibfile.bib][$this->get('YEAR') == '2004'][!$this->get('PUBDATE')][5]
gets the first five articles from 2004, sorted on publication date. bibtexquery:[bibfile.bib][strpos($this->get('AUTHOR'),'John Doe')!==FALSE][!$this->get('PUBDATE')][100]
Get the articles with 'John Doe' in the author list. A simular construct can also be used to search for words in the titel, abstract, etc. The History
Contributors
CopyrightThis software is distributed under the GNU General Public License. Comments(newest first) --- 2011-04-06 Not happy with the citation format, I propose a nice one, in order to make it integrated in a possible future release ?
#in cookbok/bibtexref/bibtexref2.php
/** this variant gives a nice (author & al., YYYY) scientific citation, instead of simple ref
*/
function cite()
{
$authors = $this->get("AUTHOR"); # get authors
$year = $this->get("YEAR"); # get year
$tauthors = split(",",$authors); # split them in an array with "," separator
if (count($tauthors) <= 1) $tauthors = split(" and ",$authors); # split them in an array with "and" separator if no ","
$out = "";
#print_r($tauthors);
if (count($tauthors) > 2) { # if more than 2 authors
$out = $tauthors[0]." & al.";
}else{
$out = $authors ;
}
$ret = "([[" . $this->getCompleteEntryUrl() . " | " . $out.", ".$year . "]])";
return $ret;
}
lokinou, happy to contribute 2011-04-01
here is my page code
this is the citation in the bib.bib file @ARTICLE{939829,
author={Pfurtscheller, G. and Neuper, C.},
journal={Proceedings of the IEEE}, title={Motor imagery and direct brain-computer communication},
year={2001},
It displays only closed empty parenthesis '()' what did I do wrong ? (no april's fools) Lokinou Auto solved : 2010-12-09 How to link to pdf file? With Attach:PDF Δ? Or do we add a field that specifies the pdf file to the bibtex entry? Thx. Oguz. 2010-07-06 For people having problems with && for anding conditions in the select rule of bibtexquery, a fix is to add:
$toeval = str_replace("&", "&", $toeval);
at line 58 in function evalCond. Frédéric Boulanger <frederic.boulanger@supelec.fr> 2010-1-16 For people having problems with the error messages: Warning: reset() [function.reset]: Passed variable is not an array or object in somedir/bibtexref/bibtexref3.php on line 841
Warning: Variable passed to each() is not an array or object in somedir/bibtexref/bibtexref3.php on line 843
(or slightly different line numbers) Make sure that the directory in your config.php has a trailing slash. IE $BibtexBibDir = 'somepath/references/' NOT $BibtexBibDir = 'somepath/references' This solved my problems (this problem around bibtexref3.php, line 987 - simple concatenation without checking for trailing slash). To make it not error so badly if the file isn't specified correctly: Around line 837, change if ($bibtable == false)
{
ParseBibFile($bib);
$bibtable = $BibEntries[$bib];
}
to if ($bibtable == false)
{
if(!ParseBibFile($bib))
return false;
$bibtable = $BibEntries[$bib];
}
Hope this helps! ~Ben 2009-05-11 How do I make a field silent? ie I don't want to display the pdf references in the complete bibtex reference? 2008-11-27 I have the same error message as reported by the previous message (2008-05-03) with problems on lines 843 and 845. Changing $HTTP_GET_VARS to $_GET does not solve the problem. Any idea? 2008-05-03 I'm missing something here, I tried setting it up but I keep getting this error message: Warning: reset() [function.reset]: Passed variable is not an array or object in XXX/bibtexref/bibtexref3.php on line 843
Warning: Variable passed to each() is not an array or object in XXXX/bibtexref/bibtexref3.php on line 845
and also "Invalid BibTex Entry!". First I thought there was something wrong with my references so I went to the example site and grabbed a reference there but I get the same error. I've applied the patch below. Does anyone have a suggestion of what the error could be or how I can get more info from the script about what fails? 2008-06-23 $HTTP_GET_VARS appears to be no longer supported in newer versions of PHP. Change these calls to $_GET 9 January 2008 A minor hack is needed for someone whose name includes the characters "and" (e.g., Sandeep becomes S, eep). line 72 of bibtexref3.php: $aut = explode("and", $aut);
>>>
$aut = explode(" and ", $aut);
line 72 of bibtexref3.php: $edi = explode("and", $edi);
>>>
$edi = explode(" and ", $edi);
Also, am currently unable to do "&&" query concatenation, though "||" is possible. Anding gives the previously mentioned "Parse error: parse error, unexpected ';' in cookbook/bibtexref/bibtexref3.php(57) : eval()'d code on line 1" Great otherwise, though I do wish the standard jan,feb,mar,apr... months were supported, I can change this in the (other, custom) tool I use to generate my .bib file. Thanks, Jonathan Sprinkle, http://www.ece.arizona.edu/~sprinkjm/Publications/ (28/01/2008) I have the same Problem. The error occurs in the function evalCond (line 53). Appending a second condition directly in the evalCond function works without problems. So I think there seems to be something wrong with handing over the &-symbol. (I have not a real idea of php)
A (dirty?) workaround: adding $toeval = str_replace("A_N_D", " && ", $toeval); before the eval() function and using A_N_D instead of &&.
Matthias
(28-Oct-2007) This is a great tool. Just a question: What should I use if I want to select a specific year and author's name? If I try to mix the two commands each between bracket, bibtexquery:[bibfile.bib][$this->get('YEAR') == '2004'][strpos($this->get('AUTHOR'),'John Doe')!==FALSE][!$this->get('PUBDATE')][5]
I get an error message. It is probably trivial, but I am not familiar with PHP. Thanks in advance. Normand --- Normand, you should just concatenate the two queries within the same bracket. Basically the queries are PHP code that is executed (urk, isn't that bad - you should control who can edit your pages then) to allow any possible combination. For instance, the following query bibtexquery:[bibfile.bib][$this->get('YEAR') == '2004' && strpos($this->get('AUTHOR'),'John Doe')!==FALSE][!$this->get('PUBDATE')][5]
should work for you. Thank you for your answer but this solution does not work. I get an error message about the PHP. "Parse error: parse error, unexpected ';' in cookbook/bibtexref/bibtexref3.php(57) : eval()'d code on line 1" If I try each condition separately, it works, but not together. I use the latest version of BibtexRef. Normand --- (18-Jun-2007) Thank you everyone for the beautiful work. I've had some problems making it work, but thanks to the suggestion by everyone, I've done it. I've only one question: there is a way to include at the end of a page a complete bibliography, able to collect the citations done in the text? (in complete latex style). I knew a wiki, Uniwakka, able to do that, but for work reason now I'm using PmWiki (that I consider better for a lot of reason), but having this kind of feature can be great. Thanks Maurizio ps: unfortunately I don't know php very well, but if someone can give me direction, I can try to write this feature if it's absent now. Certainly a little bit more of documentation can be useful, and because I'm going to write suggestions for my colleagues, maybe I can assemble them and post them (or there is documentation I didn't find?). (6-Jun-2007) Thank you to all the contributors who have worked on this recipe. Note to those who would like to use it with Asian language references: neither the file version nor the wiki-page version (bibtexref3.zip) are able to display Japanese titles saved as UTF-8. The titles get truncated in unpredictable places. It could be a problem with my setup (BibDesk on a Mac) but the .bib file looks fine in a UTF-8 text editor. --- I had the problem, that when opening a bib-entry, I got a page with " Invalid BibTex Entry: [,]! ". The solution below solved that for me. Matthias I have a problem with Pierre's version. In HandleBibEntry, but by replacing $bibfile = $HTTP_GET_VARS['bibfile']; $bibref = $HTTP_GET_VARS['bibref']; with $bibfile = $_GET["bibfile"]; $bibref = $_GET["bibref"]; it seems to work for me. -- F. I did a lot of changes. The most notable ones are:
See my example at http://www.cef-cfr.ca/index.php?n=Membres.DamaseKhasa My version includes Rob's change below.
I had a problem with a couple of escaped characters appearing in the eval statement, so I've added a couple of lines to replace these before they are eval'ed and removed the case sensitivity in the get() and getFormat() functions. Also, the inProceedings class had a bug (it declared getPages *inside* another function). These are all fixed here:
Also added $UploadExts['bib'] = 'text/plain'; to the end of the file to allow bibs to be uploaded without modification of config.php One final note - on my system it seems that when i refer to the bibtex file i have to add a forward slash, so [sample.bib] becomes [/sample.bib] --Rob The original version uses fgets without an (now optional) second parameter. With older PHP this leads to a flood of error messages --- with a decently big BIB file a deadly flood to the browser. Rob's version fixes this too. --Vaclav Is there an easy way to present all bib entries in the same page? If possible i'd like to present then divided by years and sorted by title. Unfortunately $this->get('YEAR') <= '2000' doesn't work. And Integer.parseInt($this->get('YEAR')) < 2000 doesn't seem to work either.--Bernd You have to add $toeval = str_replace("<", "<", $toeval); to the function evalCond (line 41) to be able to use the '<' symbol. Once you do that, '< 2000' works. I've done so in my version of the script: bibtexref2c.phpΔ --Anthony.
--- Great Program, thank you. Is there a way to display german charactes as ß äöü correct? One way is to make sure that those characters are encoded as HTML symbols in your bib file. So 'ü' for ü. The other way is to make sure that both the bibfile and the webpages that are generated use UTF-8 as it's character set.
You'll need to add $HTTPHeaders[] = 'Content-type: text/html; charset=utf-8;'; include_once('scripts/xlpage-utf-8.php');to the config.php to get complete utf-8 support. --Anthony. --- I met a problem with bibtexref2. If i use {[bilblio.bib,ref]} i have a message that Markup("bibtexcite","inline","/\\{\\[(.*?),(.*?)\\]\\}/e","BibCite('$1', '$2')")
by Markup("bibtexcite","inline","/\\{\\[(.*?),(.*?)\\]\\}/e","BibCite('/$1', '$2')")
my configuration is pmwiki-2.1.5, wikipublisher-2.0.5, netstream --François I also encountered the same problem of François and Rob, that you need an extra '/' in front of the bibfile. That also seems to be the case when specifying the PDF file. The latter, I couldn't fix the way François did, so I did the following in stead: To solve the PDF linking, I added the "/" to line 192: if (!$BibtexPdfUrl) $BibtexPdfUrl = FmtPageName('Then it seemed logical to do the same for the bibfile, adding "/" to line 748: if (!$BibtexBibDir) $BibtexBibDir = FmtPageName('That seems to have solved it. Hope it doesn't break anything... (I've included this changes in bibtexref2c.phpΔ ) Now I just wonder how the original Authors did it? If I look at bibtex entries on the example page, then they don't seem to have a problem with the PDF's... So is this a server specific issue? And if so, is there a general solution? BTW... Great plugin! --Anthony question: In the example usage some of the listed authors have a link to their pages. How do you do that? Answer (by Michaël Hauspie): In the wiki we are using, there are several Markup() call for each author, so the replacement is done by pmwiki example: Markup("mickey", "inline", "/Michaël Hauspie/", Keep("<a href='http://www.lifl.fr/~hauspie'>Michaël Hauspie</a>"));
--Anthony 12.8.2006: Thanks for this module, I will need it ;) Just to add a small hint: I wanted the bibcite links in the text to have 8-Sept-2006: This module is great and continues the desirable trend to blending LaTeX and the web. However, a few small issues arose:
@string{me="John Q Public"}
@string{you="Adam Bede"}
...
@article{ourwork2006,
author = me # " and " # you, ...
}
I can make a 1-time edit of my bib file for this.
This is trickier since two versions of the bib file would be necessary - for LaTeX and for pmwiki.
I looked at the source, but don't know enough php to do this, tho it sounds easier. Could you give a pointer on how to do this? Thanks. /WRF (http://wrfranklin.org) User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki. |