「Zotero」の版間の差分
Notion-MW |
Notion-MW |
||
(同じ利用者による、間の9版が非表示) | |||
25行目: | 25行目: | ||
本来はこんな言語依存の単一文字列ではなく年、月、日それぞれ明示的に別のデータとして管理するのが筋だろう。実際、この仕様のせいで、Better BibTeXの使用時に問題が発生していた(後述)。 | 本来はこんな言語依存の単一文字列ではなく年、月、日それぞれ明示的に別のデータとして管理するのが筋だろう。実際、この仕様のせいで、Better BibTeXの使用時に問題が発生していた(後述)。 | ||
<span id="better-bibtex-for-zotero | <span id="better-bibtex-for-zotero"></span> | ||
== [https://retorque.re/zotero-better-bibtex/ <strong>Better BibTeX for Zotero</strong>] == | == [https://retorque.re/zotero-better-bibtex/ <strong>Better BibTeX for Zotero</strong>] == | ||
42行目: | 42行目: | ||
参考文献には出版年を書く必要があり、BibTeXではyearというフィールドに書かれる。このデータはZoteroの文献情報のdateのところから取得されており、「April 22, 2011」「2011-04-22」のようなdateのデータからは正しく「2011」だけを抽出してくれるが、dateが前述の「4月 22 , 2011」のような書式になっていた場合はうまくいかず、この文字列全てがBibTeX(.bib)に出力されてしまう(報告済み: [https://github.com/retorquere/zotero-better-bibtex/issues/2449 [Bug]: Japanese date format is not parsed correctly · Issue #2449 · retorquere/zotero-better-bibtex]、6.7.61あたりで修正済み)。←の通り、Better BibTeXのエクスポート時に適用されるscript(Export → postscript)のところにデータを置換するための以下のようなコードを書いておくとよい。 | 参考文献には出版年を書く必要があり、BibTeXではyearというフィールドに書かれる。このデータはZoteroの文献情報のdateのところから取得されており、「April 22, 2011」「2011-04-22」のようなdateのデータからは正しく「2011」だけを抽出してくれるが、dateが前述の「4月 22 , 2011」のような書式になっていた場合はうまくいかず、この文字列全てがBibTeX(.bib)に出力されてしまう(報告済み: [https://github.com/retorquere/zotero-better-bibtex/issues/2449 [Bug]: Japanese date format is not parsed correctly · Issue #2449 · retorquere/zotero-better-bibtex]、6.7.61あたりで修正済み)。←の通り、Better BibTeXのエクスポート時に適用されるscript(Export → postscript)のところにデータを置換するための以下のようなコードを書いておくとよい。 | ||
< | <syntaxhighlight lang="vb.net">if (tex.has.year) { | ||
tex.add({name: 'year', replace: true, value: tex.has.year.value.replace(/.* /, '')}) | tex.add({name: 'year', replace: true, value: tex.has.year.value.replace(/.* /, '')}) | ||
}</ | }</syntaxhighlight> | ||
設定箇所はこんな感じ↓ | 設定箇所はこんな感じ↓ | ||
<div class="res-img"> | <div class="res-img">https://turgenev.cloudfree.jp/mw1/imgs/zot-settings.jpg</div> | ||
* 今は治っているかもしれないが、デバッグ出力を有効化して再起動してからスクリプトを一度編集しないとスクリプトが読み込まれないバグがあった([https://github.com/retorquere/zotero-better-bibtex/issues/2447 https://github.com/retorquere/zotero-better-bibtex/issues/2447])。 | * 今は治っているかもしれないが、デバッグ出力を有効化して再起動してからスクリプトを一度編集しないとスクリプトが読み込まれないバグがあった([https://github.com/retorquere/zotero-better-bibtex/issues/2447 https://github.com/retorquere/zotero-better-bibtex/issues/2447])。 | ||
58行目: | 58行目: | ||
ZoteroはGUIのソフトであるが、コマンドラインからも一定の操作が可能である。具体的には、<code>zotero://</code>という形式のURL(URIスキーム)を以下のように指定してZoteroを起動することができる(既に起動していた場合は、画面に変化が起こる)。 | ZoteroはGUIのソフトであるが、コマンドラインからも一定の操作が可能である。具体的には、<code>zotero://</code>という形式のURL(URIスキーム)を以下のように指定してZoteroを起動することができる(既に起動していた場合は、画面に変化が起こる)。 | ||
< | <syntaxhighlight lang="python">zotero.exe -url "zotero://url/here"</syntaxhighlight> | ||
URLについては、明確にAPIとして仕様が定められたものではなさそうで、全体的にあまりドキュメントは充実していない。 | URLについては、明確にAPIとして仕様が定められたものではなさそうで、全体的にあまりドキュメントは充実していない。 | ||
74行目: | 74行目: | ||
コード例: | コード例: | ||
< | <syntaxhighlight style="margin-bottom:0.2em;" lang="python">import sqlite3 | ||
import sys | import sys | ||
import json | import json | ||
import subprocess | import subprocess | ||
db = sqlite3.connect('file:'+sys.argv[1]+'?mode=ro& | db = sqlite3.connect('file:'+sys.argv[1]+'?mode=ro&nolock=1', uri=True) | ||
cur = db.cursor() | cur = db.cursor() | ||
cur.execute('SELECT data FROM | cur.execute('SELECT data FROM "better-bibtex" where name="better-bibtex.citekey"') | ||
d = json.loads(cur.fetchone()[0]) | d = json.loads(cur.fetchone()[0]) | ||
mydict = {} | mydict = {} | ||
for item in d[ | for item in d["data"]: | ||
mydict[item[ | mydict[item["citekey"]] = item["itemKey"] | ||
myKey = mydict[sys.argv[3]] | myKey = mydict[sys.argv[3]] | ||
db2 = sqlite3.connect('file:'+sys.argv[2]+'?mode=ro& | db2 = sqlite3.connect('file:'+sys.argv[2]+'?mode=ro&nolock=1', uri=True) | ||
cur2 = db2.cursor() | cur2 = db2.cursor() | ||
cur2.execute( | cur2.execute("SELECT itemID FROM items WHERE key=?", (myKey, )) | ||
item_id = cur2.fetchone()[0] | item_id = cur2.fetchone()[0] | ||
cur2.execute( | cur2.execute("SELECT collectionID FROM collectionItems WHERE itemID=?", (item_id, )) | ||
# 所属する最初のコレクションIDを取得 | # 所属する最初のコレクションIDを取得 | ||
collection_id = cur2.fetchone()[0] | collection_id = cur2.fetchone()[0] | ||
# collectionIDからcollectionKeyを取得 | # collectionIDからcollectionKeyを取得 | ||
cur2.execute( | cur2.execute("SELECT key FROM collections WHERE collectionID=?", (collection_id,)) | ||
collection_key =cur2.fetchone()[0] | collection_key =cur2.fetchone()[0] | ||
print(collection_key) | print(collection_key) | ||
subprocess.run(f' | subprocess.run(f'"C:\Program Files (x86)\Zotero\zotero.exe" -url "zotero://select/library/collections/{collection_key}/items/{myKey}') | ||
db.close() | db.close() | ||
db2.close()</ | db2.close()</syntaxhighlight> | ||
<div style='text-align: center;'>zoto.py</div> | <div style='text-align: center;'>zoto.py</div> | ||
上記コードは以下のように起動できる。 | 上記コードは以下のように起動できる。 | ||
< | <syntaxhighlight lang="c#">python "path\to\zoto.py" "%USERPROFILE%\Zotero\better-bibtex.sqlite" "%USERPROFILE%\Zotero\zotero.sqlite" %1</syntaxhighlight> | ||
* [[Windowsのクリップボードを用いた選択コンテンツの取得|Windowsのクリップボードを用いた選択コンテンツの取得]]と組み合わせれば、選択文字列をCitation keyとするアイテムを一発で開くことも可能。 | * [[Windowsのクリップボードを用いた選択コンテンツの取得|Windowsのクリップボードを用いた選択コンテンツの取得]]と組み合わせれば、選択文字列をCitation keyとするアイテムを一発で開くことも可能。 | ||