2015年11月12日

次のソースをbbl.luaとでもして保存.

kpse.set_program_name("texlua")
if arg[1] == nil then
    print("no input")
    os.exit(1)
end

local file = arg[1]
if file:sub(-4,-1):lower() ~= ".bbl" then file = file .. ".bbl" end
file = kpse.find_file(file)
if file == nil then print("error: file not found") os.exit(1) end
local fp,msg = io.open(file,"r")
if fp == nil then print("error: " .. msg) os.exit(1) end
local buf = fp:read("*a")
fp:close()
buf = buf:gsub("\\bibitem%b[](%b{})","}\n\\footnotereference%1{")
buf = buf:gsub("\\bibitem(%b{})","}\n\\footnotereference%1{")
buf = buf:gsub("\\begin{thebibliography}%b{}[%s\n]*}","")
buf = buf:gsub("\\end{thebibliography}","}")
buf = buf:gsub("\n\n+","\n")

fp = io.open(file,"w")
fp:write(buf)
fp:close()

次のソースをsample.texとでもして保存.jpnbook.bibはTeX Wikiの文献データベースから.

\documentclass{jsarticle}
\makeatletter
\def\footnotereference#1#2{%
 \@namedef{footnote@reference@contents@#1}{#2}%
}
\def\@citex[#1]#2{\leavevmode
  \let\@citea\@empty
  \@for\@citeb:=#2\do
    {\@citea\def\@citea{,\penalty\@m\ }%
     \edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
     \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
     \@ifundefined{footnote@reference@contents@\@citeb}{\hbox{\reset@font\bfseries ?}%
       \G@refundefinedtrue
       \@latex@warning
         {Citation `\@citeb' on page \thepage \space undefined}}%
       {\footnote{\@nameuse{footnote@reference@contents@\@citeb}\if@tempswa , #1.\fi}}}}
\AtBeginDocument{\InputIfFileExists{\jobname.bbl}{}{}}
\makeatother
\begin{document}
\TeX ブック\cite{jtexbook}はなかなか買えない.
Lamport本\cite{jlatexbook}も買いにくくなってきている.

\bibliography{jpnbook}
\bibliographystyle{jplain}
\end{document}

次を実行.

> platex sample.tex
> pbibtex sample
> texlua bbl.lua sample
> platex sample
> dvipdfmx sample.dvi

こんなんができる.

4 件のコメント:

kmaeda さんのコメント...

例えば,LuaTeX-ja & biblatex-chicago でこんな感じです(なぜか uplatex だとうまくいかない……).

\documentclass{ltjsarticle}
\usepackage[authordate,backend=biber]{biblatex-chicago}
\addbibresource{jpnbook.bib}
\begin{document}
\TeX ブック\footcite{jtexbook}はなかなか買えない.
Lamport本\footcite{jlatexbook}も買いにくくなってきている.
\printbibliography
\end{document}

bibtex の代わりに biber を使います.
これを和文雑誌毎の細かい引用形式の違いにも全部対応できるようにしたい,というのが要望です.
どこまで対応できればよいのかは私にもまだよく把握できていないです.

具体的な論文の例は,例えば
http://repository.kulib.kyoto-u.ac.jp/dspace/handle/2433/56966
にあります.

abenori さんのコメント...

ありがとうございます.あまり脚注に出るかは関係ない気もしてきました..bstがすでにあるならばちょっと手を加えればできそうだし,ないならばどうせ何かで書式を書くという苦しみをやらないとならなそう…….

もちろんこんなんはできるわけだけど
\documentclass{jsarticle}
\usepackage{chicago}
\makeatletter
\def\cite{\def\@citeseppen{-1000}%
\def\@cite##1##2{\footnote{##1\if@tempswa , ##2\fi}}%
\def\citeauthoryear##1##2##3{##1 ##3}\@internalcite}
\makeatother

\begin{document}
\TeX ブック\cite{jtexbook}はなかなか買えない.
Lamport本\cite{jlatexbook}も買いにくくなってきている.
\bibliography{jpnbook}
\bibliographystyle{chicago}
\end{document}

> (なぜか uplatex だとうまくいかない……)
\usepackage[authordate,backend=biber,bibencoding=utf8,texencoding=utf8]{biblatex-chicago}
とencodingを指定したらとりあえずuplatexでもコンパイルできました.

kmaeda さんのコメント...

> あまり脚注に出るかは関係ない気もしてきました.
そうですね.biblatex でベースはできているので,あとは細かいカスタマイズができるかの問題みたいです.
bibtex だと,jurabib.sty というのがあるのですが,まだ未調査です.

> encodingを指定したらとりあえずuplatexでもコンパイルできました.
ありがとうございます.できました.デフォルト utf8 じゃないかと思っていたのですが,違うのか.
自動判別でもするのかな.

abenori さんのコメント...

既存のスタイルがないとなると大変そうです.

> デフォルト utf8 じゃないかと思っていたのですが,違うのか.自動判別でもするのかな.
違うみたいですね.以前同じようにはまったのですが ( http://d.hatena.ne.jp/abenori/20120610 ) とりあえず上で動いちゃったのでその後調べていないです.biberのマニュアルにはTeXエンジンによると書いてありますね.