Notion-MW
 
Notion-MW
 
(同じ利用者による、間の9版が非表示)
25行目: 25行目:
本来はこんな言語依存の単一文字列ではなく年、月、日それぞれ明示的に別のデータとして管理するのが筋だろう。実際、この仕様のせいで、Better BibTeXの使用時に問題が発生していた(後述)。
本来はこんな言語依存の単一文字列ではなく年、月、日それぞれ明示的に別のデータとして管理するのが筋だろう。実際、この仕様のせいで、Better BibTeXの使用時に問題が発生していた(後述)。


<span id="better-bibtex-for-zotero-m_linksep_m"></span>
<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&#45;04&#45;22」のようなdateのデータからは正しく「2011」だけを抽出してくれるが、dateが前述の「4月 22 , 2011」のような書式になっていた場合はうまくいかず、この文字列全てがBibTeX(.bib)に出力されてしまう(報告済み&#58; [https://github.com/retorquere/zotero-better-bibtex/issues/2449 &#91;Bug&#93;&#58; Japanese date format is not parsed correctly · Issue &#35;2449 · retorquere/zotero&#45;better&#45;bibtex]、6.7.61あたりで修正済み)。←の通り、Better BibTeXのエクスポート時に適用されるscript(Export → postscript)のところにデータを置換するための以下のようなコードを書いておくとよい。
参考文献には出版年を書く必要があり、BibTeXではyearというフィールドに書かれる。このデータはZoteroの文献情報のdateのところから取得されており、「April 22, 2011」「2011&#45;04&#45;22」のようなdateのデータからは正しく「2011」だけを抽出してくれるが、dateが前述の「4月 22 , 2011」のような書式になっていた場合はうまくいかず、この文字列全てがBibTeX(.bib)に出力されてしまう(報告済み&#58; [https://github.com/retorquere/zotero-better-bibtex/issues/2449 &#91;Bug&#93;&#58; Japanese date format is not parsed correctly · Issue &#35;2449 · retorquere/zotero&#45;better&#45;bibtex]、6.7.61あたりで修正済み)。←の通り、Better BibTeXのエクスポート時に適用されるscript(Export → postscript)のところにデータを置換するための以下のようなコードを書いておくとよい。


<pre class="dummy_str_visual_basic">if (tex.has.year) {
<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(/.* /, '')})
}</pre>
}</syntaxhighlight>
設定箇所はこんな感じ↓
設定箇所はこんな感じ↓


<div class="res-img">[[File:9A6D0175-EBED-4707-9810-F7A249D73330.jpg]]</div>
<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&#58;//</code>という形式のURL(URIスキーム)を以下のように指定してZoteroを起動することができる(既に起動していた場合は、画面に変化が起こる)。
ZoteroはGUIのソフトであるが、コマンドラインからも一定の操作が可能である。具体的には、<code>zotero&#58;//</code>という形式のURL(URIスキーム)を以下のように指定してZoteroを起動することができる(既に起動していた場合は、画面に変化が起こる)。


<pre class="dummy_str_python">zotero.exe -url &quot;zotero://url/here&quot;</pre>
<syntaxhighlight lang="python">zotero.exe -url "zotero://url/here"</syntaxhighlight>
URLについては、明確にAPIとして仕様が定められたものではなさそうで、全体的にあまりドキュメントは充実していない。
URLについては、明確にAPIとして仕様が定められたものではなさそうで、全体的にあまりドキュメントは充実していない。


74行目: 74行目:
コード例&#58;
コード例&#58;


<pre style="margin-bottom:0.2em;" class="dummy_str_python">import sqlite3
<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&amp;nolock=1', uri=True)
db = sqlite3.connect('file:'+sys.argv[1]+'?mode=ro&nolock=1', uri=True)
cur = db.cursor()
cur = db.cursor()
cur.execute('SELECT data FROM &quot;better-bibtex&quot; where name=&quot;better-bibtex.citekey&quot;')
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[&quot;data&quot;]:
for item in d["data"]:
     mydict[item[&quot;citekey&quot;]] = item[&quot;itemKey&quot;]
     mydict[item["citekey"]] = item["itemKey"]
myKey = mydict[sys.argv[3]]
myKey = mydict[sys.argv[3]]


db2 = sqlite3.connect('file:'+sys.argv[2]+'?mode=ro&amp;nolock=1', uri=True)
db2 = sqlite3.connect('file:'+sys.argv[2]+'?mode=ro&nolock=1', uri=True)
cur2 = db2.cursor()
cur2 = db2.cursor()
cur2.execute(&quot;SELECT itemID FROM items WHERE key=?&quot;, (myKey, ))
cur2.execute("SELECT itemID FROM items WHERE key=?", (myKey, ))
item_id = cur2.fetchone()[0]
item_id = cur2.fetchone()[0]
cur2.execute(&quot;SELECT collectionID FROM collectionItems WHERE itemID=?&quot;, (item_id, ))
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(&quot;SELECT key FROM collections WHERE collectionID=?&quot;, (collection_id,))
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'&quot;C:\Program Files (x86)\Zotero\zotero.exe&quot; -url &quot;zotero://select/library/collections/{collection_key}/items/{myKey}')
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()</pre>
db2.close()</syntaxhighlight>
<div style='text-align: center;'>zoto.py</div>
<div style='text-align: center;'>zoto.py</div>


上記コードは以下のように起動できる。
上記コードは以下のように起動できる。


<pre class="dummy_str_c#">python &quot;path\to\zoto.py&quot; &quot;%USERPROFILE%\Zotero\better-bibtex.sqlite&quot; &quot;%USERPROFILE%\Zotero\zotero.sqlite&quot; %1</pre>
<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とするアイテムを一発で開くことも可能。