0

Is it possible to pass a sample bibtex document into a python source code block to be evaluated?

:PROPERTIES:
:ID:       d7154890-6d45-44c0-9b0c-9c0f6533c11e
:header-args: :session bibtex
:END:

#+NAME: sample_bib
#+BEGIN_SRC bibtex
@book{崔光宙_先秦儒家禮樂敎化思想在現代敎育上的涵義與實施_1985,
  title = {先秦儒家禮樂敎化思想在現代敎育上的涵義與實施},
  author = {{崔光宙}},
  date = {1985},
  series = {私立東吳大學中國學術著作獎助委員會叢書},
  edition = {初版},
  number = {94},
  publisher = {{私立東吳大學中國學術著作獎助委員會}},
  location = {{台北市}},
  langid = {chi}
}

@article{李平_中國古代樂論的易學淵源_1996,
  title = {中國古代樂論的《易》學淵源},
  author = {{李平}},
  date = {1996},
  journaltitle = {音樂藝術.上海音樂學院學報},
  number = {01},
  pages = {11-16+27},
  issn = {1000-4270},
  url = {https://kns.cnki.net/kcms/detail/detail.aspx?dbcode=CJFD&dbname=CJFD9697&filename=SHYB199601002&v=IRe2C4LIBXc2dm%25mmd2FCtYiLuYcL8BGh6BOP9B5FiG59mEXb4llLOFZuq17u9CBg6yGt},
  urldate = {2021-07-26},
  langid = {中文;},
  keywords = {《乐论》,《周易》,《易》,《易》学,十二律,吕氏春秋,天地万物,音乐本体}
#+END_SRC



#+BEGIN_SRC python :results output :noweb yes
import bibtexparser
from bibtexparser.bwriter import BibTexWriter
from bibtexparser.bibdatabase import BibDatabase

with open(<<sample_bib>>) as bibtex_file:
    bibtex_str = bibtex_file.read()

    db = bibtexparser.loads(bibtex_str)

print(db)
#+END_SRC

#+RESULTS:

The python source block above returns no results. And there is No org-babel-execute function for bibtex`.

1

You can make a simple bibtex execute function like this:

#+BEGIN_SRC emacs-lisp
(defun org-babel-execute:bibtex (body params)
  body)
#+END_SRC

Then use a variable instead of noweb like this:

#+BEGIN_SRC python :results output :var bibdata=sample_bib
import bibtexparser
from bibtexparser.bwriter import BibTexWriter
from bibtexparser.bibdatabase import BibDatabase

db = bibtexparser.loads(bibdata)

print(db)
#+END_SRC

#+RESULTS:
: <bibtexparser.bibdatabase.BibDatabase object at 0x7f87201f8910>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.