From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id SIJHDPl5oGPF2QAAbAwnHQ (envelope-from ) for ; Mon, 19 Dec 2022 15:49:29 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id EC06C/l5oGP/AQAAG6o9tA (envelope-from ) for ; Mon, 19 Dec 2022 15:49:29 +0100 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 C575E36A7 for ; Mon, 19 Dec 2022 15:49:28 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7HRh-0001ur-0D; Mon, 19 Dec 2022 09:48:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7HRf-0001uf-2F for emacs-orgmode@gnu.org; Mon, 19 Dec 2022 09:48:47 -0500 Received: from mailer-211-161.hitrost.net ([91.185.211.161]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7HRc-0004PH-Qn for emacs-orgmode@gnu.org; Mon, 19 Dec 2022 09:48:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=christianmoe.com; s=x; h=Content-Type:MIME-Version:Message-ID:Date:Subject: To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=/sK1JPx6ufQuGWG8CC98rG9aqgTHgfQxetB3PadgPQQ=; b=A5LKGaSUFvkM0WhDw20fAfCFSQ io//BnC9/LHKvdfg/Q85HOTe0E/mL0+kXpdfwVpMI9p494C8cq1DCJfFMsWlvZBx5az9V5Xh1qB5G dhpUH8R1kI3RXoCpKU4i8eeR5VpZAK2BQP4N2loEA9n5zHYKEqZnPhf8buiWZ4Q4LpD3LvlmaS4mg gBPZsd9LIPdZxN06YC2AAvzXc7hh7gliRA2+EkTfBB69vVCrLxRnpVrb3G8nPaYaaqm44/W2/W8YH G32UJdUcb7hf9vE/ZWuoB5UDF+7zjcsEJT1JI0ZJjDd5G8KrbLvM58eV7c4al4G5nxLLMm+Ch0Tnf aLrEjdUA==; Received: from 84-20-244-215.dynamic.telemach.net ([84.20.244.215] helo=Tauriel) by b1.hitrost.net with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1p7HRW-005QD4-2E; Mon, 19 Dec 2022 15:48:38 +0100 User-agent: mu4e 1.2.0; emacs 27.2 From: Christian Moe To: "emacs-orgmode@gnu.org" Subject: Org-cite (oc-csl) tip: Filtering bibliography for language Date: Mon, 19 Dec 2022 15:48:37 +0100 Message-ID: <87k02njvp6.fsf@christianmoe.com> MIME-Version: 1.0 Content-Type: text/plain X-GeoIP: Country [IP], SI [84.20.244.215] X-Antivirus-Scanner: Clean mail though you should still use an Antivirus X-Authenticated-Id: mail@christianmoe.com Received-SPF: pass client-ip=91.185.211.161; envelope-from=mail@christianmoe.com; helo=mailer-211-161.hitrost.net X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none ("invalid DKIM record") header.d=christianmoe.com header.s=x header.b=A5LKGaSU; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1671461368; a=rsa-sha256; cv=none; b=nGG8eXLmn6CLgl3KhzJ8r4v8l4HJHh2kFsRtNZwyvc9ae4EO6nQpMfftqbvd4haC+WEE+k rp3ok/Kqvb85MDwUT/O6X4HRhQmH3m+4fD7q932AtJnI+vQfJt4XACJWv6SNTD2FS4Ac1p kHQAKiSZ+Nw5QtRlDwa5lA+Y2Fn67yoOTuiaguQCUo/QYezjU1KhQoEsT0Pw9UyoAJzrl3 gVnnhOSN3Dsni1ejq+20VVmgyuLvrzmwPJmn2qD1svPLPQdPdng7w/0zm/xrPdYhPXrwVq 7nkd4fa+4/xQNQXaUoVLkgtaviRwxaASloXFbzIprnrCLI9Ghq00bSHyfIjKQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1671461368; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=/sK1JPx6ufQuGWG8CC98rG9aqgTHgfQxetB3PadgPQQ=; b=TXmXuV8ITF82JZdkeWBsDQN8e5RYaOsEknb/ay12NrlNhR5Llv9JRzhB3hABbcyZCTcq/f SJzjJvbJYE9954YZenV07c2ev9cT9LfiXH5SHoB1kYrFFuuTlX53EJ608XnwyQOtYZFSbi O9k4f7MjLLai1Te53gMMENb6AjqNhq+Fp3laxPesx7g8JPI+IJT3yTmN+sqdLbyLvSiJv1 Ds93SE8zLM0zCGC8ypZ0dp4cCml9OcfVNy/lqKe8RL9RTiIfr4/JQHo+Ya+99XhCVzRTVZ s7vgCgYNjmpOmz5Y/KKVWjRAicYzcPOxFu6FNGXiNkk2AmaNVicGhaDDKzAVKw== Authentication-Results: aspmx1.migadu.com; dkim=none ("invalid DKIM record") header.d=christianmoe.com header.s=x header.b=A5LKGaSU; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: -2.79 X-Spam-Score: -2.79 X-Migadu-Queue-Id: C575E36A7 X-TUID: aIrTvD5zooCa Hi, A tip some of you might find useful: I wanted to separate sub-bibliographies by language, which is not one of the out-of-the-box available properties of the PRINT_BIBLIOGRAPHY keyword.[fn:1] Specifically, I wanted to filter out Norwegian items into one subbibliography and non-Norwegian ones into another in the same document.[fn:2] I found out how to do it with the `PRINT_BIBLIOGRAPHY: :filter ' property, which turns out to be used in the function citeproc-sb--match-p, where it is applied to a var-value list. I defined a predicate for Norwegian, bibitem-norwegian-p, that matches a regexp for various labels for Norwegian[fn:3] against the language value. #+begin_src elisp (defun bibitem-norwegian-p (vv) "Returns non-nil (0) if a bibliography item is in Norwegian. For use in an org-cite PRINT_BIBLIOGRAPHY filter." (let ((itemlang (alist-get 'language vv))) (and itemlang (string-match "n[obn][r-bo]?" itemlang)))) #+end_src Then I could successfully use it as follows: #+PRINT_BIBLIOGRAPHY: :filter bibitem-norwegian-p For the list of non-Norwegian items I just needed to define a complementary function: #+begin_src elisp (defun bibitem-not-norwegian-p (vv) (not (bibitem-norwegian-p vv))) #+begin_src elisp #+PRINT_BIBLIOGRAPHY: :filter bibitem-not-norwegian-p Adapt as needed for other languages and use cases. Refinements welcome. I'm especially wondering what would be an elegant way to generalize this for more languages without defining a predicate for each language (given that we cannot pass the language as an additional argument in the print_bibliography line). * Footnotes [fn:1] [[info:org#Bibliography options in the ``biblatex'' and ``csl'' export processors]] [fn:2] For this to work at all, of course, your CSL JSON or BibTeX has to contain language information on the items; it should, or English formatting such as title-casing might be applied inappropriately to non-English items by some styles. [fn:3] The regexp is complicated because Norwegian is complicated, my labeling is inconsistent and I want to match at least no, nb, nn, no-NO, nb-NO, nn-NO, nor, nob, nno, norsk and Norwegian ... Yours, Christian