[OJS 3.1] How to add a custom Citation Format (CSL)?

Hi! Is there a way to add any other Citation Format, except those in the current list?
I hoped there would be such an option, since that is what CSL is about :slight_smile:

Hi @Ph_We,

It’s possible to add a custom citation format but right now it requires custom coding. Essentially, you must write a custom plugin which hooks in to add the custom style file. If you would like to try it, @NateWr can give you a run-down of how to do it. Please let us know.

Best,
Amanda Stevens
Public Knowledge Project Team

1 Like

Hi @astevens,

Thanks very much for your answer. That would be good as a temporary workaround, especially if you could give me some working example (of how it works with the current formats).

But please, keep in mind, that the ability to add custom formats might be much anticipated.

P.S. I have actually been working on the custom format for the previous ‘How to cite’ plugin. And now it appears to be obsolete: GitHub - Ph-We/GOST: This plugin implements the GOST (ГОСТ 7.0.5-2008) citation format, which is widely used in many countries, like Russia, Ukraine, Belarus and others. :smiley:

Hi @Ph_We,

Yes, we’ve completely replaced the old Citation Formats plugins with the new CSL style generator. We plan to allow adding new formats with a simple file upload, but it didn’t make it into 3.1.

In the meantime, you can do so by creating a generic plugin, and using our hooks system to register a citation style. All default styles are registered in an array, which is then passed through a hook here:

When adding your custom style to this array, add a useCsl key which includes the full path to your custom CSL style. (All plugins include a Plugin::$pluginPath variable with the path to the plugin files.)

That will make the CSL file appear in the Citation Style Language plugin settings under Settings > Website > Plugins. You can then enable it there.

1 Like

Thank you so much, I’ll make a try.

Looks like citepro-php implementation of CSL used in OJS can’t make initials from cyrillic given. For example with latin character this works https://pj.iph.ras.ru/index.php/ph_j/article/view/46
and https://pj.iph.ras.ru/index.php/ph_j/article/view/100
And with cyrillic not https://pj.iph.ras.ru/index.php/ph_j/article/view/31

That’s my csl configuration for author:
<name initialize-with=". " initialize=“true” name-as-sort-order=“first” sort-separator=" ">

1 Like

Bug with cyrillic characters is fixed. initialize not works for cyrillic symbols · Issue #46 · seboettg/citeproc-php · GitHub

1 Like

Hi @litvinovg,

Thank you! When would this be available in OJS?

It is already available. https://github.com/pkp/citationStyleLanguage/issues/15

1 Like

Dear @NateWr,

since I have soooooooo no idea of PHP, could you please help me in constructing the necessary generic plugin?

So far I have:

<?php

import('lib.pkp.classes.plugins.GenericPlugin');

class AddCtECitationStyle extends GenericPlugin {
/**
 * Initialize the theme
 */
public function init() {
    HookRegistry::register ('CitationStyleLanguage::citationStyleDefaults', array(&$defaults, 'loadTemplateData'));
}

/**
 * Fired when the `TemplateManager::display` hook is called.
 *
 * @param string $hookname
 * @param array $args [$templateMgr, $template, $sendContentType, $charset, $output]
 */
public function loadTemplateData($hookName, $args) {

    // Retrieve the TemplateManager
    $templateMgr =& $args[0];

    // Attach a custom piece of data to the TemplateManager
    $cteStyle = array(
         'id' => 'journal-name',
         'title' => 'Journal Name',
         'isEnabled' => true,
         'useCsl' => '/srv/www/htdocs/journals/journal_name/plugins/generic/addCtECitationStyle/citationStyle.csl'
    );

    $templateMgr->assign('useCsl', $steStyle);
}

/**
     * @copydoc Plugin::getDisplayName()
     */
    function getDisplayName() {
            return __('New Citation Style');
    }
    /**
     * @copydoc Plugin::getDescription()
     */
    function getDescription() {
            return __('Add the CtE citation style to the Citation Style Language.');
    }
}

?>

And (surprise!), it does not work! Could you please tell me, what the registry expects?

Sorry for my ignorance.

@NateWr

May I push this again and bring it to some’s attention.

Hi @GrazingScientist,

Try this:

<?php

import('lib.pkp.classes.plugins.GenericPlugin');

class AddCtECitationStyle extends GenericPlugin {
	/**
	 * Hook into citation style
	 */
	public function init() {
		HookRegistry::register('CitationStyleLanguage::citationStyleDefaults', array($this, 'addCSLStyle'));
	}

	/**
	 * Add a CSL style to the list of default styles
	 *
	 * @param string $hookname
	 * @param array $args [$defaults, CitationStyleLanguagePlugin]
	 */
	public function addCSLStyle($hookName, $args) {
		$defaults = $args[0];

		$defaults[] = array(
			'id' => 'journal-name',
			'title' => 'Journal Name',
			'isEnabled' => true,
			'useCsl' => '/srv/www/htdocs/journals/journal_name/plugins/generic/addCtECitationStyle/citationStyle.csl',
		);
	}

	/* Your other methods */
}

Hi @NateWr,

thanks for the response. The code makes a lot more sense this way.

However, the citation style is not shown. Although the generic plugin from above is enabled, when I open the “Properties” field of the Citation Style Language in the Plugin section, the style is not there to be selected.

Do I have to select the style somewhere else?

Try changing this line:

$defaults = $args[0];

Add a & after the = like this:

$defaults =& $args[0];

If that doesn’t do it, can you share the full plugin you’re using to try to add the style? I’ll try it out and see if I can spot what’s missing.

Still does not work! I pushed the Plugin to GithHub.

Thanks for your help!

Great! That makes it very easy. I’ve issued a Pull Request to your repository with the necessary changes to make the plugin work:

https://github.com/GrazingScientist/CitationPlugin/pull/1

Perhaps noteworthy:

APA seems to be defaulted as the primary citation style via

'isPrimary' => true,

If you add this to the style added via GrazingScientist’s plugin while deleting it in CitationStyleLanguagePlugin.inc.php your custom CSL file will be the default citation style shown when opening the article page.

/**
 * Add a CSL style to the list of default styles
 *
 * @param string $hookname
 * @param array $args [$defaults, CitationStyleLanguagePlugin]
 */
public function addCSLStyle($hookName, $args) {
	$defaults =& $args[0];

	$defaults[] = array(
		'id' => 'contributions-to-entomology',
		'title' => 'Contributions to Entomology',
		'isEnabled' => true,
        'isPrimary' => true,
		'useCsl' => Core::getBaseDir() . '/' . $this->getPluginPath() . '/contribEntomol.csl',
	);
}

I played a litle with CSL styles and this model. Yes, APA default style, but only if no config in DB. After save plugin config - primary style can be different.
Other question - your custom style will be shown in config form to enable it and set it primary? I don`t know.
I used other approach - just added CSL style in builtin module…

1 Like

Thanks for the info!

Now I face a new problem though. The CSL Plugin is not shown as soon as I activate the custom plugin. It worked in XAMPP like a charm but won’t work on the server. See http://www.zjapanr.de/index.php/zjapanr/article/view/1.

Do we have the ability to add custom styles in the most current version of the plugin? (We are on 3.1.0.1 now, so we have not upgraded to 3.1.1).

2 Likes