melat0nin/zotero-roam-export

Possible to have Citekey as heading?

roam-user opened this issue · 24 comments

Would it be possible to have the BetterBibTex citekey as the title of the output file, and the title of the reference as a separate title field?
I am using the citekey in the roam text, so that I can export the markdown file, let it run through pandoc, and have all the references properly formatted in the output PDF or Word file.

Do you mean have the citekey as the file name? This can be achieved manually by specifying it at the point of saving, although I appreciate that's a little unintuitive. It's probably simplest to implement the filename change using a Zotero preference -- obviously we don't want to enforce that as a default. I'll look into this.

Can you give me an example of how you'd like the fields to look?

Actually I think I've misunderstood what you're asking for. Is it something like this?

[
	{
		"title": "thisIsMyCiteKey2020",
		"children": [
			{
				"string": "Metadata",
				"heading": 3,
				"children": [
					{
						"string": "Title:: [[Title of Item]]"
					},
					{
						"string": "Author(s):: [[Autho R. One]], [[Autho R. Two]]"
					},
					{
						"string": "Topics:: [[MyTopic]]"
					},
					{
						"string": "Type:: [[Article]]"
					},
					{
						"string": "Date:: 2014"
					},
					{
						"string": "Date added:: [[May 11th, 2020]]"
					},
					{
						"string": "URL:: [url.com](url.com)"
					},
					{
						"string": "Tags:: #[[Tag1]], #[[Tag2]], #[[ZoteroImport]]"
					}
				]
			}
		],
		"edit-time": 1589209899
	}
]

(the crucial changed elements being title and "string": "Title:: [[Title of Item]]")

Yes, that's what I mean. The citekey as a filename. If a @ could be added in front of it, that would be even better, as it could then directly be used by Pandoc as a reference indicator.
I understand, not everyone wants it this way, but it would be nice if this was an option.
How can I do that manually when exporting.

How about double colons after Metadata and Notes as well. One can then search for only metadata or notes. Like this?

[
{
"title": "thisIsMyCiteKey2020",
"children": [
{
"string": "Metadata::",
"heading": 3,
"children": [
{
"string": "Title:: [[Title of Item]]"
},
{
"string": "Author(s):: [[Autho R. One]], [[Autho R. Two]]"
},
{
"string": "Topics:: [[MyTopic]]"
},
{
"string": "Type:: [[Article]]"
},
{
"string": "Date:: 2014"
},
{
"string": "Date added:: [[May 11th, 2020]]"
},
{
"string": "URL:: url.com"
},
{
"string": "Tags:: #[[Tag1]], #[[Tag2]], #[[ZoteroImport]]"
}
]
}
],
"edit-time": 1589209899
}
]

Yes, that's what I mean. The citekey as a filename. If a @ could be added in front of it, that would be even better, as it could then directly be used by Pandoc as a reference indicator.
I understand, not everyone wants it this way, but it would be nice if this was an option.
How can I do that manually when exporting.

When you select 'Export item(s) to Roam...' and the file picker appears, just type a new name (but make sure it still has .json on the end.

But that's not a full solution of course. I'll investigate adding preferences, which once done will make it easy enough to implement the citekey as filename as per the OP :)

How about double colons after Metadata and Notes as well. One can then search for only metadata or notes. Like this?

[
{
"title": "thisIsMyCiteKey2020",
"children": [
{
"string": "Metadata::",
"heading": 3,
"children": [
{
"string": "Title:: [[Title of Item]]"
},
{
"string": "Author(s):: [[Autho R. One]], [[Autho R. Two]]"
},
{
"string": "Topics:: [[MyTopic]]"
},
{
"string": "Type:: [[Article]]"
},
{
"string": "Date:: 2014"
},
{
"string": "Date added:: [[May 11th, 2020]]"
},
{
"string": "URL:: url.com"
},
{
"string": "Tags:: #[[Tag1]], #[[Tag2]], #[[ZoteroImport]]"
}
]
}
],
"edit-time": 1589209899
}
]

How about double colons after Metadata and Notes as well. One can then search for only metadata or notes. Like this?

[
{
"title": "thisIsMyCiteKey2020",
"children": [
{
"string": "Metadata::",
"heading": 3,
"children": [
{
"string": "Title:: [[Title of Item]]"
},
{
"string": "Author(s):: [[Autho R. One]], [[Autho R. Two]]"
},
{
"string": "Topics:: [[MyTopic]]"
},
{
"string": "Type:: [[Article]]"
},
{
"string": "Date:: 2014"
},
{
"string": "Date added:: [[May 11th, 2020]]"
},
{
"string": "URL:: url.com"
},
{
"string": "Tags:: #[[Tag1]], #[[Tag2]], #[[ZoteroImport]]"
}
]
}
],
"edit-time": 1589209899
}
]

I've opened this out into another issue (#8) to keep track of there. It's a good idea I think.

In tried to replace
235 roamItem.title = item.getField("title");
with
235. roamItem.title = item.getField("bbtCiteKey");

but it does not work. I wonder why?

BBT citekeys aren't part of the standard item metadata but are provided by Zotero.BetterBibtex -- see line 151 and the if statement it's part of:

var bbtItem = Zotero.BetterBibTeX.KeyManager.get(item.getField('id'));

A unique id in the record would be very useful so I can refer back to Zotero from Roam.
I was not aware of BetterBibtex until today, but I know that Zotfile retrieves the record's URI and is (I understand) a lighter plug-in compared to BetterBibtex.
I do not have a settled workflow in place atm so don't yet know what would be best but I think the record's URI would be very useful, even though it is not as meaningful as BetterBibtex's citekey.
Does that make sense?

BBT citekeys aren't part of the standard item metadata but are provided by Zotero.BetterBibtex -- see line 151 and the if statement it's part of:

var bbtItem = Zotero.BetterBibTeX.KeyManager.get(item.getField('id'));

I understand. I just thought once the the VAR bbtCiteKey has been defined, it could be used later to define roamItem.title.

Using the title might be useful for a few references, but they are not unique identifiers. A title like “Introduction” can only be used once. As an academic, using “@citekey” makes it useful when exporting Roam markdowns flies for further processing. And in Roam, I can see where I quoted what literature.

@richardlm

A unique id in the record would be very useful so I can refer back to Zotero from Roam.
I was not aware of BetterBibtex until today, but I know that Zotfile retrieves the record's URI and is (I understand) a lighter plug-in compared to BetterBibtex.
I do not have a settled workflow in place atm so don't yet know what would be best but I think the record's URI would be very useful, even though it is not as meaningful as BetterBibtex's citekey.
Does that make sense?

I don't think Zotfile and BBT have the same functionalitycan be said to have the same purpose. But ultimately it depends on what you mean by "refer", and what your desired workflow is.

One option might be to open the item in Zotero via a URL, just as the current PDF link does (except in this case focus on the item, not the attached file). This would only work on a machine that has it installed and has the relevant library, although another option could be to open the item in the online library. But again I'm not clear what the value of this would be without a clearly-defined workflow use-case.

BBT citekeys aren't part of the standard item metadata but are provided by Zotero.BetterBibtex -- see line 151 and the if statement it's part of:

var bbtItem = Zotero.BetterBibTeX.KeyManager.get(item.getField('id'));

I understand. I just thought once the the VAR bbtCiteKey has been defined, it could be used later to define roamItem.title.

Using the title might be useful for a few references, but they are not unique identifiers. A title like “Introduction” can only be used once. As an academic, using “@citekey” makes it useful when exporting Roam markdowns flies for further processing. And in Roam, I can see where I quoted what literature.

