A citation plugin that implements basic functionality, hoping to make your SiYuan more academically oriented.
Update 0.3.6:
Edit -> Preferences -> Advanced -> Editor
and set extensions.zotero.debug-bridge.token
to your password, and update to the latest version of the citation plugin to use it properly.Starting from version 0.1.1, this plugin now supports accessing Zotero using the debug-bridge plugin. Compared to the current method of using better-bibtex, this approach provides faster access and higher efficiency. Additionally, it enables many extra functionalities (for more details, see the ttChen's Quicker Actions, which might be integrated into this plugin for both Siyuan and Zotero functionalities). Users who wish to utilize this feature should prepare in advance by following the specific steps outlined in Run Javascript in Zotero.
Special thanks to Geo123abc for creating the tutorial video.
Add citations to your notes, which refer to literature note generated in a specified folder, as shown in the following image:
Currently, you can use three different sources for literature data: Data Files (BibTeX and CSL-JSON), Zotero/Juris-M (using Better BibTeX plugin), and Zotero/Juris-M (using debug-bridge plugin). The following table provides a comparison between the three data sources:
Data Source | BibTeX and CSL-JSON | Zotero/Juris-M with Better BibTeX plugin | Zotero/Juris-M with debug-bridge plugin |
---|---|---|---|
Literature Identifier | citekey Allows multiple files Ensure uniqueness on your own |
citekey Generated by BBT |
citekey / itemKey citekey generated by BBT itemKey generated by Zotero |
Search Panel | Citation plugin panel | Zotero panel | Citation plugin panel / Zotero panel (optional) |
Initialization Speed | Slow | Fast | Fast |
Search/Insert Speed | Fast | Slow | Fast (Citation plugin panel) |
Compatible with Zotero 7 | - | × (temporarily) | √ |
Compatible with Other Reference Managers | ✓ | × | × |
Supports Importing PDF Annotations | × | × | ✓ |
Support for Automatic Referencing from Zotero Drag-and-Drop | × | ✓ | ✓ |
Supports Inserting Multiple Literature at Once via Search Panel | × | ✓ | × (Citation plugin panel) ✓ (Zotero panel) |
Insert Zotero Selected Items | × | × | ✓ |
Insert Custom Tags into Zotero Items | × | × | ✓ |
Generate Word Document with Citations (future version) | × | ✓ | ✓ |
Citation for SiYuan
plugin switch in Settings - Marketplace - Downloaded
to enter the settings panel. Alternatively, you can directly enter the plugin's settings panel by clicking on "Citation for SiYuan" in the plugin menu after clicking on the top toolbar's plugin button./
, for example, /References
or /Assets/References
. Note that this path is essentially the document's location, so do not include a trailing /
. Note: If you change the path of the library, the literature libraries on the previous path will become invalid. Additionally, please ensure that the document exists, as the plugin does not automatically create the library document if it does not exist.If you have any doubts about this process, please refer to the tutorial video created by Geo123abc. If you still have questions, feel free to raise an issue on the plugin's GitHub repository or contact me via email (siyuan_citation@126.com)
csl-json
and bibtex
files in the [Workspace]/data/storage/petal/siyuan-plugin-citation/references/
folder, which contain the literature you want to reference. Refer to How to Obtain Literature Data Files for methods to obtain the files.Zotero (better-bibtex)
or Juris-M (better-bibtex)
as the database type.Zotero (debug-bridge)
or Juris-M (debug-bridge)
as the database type.Slash Menu:
You can access this option in the slash menu by typing "插入文献引用," "addcitation," or "charuwenxianyinyong."
You can access this option in the slash menu by typing "插入文献笔记," "addliteraturenotes," or "charuwenxianbiji."
You can access this option in the slash menu by typing "引用Zotero中选中的文献," "addzoteroselecteditemscitations," or "yinyongzoterozhongxuanzhongdetiaomu."
Commands (can be searched directly in the Top Bar Plugin Button - Command Panel
or set shortcuts in Settings - Shortcuts - Plugins - Literature Reference
):
Document's upper-right "More" menu:
{{ }}
, for example {{title}}
.Shift/Ctrl + Enter
to line break and use Tab
to input tab characters.In the templates for literature content and citations, the following variables can be used, and they are undefined by default if not present:
- {{key}}: Unique identifier of the literature, depending on whether "Use itemKey as Index" is enabled, it will be "libraryID_citekey" or "libraryID_itemKey," always exists.
- {{citekey}}: Identifier of the literature, requires ensuring uniqueness when using data files, automatically generated by the Better BibTeX plugin, if not installed, it will be the same as itemKey.
- {{itemKey}}: Unique identifier of the literature entry in Zotero, automatically generated by Zotero, does not exist if not using Zotero.
- {{libraryID}}: Library ID of the literature content in Zotero, defaults to 1 if using data files, and will support multiple libraries (multiple files with duplicate citekeys) in the future, does not exist if not using Zotero.
- {{abstract}}: Abstract.
- {{authorString}}: String of all authors sorted in order, empty string if not present.
- {{containerTitle}}: Title of the publication (journal, conference proceedings, etc.) where the literature is located, null if not present.
- {{DOI}}: DOI of the literature.
- {{eprint}}: Eprint.
- {{eprinttype}}: Type of the eprint.
- {{eventPlace}}: Location of the event (e.g., conference).
- {{page}}: Page numbers.
- {{publisher}}: Publisher.
- {{publisherPlace}}: Place of publication.
- {{tags}}: All tags, connected with ", "; CSL-JSON files do not have this variable, empty string if not present.
- {{title}}: Title.
- {{titleShort}}: Abbreviated title, many literature entries do not have an abbreviated title.
- {{type}}: Type of the literature (note: the type identifier may be different when directly obtained from Zotero and when obtained after exporting).
- {{URL}}: URL of the literature.
- {{year}}: Publication year of the literature.
- {{files}}: Attachments of the literature. Will be displayed in the default format, one file per line, with a link to navigate to the file in Zotero (if it is a PDF, the link can directly open the PDF in Zotero).
- {{fileList}}: Attachments of the literature in the initial data source format, for user customization. It is an object list and can be accessed by using ".", empty list if not present. The method to call its attributes is as follows:
- {{fileList[i].type}}: Type of the attachment, i.e., the file extension.
- {{fileList[i].fileName}}: Complete file name of the attachment.
- {{fileList[i].path}}: Absolute path of the attachment, with `file://`.
- {{fileList[i].zoteroSelectURI}}: Link to select the attachment in Zotero (link only).
- {{fileList[i].zoteroOpenURI}}: Link to directly open the attachment in Zotero (link only, for PDF files only).
- {{zoteroSelectURI}}: Directly navigate to the corresponding item in Zotero.
- {{note}}: Notes made in Zotero, supports direct navigation to Zotero through links.
Additionally, the following variables can be used in the citation links:
- {{shortAuthor}}: Generates a shorter author string according to the IEEE format (approximately), for example, "Lin and Morse et al.," empty string if not present.
- {{citeFileID}}: ID of the literature content document in SiYuan, used to assist in generating citation links or external links, for example, `20230707192208-ocs4482`.
The templates also include the following special variables:
moment()
object of the current time, allows customizing the format in the template, method reference moment.js.If you use Zotero/Juris-M (debug-bridge) as the data source for literature, you can use the following variables:
- {{annotations}}: PDF annotations of the literature, distinguished by the document they belong to, also supports displaying annotations in batches, empty string if not present.
- {{annotationList}}: Initial data source format of PDF annotations, for user customization. It is an object list and can be accessed by using ".", empty list if not present. The method to call its attributes is as follows:
- {{annotationList[i].parentKey}}: itemKey of the Zotero item where the annotation is located.
- {{annotationList[i].parentTitle}}: Title of the PDF file where the annotation is located.
- {{annotationList[i].detail}}: Details of single PDF file annotations, which is a list.
- {{annotationList[i].detail[j].key}}: itemKey of the single annotation.
- {{annotationList[i].detail[j].annotationText}}: Text content of the single annotation.
- {{annotationList[i].detail[j].annotationComment}}: Comment of the single annotation.
- {{annotationList[i].detail[j].annotationPosition}}: Position of the single annotation, you can use `.pageIndex` to obtain the page number of the annotation.
- {{annotationList[i].detail[j].zoteroOpenURI}}: Link to directly open the location of the annotation in Zotero.
For more variables, check the "entry-data" attribute of the literature content document after importing, which includes all the information imported for that literature.
In version 0.0.6, the template handling section utilizes template.js. To accommodate the template syntax commonly used by general users, before performing variable calculations and replacements, all {{ }}
will be replaced with <%= %>
for template.js to process the templates. Therefore, besides using the existing {{variable}}
syntax, there are many advanced usage methods available:
{{ }}
.For example, the following template allows the line to not appear as "Tags: " when there are no {{tags}}
variables:
{{ tags.length ? `\n**Tags**:\t\t${tags}` : "" }}
And the following template prevents the "Files" section from being generated when there are no associated files:
<% if (files.length) { %>
# Files
{{files}}
<% } %>
The following template has the same effect as the previous one:
<% if (fileList.length) { %>
# Files
{{fileList.map(file => {if (file.type === "pdf") return `[[Open]](${file.zoteroOpenURI})\t|\t[${file.fileName}](file.path)`; else return `[[Locate]](${file.zoteroSelectURI})\t|\t[${file.fileName}](file.path)`;}).join("\n")}}
<% } %>
Note: All variables return strings and will not directly return null
. Therefore, please use .length
to check if a variable exists.
In version v0.0.8, the literature note now supports a user data section, indicated by a top-level heading named "User Data" by default (this allows the floating preview in Obsidian to directly preview all user data). The content after this heading will not be updated with citations, but it also imposes some formatting requirements on the literature note. The format of an individual literature note document is as follows:
((User Data Title ID 'User Data Title'))
Template-generated content
# User Data Title (default: "User Data")
User data content
# User Data Title
(including the content of this heading) can be modified and will not be updated with citations.# User Data Title
, including the top-most citation, will be updated with citations, so please do not modify it.# User Data Title
heading itself!! If you only clear its content, the block ID will not change. However, if you delete this heading and create a new one, the block ID will change, and all user data below it will be cleared in the next citation update!!!If you use Zotero:
Use the Better BibTeX plugin to export your library in the format of Better BibLaTex or Better CSL JSON (select "Keep Update" to apply changes made to Zotero entries in SiYuan in real-time).
If you use other reference management software:
The sample.bib
and sample.json
files in [Workspace]/data/siyuan-plugin-citation/sample-data/
are provided for reference. If your software can provide exports in these formats, you can use them.
Note: In the .bib and .json files, each literature's citekey/id must be unique.
The citation link template will be fully customized, meaning that the template will no longer generate anchor text, but will be directly inserted into the document. In this case, to avoid affecting your own content, the refresh citation feature of the plugin will not maintain the non-link parts (outside the double brackets).
The regular expression for finding citation links is /\(\((.*?)\\"(.*?)\\"\)\)/g. Please make sure your template format conforms to this expression.
⚠️Note: After enabling the switch, please make sure your template includes ...(({{citeFileID}} "..."))...
, otherwise the generated links will not be able to reference the literature note.
This plugin strongly recommends using static anchor text for citation links (meaning the anchor text is enclosed in double quotes within the link and is not updated when the referenced document's name changes). This approach is not only more stable but also allows for the possibility of adding parameters to the citation links in future updates, allowing for different link formats (similar to \citep and \citet in LaTeX).
If dynamic anchor text for citation links is used, the document ID of the literature content will be temporarily displayed after referencing. The content will only appear after refreshing with F5
.
Clicking the "Delete Data" button will delete all the data saved in the settings panel and restore it to the initial values set by the plugin author.
Note: This feature does not delete the .bib and .json files!
Please check if the notebook option in the settings panel is blank. The library must be located in an open notebook, otherwise, the plugin will not work. If the notebook where the library is located is closed, you need to reselect the notebook and path for the library.
Please check if the library document exists. To prevent users from unintentionally disrupting their document hierarchy, the plugin does not automatically create a document in the document tree. When the library document does not exist, the plugin's functionality cannot be used.
After creating the document, you need to reload the database. Although it is not necessary, it is highly recommended restarting the SiYuan to ensure the effectiveness of setting.
Please check the status of your Zotero/Juris-M and ensure that you have installed the Better BibTeX plugin in Zotero/Juris-M. This plugin relies on the Better BibTeX plugin to run. There are plans to directly access zotero.sqlite without relying on this plugin in the future.
It is welcomed to raise an issue
This plugin exposes specific events for external calls. Here's how you can utilize them:
Get the eventBus
object of this plugin under window.siyuan.ws.app.plugins
window.siyuan.ws.app.plugins.find(p => p.name === "siyuan-plugin-citation").eventBus
Use eventBus.emit(rule: TRuleType, e: CustomEventDetail)
to send requests
type TRuleType = "GetFromPool" | "Refresh";
interface RefreshEventDetail extends CustomEventDetail {
type: "database" | "literature note";
docIDs?: string[];
keys?: string[];
refreshAll?: boolean;
confirmUserData?: boolean;
}
interface GetEventDetail extends CustomEventDetail {
keyorid: string;
triggerFn: (idorkey: string) => any;
}
GetFromPool
rule, the parameter e
has a type of GetEventDetail
.Refresh
rule, the parameter e
has a type of RefreshEventDetail
. Use the type
to choose whether to reload the database or refresh literature content. Set confirmUserData
to false
to avoid displaying the "User data not found" prompt.The code of the following projects was referenced, and I would like to express my gratitude:
Thanks to everyone in the "思源笔记折腾群" for answering my questions and providing guidance.
Thanks to Geo123abc and ttChen for providing information, suggestions, and testing support.
I actually prefer GitHub issues over sponsorship. Every question and request you raise there becomes my motivation.