# citeproc-php # [](https://packagist.org/packages/seboettg/citeproc-php) [](https://packagist.org/packages/seboettg/citeproc-php/stats) [](https://opensource.org/licenses/MIT) [](https://scrutinizer-ci.com/g/seboettg/citeproc-php/build-status/master) [](https://scrutinizer-ci.com/g/seboettg/citeproc-php/code-structure/master/code-coverage/src/) [](https://scrutinizer-ci.com/g/seboettg/citeproc-php/?branch=master) [](https://scrutinizer-ci.com/code-intelligence)     citeproc-php is a full-featured CSL 1.0.1 processor that renders bibliographic metadata into html formatted citations or bibliographies using CSL stylesheets. citeproc-php renders bibliographies as well as citations (except of [Citation-specific Options](http://docs.citationstyles.org/en/stable/specification.html#citation-specific-options)). ## Citation Style Language CSL ## The Citation Style Language (CSL) is an XML-based format to describe the formatting of citations, notes and bibliographies, offering: * An open format * Compact and robust styles * Extensive support for style requirements * Automatic style localization * Infrastructure for style distribution and updating * Thousands of freely available styles (Creative Commons BY-SA licensed) For additional documentation of CSL visit [http://citationstyles.org](http://citationstyles.org). ## Installing citeproc-php ## The recommended way to install citeproc-php is through [Composer](https://getcomposer.org). ```bash $ curl -sS https://getcomposer.org/installer | php ``` Add the following lines to your `composer.json` file in order to add required program libraries as well as CSL styles and locales: ```json { "name": "vendor-name/program-name", "repositories": [ { "type": "package", "package": { "name": "citation-style-language/locales", "version":"1.0.0", "source": { "type": "git", "url": "https://github.com/citation-style-language/locales.git", "reference": "master" } } }, { "type": "package", "package": { "name": "citation-style-language/styles", "version":"1.0.0", "source": { "type": "git", "url": "https://github.com/citation-style-language/styles.git", "reference": "master" } } } ], "require": { "citation-style-language/locales":"@dev", "citation-style-language/styles":"@dev", "seboettg/citeproc-php": "^2" } } ``` Next, run the Composer command to install the latest stable version of citeproc-php and its dependencies: ```bash $ php composer.phar install --no-dev ``` After installing, you need to require Composer's autoloader: ```php require 'vendor/autoload.php'; ``` You can then later update citeproc-php using composer: ```bash $ composer.phar update --no-dev ``` If you have trouble using composer you will find further information on [https://getcomposer.org/doc/](https://getcomposer.org/doc/). ## How to use citeproc-php ## citeproc-php renders bibliographical metadata into html formatted citations or bibliographies using a stylesheet which defines the citation rules. ### Get the metadata of your publications ### Create a project folder: ```bash $ mkdir mycslproject $ cd mycslproject ``` First, you need json formatted metadata array of publication's metadata. There are a lot of services that supports CSL exports. For instance [BibSonomy](https://www.bibsonomy.org), [Zotero](https://www.zotero.org/), [Mendeley](https://www.mendeley.com/). If you don't use any of these services, you can use the following test data for a first step. ```javascript [ { "author": [ { "family": "Doe", "given": "James", "suffix": "III" } ], "id": "item-1", "issued": { "date-parts": [ [ "2001" ] ] }, "title": "My Anonymous Heritage", "type": "book" }, { "author": [ { "family": "Anderson", "given": "John" }, { "family": "Brown", "given": "John" } ], "id": "ITEM-2", "type": "book", "title": "Two authors writing a book" } ] ``` Copy this into a file in your project root and name that file `metadata.json`. ### Build a first simple script ### ```php render(json_decode($data), "bibliography"); ``` You can also render citations instead of bibliographies: ```php echo $citeProc->render(json_decode($data), "citation"); ``` ### Filter Citations ### Since version 2.1 you have also the possibility to apply a filter so that just specific citations appear. ```php
This a wise sentence render($data, "citation", json_decode('[{"id":"item-1"}]')); ?>.
This is the most wise sentence render($data, "citation", json_decode('[{"id":"item-1"},{"id":"ITEM-2"}]')); ?>.
``` ### Bibliography-specific styles using CSS ### Some CSL stylesheets use bibliography-specific style options like hanging indents or alignments. To get an effect of these options you can render separated Cascading Stylesheets using CiteProc. You have to insert these styles within the `` tag of your html output page. ```php render(json_decode($data), "bibliography"); $cssStyles = $citeProc->renderCssStyles(); ?>This ia a wise sentence render(json_decode($data), "citation", json_decode('[{"id":"item-1"}]')); ?>.