You're right, this can certainly be done (citekey as filename), but I won't make it a default until the preferences have been bootstrapped in order to make it an option. That will take a little more time. (my reply was just pointing out why what you were trying didn't work).

As with @richardlm's suggestion I'd be interested to see a description of the intended workflow -- I don't use BBT myself, but will likely start to soon as I work more with LaTeX, and I think more integration of citekeys will be useful. But I'm wary of straying too far from vanilla Zotero, since many (most?) users won't use BBT and won't rely on citekeys. Hence the need to wait for the preferences infrastructure to be set up.

Quick correction to my comment: I meant Zutilo rather than Zotfile.

As I've only just got access to Roam it's early days for establishing a solid workflow but it's a valid question so I'll get back to you when I've developed a good use case.

My workflow when writing in Roam (or any markdown file) is to cite with (@bbtcitekey) in the text. If the item name in Roam is @bbtcitekey I can then mark it ([[@bbtcitekey]]) and click on it to get back to the reference and all my notes in Roam. When exporting the file to a markdown or later Latex document, one can use Zettl which automatically takes the [[]] away and finds the proper reference in my BibTex file. The documents get properly formatted and the reference list is automatically produced. One can also run the document through Pandoc, with the same outcome. I would not know how to cite and reference without BBT and citekeys.
This way, all the writing can be done in Roam.

I understand not everyone might use citekeys. Any advice on how the roamexports.js could be altered to achieve this would be appreciated. I am not familiar with Javascript, but could integrate your code into the file and then make the .xpi file.

I also tried to insert the title with Title:: title under the author's name but was not successful. Is that difficult to do?

@richardlm
A unique id in the record would be very useful so I can refer back to Zotero from Roam.
I was not aware of BetterBibtex until today, but I know that Zotfile retrieves the record's URI and is (I understand) a lighter plug-in compared to BetterBibtex.
I do not have a settled workflow in place atm so don't yet know what would be best but I think the record's URI would be very useful, even though it is not as meaningful as BetterBibtex's citekey.
Does that make sense?

I don't think Zotfile and BBT have the same functionalitycan be said to have the same purpose. But ultimately it depends on what you mean by "refer", and what your desired workflow is.

One option might be to open the item in Zotero via a URL, just as the current PDF link does (except in this case focus on the item, not the attached file). This would only work on a machine that has it installed and has the relevant library, although another option could be to open the item in the online library. But again I'm not clear what the value of this would be without a clearly-defined workflow use-case.

Getting back to the reference in Zotero is easy by adding
zotero://select/items/bbt:citekey

Getting back to the reference in Zotero is easy by adding
zotero://select/items/bbt:citekey

It's not that it is difficult to use, I just do not need any of the other functionality of BBT (I don't use Latex). I already have Zutilo installed for its functions (e.g. copying tags between records, creating book sections) and it would be easy to use its 'Copy Zotero URI'. I'll have to think through my use cases - at the moment it is primarily being able to go between Roam and Zotero with single clicks.

My workflow when writing in Roam (or any markdown file) is to cite with (@bbtcitekey) in the text. If the item name in Roam is @bbtcitekey I can then mark it ([[@bbtcitekey]]) and click on it to get back to the reference and all my notes in Roam. When exporting the file to a markdown or later Latex document, one can use Zettl which automatically takes the [[]] away and finds the proper reference in my BibTex file. The documents get properly formatted and the reference list is automatically produced. One can also run the document through Pandoc, with the same outcome.

That's a great workflow!
Subscribing to this issue for developments..

Okay I've made a first stab at this, how does the following suit?

image

It works such that if BBT is installed and the option is enabled it'll use @{citekey} as the title of the Roam page, and add the title field beneath, as in the screenshot above. If either BBT isn't installed or the option isn't enabled it'll work as before.

That looks great! The only change I would suggest is to have the Title inside the Metadata block below Author(s).

That looks great! The only change I would suggest is to have the Title inside the Metadata block below Author(s).

No problem, I'll make that change and publish a new release later today.

Please test: https://github.com/melat0nin/zotero-roam-export/releases/tag/v1.6

Enable the new option by going to Edit menu > Preferences > Advanced > Config Editor then setting the extensions.roamexport.citekey_as_title option to true (just double-click it). You must of course have BBT installed for this to work.

It works! Thank you so much for making the changes so quickly!
This is an amazing tool that saves me a lot of time.

My workflow when writing in Roam (or any markdown file) is to cite with (@bbtcitekey) in the text. If the item name in Roam is @bbtcitekey I can then mark it ([[@bbtcitekey]]) and click on it to get back to the reference and all my notes in Roam. When exporting the file to a markdown or later Latex document, one can use Zettl which automatically takes the [[]] away and finds the proper reference in my BibTex file. The documents get properly formatted and the reference list is automatically produced. One can also run the document through Pandoc, with the same outcome. I would not know how to cite and reference without BBT and citekeys.
This way, all the writing can be done in Roam.

I understand not everyone might use citekeys. Any advice on how the roamexports.js could be altered to achieve this would be appreciated. I am not familiar with Javascript, but could integrate your code into the file and then make the .xpi file.

I also tried to insert the title with Title:: title under the author's name but was not successful. Is that difficult to do?

Hello @roam-user , do you mind sharing more detail on how you convert your Roam's markdown to latex/pdf? I'm just started using pandoc but the latex retain all the roam's bullet and [[ ]], while the pdf fail to generate.