citations

2 views
Skip to first unread message

jesse hoey

unread,
Dec 30, 2011, 9:39:59 AM12/30/11
to wikipublisher
Hi -
I really like the ability to edit citations, but is there any way to
include citations such that one can specify the data for the citation
(as with a <ref> tag in Wikimedia), rather than the raw .bbl content?
It seems this would be necessary for proper formatting of the
bibliography in different formats?

thanks and happy new year!
jesse

JR

unread,
Dec 30, 2011, 7:02:55 PM12/30/11
to wikipublisher
Hi Jesse

Can you give an example of what you mean?

When you include wiki markup in the definitions of references in a
(:bib:) ... (:bibend:) block (or in the individual fields when using
the edit feature), this is used to format the reference.

At the moment, there isn't a way to change the formatting of a
reference to use a different style for different purposes -- you have
to use markup to format the entries as you want them to appear in the
bibliography. For example, I use '/ ... /' markup to format titles.
However, you can switch between author-year and numbered citations.

There is a sample page showing a formatted bibliography at
http://www.wikipublisher.org/wiki/Bibliographies/Advocacy -- hope this
helps.

JR

jesse hoey

unread,
Dec 30, 2011, 8:22:26 PM12/30/11
to wikipublisher
Hi -
Right now I can easily do cite(John:2001) and then add a *John:2001
in between (:bib:) and (:bibend:), but then I have to specify the
reference text as a single string, so I can't guarantee uniformity
across all references. In LaTeX, I can specify each field
independently and then use different bib styles to format as is
necessary for a particular document. So I guess I'm looking for some
markup that is more like
<ref>title="my paper"|author="john and joe"| journal="journal of X"|
year="2001"</ref>

and this would be rendered automatically as a citation at the bottom
of the document and a reference in the text like (John,2001).

I have found Bibtexref which allows one to reference a .bib file from
the main wiki text, but then it seems you have to upload .bib files
for everything. This is great for the content, but not so for
usability.

Cheers,
jesse



On Dec 30, 7:02 pm, JR <ranki...@gmail.com> wrote:
> Hi Jesse
>
> Can you give an example of what you mean?
>
> When you include wiki markup in the definitions of references in a
> (:bib:) ... (:bibend:) block (or in the individual fields when using
> the edit feature), this is used to format the reference.
>
> At the moment, there isn't a way to change the formatting of a
> reference to use a different style for different purposes -- you have
> to use markup to format the entries as you want them to appear in the
> bibliography. For example, I use '/ ... /' markup to format titles.
> However, you can switch between author-year and numbered citations.
>
> There is a sample page showing a formatted bibliography athttp://www.wikipublisher.org/wiki/Bibliographies/Advocacy-- hope this

JR

unread,
Jan 1, 2012, 7:24:46 PM1/1/12
to wikipublisher
Hi Jesse

The other problem with using bibtexref is that it would need to output
citations and references in the correct wikibook xml when producing a
pdf version of the document. I don't know how easy or hard this would
be, but it's probably hard.

So let's think aloud about how practical it would be to extend the
citations recipe in wikipublisher to provide a field-oriented
interface. We don't want to re-write the citations recipe, but can we
extend it to provide different reference styles, without breaking
existing installations? First, let's agree on what we mean by
"citation" and "reference".

A citation is the bit in the body text, such as cite(Joe:2010), and a
reference is the description in the footer that describes Joe:2010 in
full. I think the cite(key) markup is already sufficiently flexible
and the focus for extension is the formatting of the references.

Suppose we adopt a syntax like key1="value1" key2="value2" ... -- this
will let us use the existing pmwiki "ParseArgs" function to take apart
the string.

Next, suppose we make a small change to cookbook/wikipublisher/
citations.php that does something like:

global $ReferenceFormatFunction;

...

if (@$ReferenceFormatFunction)
$citetext = $ReferenceFormatFunction($citetext);

Now you can provide your own formatting function using wiki markup;
for example:

