bib.yml
に参考文献情報を記載する- カスタムインライン命令
@<bibinfo>{id}
で参考文献情報を展開できるようにする。review-ext.rb
は認識される場所に配置してください。 ruby generate-bib-re.rb bib.yml bib.re
などとしてbib.yml
からbib.re
を生成する
Last active
July 22, 2024 14:58
-
-
Save j5ik2o/33ee4846c31472033cd2d166ff9dc9af to your computer and use it in GitHub Desktop.
Re:VIEWにて参考文献情報のためのインライン命令を追加する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /work/src/bib.yml | |
Evans: | |
type: book | |
title: "エリック・エヴァンスのドメイン駆動設計: ソフトウェアの核心にある複雑さに立ち向かう" | |
author: "エリック・エヴァンス" | |
translator: "今関 剛 (監修), 和智 右桂 (翻訳), 牧野 祐子 (翻訳)" | |
publisher: "翔泳社" | |
year: 2011 | |
isbn: "978-4798121963" | |
url: "https://www.amazon.co.jp/dp/B00GRKD6XU/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
def generate_bib_re(yml_path, re_path) | |
# YAMLファイルを読み込む | |
bib_data = YAML.safe_load(File.read(yml_path)) | |
# bib.reの内容を生成 | |
content = "= 参考文献\n\n" | |
bib_data.each do |id, info| | |
content << "//bibpaper[#{id}][#{info['title']}]{\n" | |
content << "著者: #{info['author']}\n" | |
content << "出版社(発刊年): #{info['publisher']}(#{info['year']})\n" | |
content << "URL: #{info['url']}\n" if info['url'] | |
content << "//}\n\n" | |
end | |
# bib.reファイルに書き込む | |
File.write(re_path, content) | |
end | |
# スクリプトが直接実行された場合のみ処理を実行 | |
if __FILE__ == $0 | |
yml_path = ARGV[0] || 'bib.yml' | |
re_path = ARGV[1] || 'bib.re' | |
generate_bib_re(yml_path, re_path) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /work/src/review-ext.rb | |
require 'review/extentions' | |
module ReVIEW | |
class Compiler | |
alias_method :original_initialize, :initialize | |
def initialize(*args) | |
original_initialize(*args) | |
$stderr.puts "Debug: Compiler initialized, registering bibinfo" | |
self.class.definline :bibinfo | |
end | |
def inline_bibinfo(*args) | |
begin | |
id = args.first | |
$stderr.puts "Debug: Compiler inline_bibinfo called with id: #{id}" | |
# Compilerでは処理を行わず、そのまま返す | |
id | |
rescue => e | |
$stderr.puts "Error in Compiler inline_bibinfo: #{e}" | |
'\\textbf{書籍情報の取得中にエラーが発生しました}' | |
end | |
end | |
end | |
class LATEXBuilder | |
def inline_bibinfo(*args) | |
begin | |
id = args.first | |
$stderr.puts "Debug: LATEXBuilder inline_bibinfo called with id: #{id}" | |
# ここで実際の処理を行う | |
bib_content = File.read(File.join(@book.basedir, 'bib.yml')) | |
bib_data = YAML.safe_load(bib_content) | |
bibinfo = bib_data[id] | |
title = bibinfo['title'] | |
author = bibinfo['author'] | |
publisher = bibinfo['publisher'] | |
year = bibinfo['year'] | |
title = escape_latex('『' + title + '』') | |
author = escape_latex("著者: " + author) | |
publisher = escape_latex("出版社(発刊年): " + publisher) | |
<<-EOS | |
\\begin{itemize} | |
\\item \\textnormal{#{title}} | |
\\begin{itemize} | |
\\item #{author} | |
\\item #{publisher}(#{year}) | |
\\end{itemize} | |
\\end{itemize} | |
EOS | |
rescue => e | |
$stderr.puts "Error in LATEXBuilder inline_bibinfo: #{e}" | |
'\\textbf{書籍情報の処理中にエラーが発生しました}' | |
end | |
end | |
def escape_latex(text) | |
text.to_s.gsub(/([#$%&_{}~^\\])/, '\\\\\\1') | |
end | |
end | |
end | |
$stderr.puts "Debug: review-ext.rb loaded" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment