From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: orgmode <emacs-orgmode@gnu.org>
Subject: [Tip] Export a bibliography to HTML with bibLaTeX and make4ht
Date: Sat, 23 Jan 2021 12:03:14 +0100 [thread overview]
Message-ID: <87wnw3oqz1.fsf@posteo.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 2693 bytes --]
Hi,
When I export to LaTeX an Org document that contains a bibliography, I
use bibLaTeX with a very custom style (i.e. quite a few lines of code
related to bibLaTeX in the preamble). I wanted to apply all that
bibLaTeX setting and styles when exporting to HTML too, so I came up
with this method, using make4ht. I share it here, in case it is useful
to someone.
The idea is to compile with make4ht (see:
https://www.ctan.org/pkg/make4ht) a simple file with *only* the
bibliography, and "embed" the HTML output in the Org document. You need
to create in the working directory a tex file, which will serve as a
minimal preamble and which also includes all code related to bibLaTeX.
We can name it preamble.tex, and it would start like this:
#+begin_src latex
\documentclass{article}
\usepackage{fontspec}
\usepackage[<whatever-language>]{babel}
\usepackage[backend=biber,style=authortitle,dashed=true,sorting=nyt]{biblatex}
%% more code related to bibLaTeX...
#+end_src
We also need a small lua file that will control the make4ht compilation.
If we run make4ht in draft mode it will not call Biber. This file can be
named build.lua:
#+begin_src lua
if mode=="draft" then
Make:htlatex {}
else
Make:htlatex {}
Make:biber {}
Make:htlatex {}
end
#+end_src
And finally, this function is defined in Elisp, which takes two
arguments: the preamble-file and the *.bib file to generate the list of
references. The optional draft argument is for make4ht to run in draft
mode (that is, so you don't rebuild the bibliography). In the end Pandoc
is executed with shell output to simplify the resulting HTML:
#+begin_src emacs-lisp
(defun my-biblio-html (preamble bib &optional draft)
(when (org-export-derived-backend-p org-export-current-backend 'html)
(let ((file (file-name-sans-extension bib))
(d (if draft
"-m draft "
"")))
(shell-command (concat
"echo \"\\input{"
preamble
"}"
"\\addbibresource{"
bib
"}"
"\\begin{document}
\\nocite{*}
\\printbibliography[heading=none]
\\end{document}\" > "
file "-bib.tex"))
(shell-command-to-string (concat "make4ht -ule build.lua "
d
file
"-bib.tex > /dev/null && "
"pandoc -f html -t html "
file
"-bib.html")))))
#+end_src
An example:
#+begin_src org
,#+HTML_HEAD: <style> dd { text-indent: -2em; margin-left: 2em; } </style>
,#+HTML_HEAD: <style> .rm-lmri-12{ font-style:italic;} </style>
,* References
,#+begin_src emacs-lisp :exports results :results html
(my-biblio-html "preamble.tex" "file.bib")
,#+end_src
#+end_src
As you can see, the method is somewhat tricky, but it works well, for now. I hope that
be useful!
Regards,
Juan Manuel
[-- Attachment #2: Type: text/html, Size: 0 bytes --]
next reply other threads:[~2021-01-23 11:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-23 11:03 Juan Manuel Macías [this message]
2021-01-24 11:37 ` [Tip] Export a bibliography to HTML with bibLaTeX and make4ht Gustavo Barros
2021-01-24 13:00 ` Gustavo Barros
2021-01-24 19:20 ` Juan Manuel Macías
2021-01-24 22:44 ` Gustavo Barros
2021-01-25 17:46 ` Juan Manuel Macías
2021-01-25 18:30 ` Gustavo Barros
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wnw3oqz1.fsf@posteo.net \
--to=maciaschain@posteo.net \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).