function MyReferenceFormat($citetext) {
$opt = ParseArgs($citetext);
$layoutFmt = array('author' => array('o' => '', 'c' => ', '),
'title' => array('o' => "'/", 'c' => "/'"));
$out = array();
foreach($layoutFmt as $k => $v)
if ($opt[$k]) $out[] = $v['o]'.$opt[$k].$v[c'];
return count($out) ? implode($out) : $citetext;
}

You define the $layoutFmt array in the order you want the fields to
display, with markup to wrap around each field. If no fields are
defined, it returns the input string. The code could also treat
$layoutFmt as a global variable (so it can be set in local config.php
or Group.php files and be generalised to support different reference
types (books, journal articles, conference proceedings, etc). In
principle, it should be possible to provide a recipe for each desired
layout format -- you install the one you need, or write a new one.

What do you think? Is this what you had in mind?

JR

On 31 Dec 2011, 14:22, jesse hoey <jesse.h...@gmail.com> wrote:
> Hi  -
> > There is a sample page showing a formatted bibliography athttp://www.wikipublisher.org/wiki/Bibliographies/Advocacy--hope this

jesse hoey

unread,
Jan 2, 2012, 8:35:00 AM1/2/12
to wikipublisher


On Jan 1, 7:24 pm, JR <ranki...@gmail.com> wrote:
> Hi Jesse
>
> The other problem with using bibtexref is that it would need to output
> citations and references in the correct wikibook xml when producing a
> pdf version of the document. I don't know how easy or hard this would
> be, but it's probably hard.

Its pretty easy - you can get bibtexref to generate a string of text
(a "summary" reference) - not sure about the formatting though, but
there is probably a way to control that as well.


>
> Suppose we adopt a syntax like key1="value1" key2="value2" ... -- this
> will let us use the existing pmwiki "ParseArgs" function to take apart
> the string.
>
this sounds like a good approach


> Next, suppose we make a small change to cookbook/wikipublisher/
> citations.php that does something like:
>
> global $ReferenceFormatFunction;
>
> ...
>
> if (@$ReferenceFormatFunction)
>     $citetext = $ReferenceFormatFunction($citetext);

I take it these go in the ListCitations function, with the if
statement within the
foreach(preg_split(...))

is that right?



>
> Now you can provide your own formatting function using wiki markup;
> for example:

Great - this seems like it will fit the bill for me. I will have a
play around with this as soon as I get a chance and let you know how
it works out

I take it you mean ReferenceFormatFunction($citetext) here to fit with
the definition above?

JR

unread,
Jan 2, 2012, 6:27:51 PM1/2/12
to wikipublisher
Hi again -- this sounds like it's a promising approach to the
problem...

On 3 Jan, 02:35, jesse hoey <jesse.h...@gmail.com> wrote:
> On Jan 1, 7:24 pm, JR <ranki...@gmail.com> wrote:
>
> > Hi Jesse
>
> > The other problem with using bibtexref is that it would need to output
> > citations and references in the correct wikibook xml when producing a
> > pdf version of the document. I don't know how easy or hard this would
> > be, but it's probably hard.
>
> Its pretty easy - you can get bibtexref to generate a string of text
> (a "summary" reference) - not sure about the formatting though, but
> there is probably a way to control that as well.
>
Necessary, but not sufficient -- you can use the "View XML" button to
see all the wikibook xml that bibtexref would need to replicate. This
is left as an exercise for the reader :-)
>
>
> > Suppose we adopt a syntax like key1="value1" key2="value2" ... -- this
> > will let us use the existing pmwiki "ParseArgs" function to take apart
> > the string.
>
> this sounds like a good approach
>
> > Next, suppose we make a small change to cookbook/wikipublisher/
> > citations.php that does something like:
>
> > global $ReferenceFormatFunction;
>
> > ...
>
> > if (@$ReferenceFormatFunction)
> >     $citetext = $ReferenceFormatFunction($citetext);
>
> I take it these go in the ListCitations function, with the if
> statement within the
>  foreach(preg_split(...))
>
> is that right?

Yes, immediately above line 145, which reads:

if (@$ReferenceTag['n'])

And add

global $ReferenceFormatFunction;

at line 120
>
>
>
> > Now you can provide your own formatting function using wiki markup;
> > for example:
>
> Great - this seems like it will fit the bill for me. I will have a
> play around with this as soon as I get a chance and let you know how
> it works out
>
> I take it you mean ReferenceFormatFunction($citetext) here to fit with
> the definition above?

Not quite. We should make the function name a global variable, and do
the same for the layout format, so your recipe will look something
like:

$ReferenceFormatFunction = 'CustomReferenceFormat';

function CustomReferenceFormat($citetext) {
global $ReferenceLayoutFmt;
SDV($ReferenceLayoutFmt,
array('author' => array('o' => '', 'c' => ', '),
     'title'  => array('o' => "'/", 'c' => "/'")));
$out = array();
  foreach($ReferenceLayoutFmt as $k => $v)
  if ($opt[$k]) $out[] = $v['o]'.$opt[$k].$v[c'];
  return count($out) ? implode($out) : $citetext;
}

This creates 2 pieces of flexibility:

- people can define different $ReferenceLayoutFmt arrays for different
purposes without having to change the recipe -- the SDV function says
"use this definition only if the variable is undefined"

- people can use a completely different $ReferenceFormatFunction name
(or none)

Let me know how you get on. Once it's working, I'll add the enabling
code to citations.php and we can create a new recipe in the
wikipublisher cookbook at http://www.wikipublisher.org/wiki/Cookbook/Cookbook.

JR

JR

unread,
Jan 2, 2012, 6:32:47 PM1/2/12
to wikipublisher
Oops, missed a line. That should have read:

function CustomReferenceFormat($citetext) {
  global $ReferenceLayoutFmt;
  SDV($ReferenceLayoutFmt,
       array('author' => array('o' => '', 'c' => ', '),
             'title'  => array('o' => "'/", 'c' => "/'")));
$opt = ParseArgs($citetext);
$out = array();
  foreach($ReferenceLayoutFmt as $k => $v)
      if ($opt[$k]) $out[] = $v['o]'.$opt[$k].$v[c'];
  return count($out) ? implode($out) : $citetext;
}

JR
> wikipublisher cookbook athttp://www.wikipublisher.org/wiki/Cookbook/Cookbook.

jesse hoey

unread,
Jan 3, 2012, 7:06:37 AM1/3/12
to wikipublisher
Brilliant - this works nicely. I added the lines you said to
citations.php and then made the recipe below in cookbook/
refformat.php (some small typos in what you'd written) and added the
code below to my config.php file. this is pretty basic at this
point, but certainly shows the idea. I have quickly checked that this
works and I get PDFs formatted as expected, but not done any extensive
testing.


jesse

--- added to config.php:

include_once("cookbook/
refformat.php");

$ReferenceLayoutFmt=array('author' => array('o' => '', 'c' => ',
'),
'title' => array('o' => "'/", 'c' => "/'
"),
'journal' => array('o' => ' ', 'c'=> '.
'),
'booktitle' => array('o' => 'In ', 'c'=>'.
'),
'editors' => array('o' => ' ', 'c'=> ' (eds.).
'),
'volume' => array('o' => 'vol.', 'c'=> ',
'),
'number' => array('o' => 'no.', 'c'=> ',
'),
'month' => array('o' => ' ', 'c'=> ',
'),
'year' => array('o' => ' ', 'c'=> '.
'),
'publisher' => array('o' => ' ', 'c'=>'.
')
);

--- cookbook/refformat.php :

<?php if (!defined('PmWiki'))
exit();
$RecipeInfo['RefFormat']['0.1'] =
'20120103';
$ReferenceFormatFunction =
'CustomReferenceFormat';

function CustomReferenceFormat($citetext)
{
global
$ReferenceLayoutFmt;

SDV($ReferenceLayoutFmt,
array('author' => array('o' => '', 'c' => ',
'),
'title' => array('o' => "'/", 'c' => "/'
"),
'year' => array('o' => ' ', 'c' =>
'.')));
$opt =
ParseArgs($citetext);
$out =
array();
foreach($ReferenceLayoutFmt as $k =>
$v)
if ($opt[$k]) $out[] = $v['o'].$opt[$k].
$v['c'];
return count($out) ? implode($out) :
$citetext;
}

?

jesse hoey

unread,
Jan 3, 2012, 7:08:20 AM1/3/12
to wikipublisher
sorry - formatting was a little messed up in that post - lots of
additional newlines. Not sure how to avoid that here...

cheers

JR

unread,
Jan 3, 2012, 11:42:11 PM1/3/12
to wikipublisher
You might also change implode($out) to implode(' ', $out) and remove
the now unnecessary spaces from $ReferenceLayoutFmt. I can't think of
a case where a space between reference parts is not required.

JR
> > > > > > > > > I really like the...
>
> read more »
Reply all
Reply to author
Forward
0 new messages