all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [Tip] Export a bibliography to HTML with bibLaTeX and make4ht
@ 2021-01-23 11:03 Juan Manuel Macías
  2021-01-24 11:37 ` Gustavo Barros
  0 siblings, 1 reply; 7+ messages in thread
From: Juan Manuel Macías @ 2021-01-23 11:03 UTC (permalink / raw)
  To: orgmode

[-- 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 --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-01-25 18:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-23 11:03 [Tip] Export a bibliography to HTML with bibLaTeX and make4ht Juan Manuel Macías
2021-01-24 11:37 ` 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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.