////////////////////////////////////////// // //MathSciNetの検索結果のBibTeXからの貼り付けマクロ //Abe Noriyuki //http://www.ms.u-tokyo.ac.jp/~abenori/ // // ・AMSであるかのチェック // ・すでに登録してないかのチェック // をした後,ファイル最後に貼り付けとMathSciNetへのURL, // 及びタイトルをもじったPDFファイル名を挿入する. /////////////////////////////////////////// $searchbuf = searchbuffer;#searchopt = searchoption; begingroupundo; gofileend; ##line = lineno; paste;gofileend; if(lineno - ##line < 10){ question "本当にそれAMSのBibTeX?"; if(result == no){endgroupundo;undo;endmacro;} } insert "\n"; ##origx = x;##origy = y; searchup "@(ARTICLE|INPROCEEDINGS|INCOLLECTION|BOOK) *\\{",regular,nocasesense; moveto foundendx,foundendy; ##x = x;##y = y; searchdown ","; $$label = gettext(##x,##y,x,y); moveto ##origx,##origy; searchup "}"; left; ##lx = x;##ly = y; $$url = "http://www.ams.org/mathscinet-getitem?mr=" + $$label; gofiletop; searchdown $$url; if(result){ ##x = x;##y = y; endgroupundo; undo; message "どうやら君は既にそれを登録しているようだ."; setsearch $searchbuf,#searchopt; moveto ##x,##y; endmacro; } moveto ##lx,##ly; insert "url = {http://www.ams.org/mathscinet-getitem?mr=" + $$label + "},\n"; ##lx = x;##ly = y; moveto ##x,##y; searchdown "[^a-zA-Z]title[ \\t]*=[ \\t]*\\{",nocasesense,regular; if(!result){ message "titleが見つかりませんでした."; setsearch $searchbuf,#searchopt; endgroupundo; undo; endmacro; } moveto foundendx,foundendy; ##tbx = x;##tby = y; searchdown "},"; escape; $$titleorig = gettext(##tbx,##tby,x,y); $$title = ""; ##i = 0;##len = strlen($$titleorig); ##sp = false; while(##i < ##len){ if(midstr($$titleorig,##i,1) == " "){ if(!##sp)$$title = $$title + "_"; ##sp = true; }else if( midstr($$titleorig,##i,1) != "," && midstr($$titleorig,##i,1) != "{" && midstr($$titleorig,##i,1) != "}" && midstr($$titleorig,##i,1) != "\n" && midstr($$titleorig,##i,1) != "\r" ){ $$title = $$title + midstr($$titleorig,##i,1); ##sp = false; } ##i = ##i + 1; } moveto ##lx,##ly; insert "pdf = {" + $$title + ".pdf},\n"; setsearch $searchbuf,#searchopt; endgroupundo; endmacro;