From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id SH5mAMECDGDUagAA0tVLHw (envelope-from ) for ; Sat, 23 Jan 2021 11:04:33 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id OOnON8ACDGCMWAAAbx9fmQ (envelope-from ) for ; Sat, 23 Jan 2021 11:04:32 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id ED284940418 for ; Sat, 23 Jan 2021 11:04:31 +0000 (UTC) Received: from localhost ([::1]:54980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l3GiU-0004JL-A6 for larch@yhetil.org; Sat, 23 Jan 2021 06:04:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l3GhO-0004G8-Nq for emacs-orgmode@gnu.org; Sat, 23 Jan 2021 06:03:23 -0500 Received: from mout01.posteo.de ([185.67.36.65]:46909) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l3GhM-00040G-4w for emacs-orgmode@gnu.org; Sat, 23 Jan 2021 06:03:22 -0500 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id B6EE5160063 for ; Sat, 23 Jan 2021 12:03:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1611399796; bh=dbjFy/c6S8fgyls8P5BGOlPLmrPkQkd4YkpQ/N9q0mU=; h=From:To:Subject:Date:From; b=h6G/kN26Czx4bLv7fNXFWaiLyIpnLpNEz866dzz4/4GPDYM5QUobdse0iX0d6boHO J8QH14X20gERiP07QhmXB+oJ38ZgquSaJJ2bBmwTcffGyYNrqHysd9f/7YEzl1R4g/ jpDLRETYPTnUaHV8LVc/XyPe9CRSEXj9fIh2wETX/C1+kgaGXFhmwfVikJUh/49Nip jQffyh15qE5eRg7fH4WpRhVtFfCnBu495Hsj8wN52TPXeFAh4lLvjvQRJ3RKocWdps MJzHmjdrevT+jxK4W4Hp2VL5SJdT5Z67O5oiSUwjL33/24bYcoeaWdBtDh+2jpnl6R GxtYeg+5hL6Mg== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4DNCsb6k6cz6tmP for ; Sat, 23 Jan 2021 12:03:15 +0100 (CET) From: =?utf-8?Q?Juan_Manuel_Mac=C3=ADas?= To: orgmode Subject: [Tip] Export a bibliography to HTML with bibLaTeX and make4ht Date: Sat, 23 Jan 2021 12:03:14 +0100 Message-ID: <87wnw3oqz1.fsf@posteo.net> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.65; envelope-from=maciaschain@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -2.05 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b="h6G/kN26"; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: ED284940418 X-Spam-Score: -2.05 X-Migadu-Scanner: scn0.migadu.com X-TUID: ae/yknjndXOW --=-=-= Content-Type: text/plain 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[]{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: ,#+HTML_HEAD: ,* 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 --=-=-= Content-Type: text/html --=-=-=--