From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:1008:1e59::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id 0H+CDeYOW2YKggEAA41jLg (envelope-from ) for ; Sat, 01 Jun 2024 14:07:02 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id iMrqCOYOW2Y7JAEA62LTzQ (envelope-from ) for ; Sat, 01 Jun 2024 14:07:02 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=none; 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=1717243622; a=rsa-sha256; cv=none; b=CgP3tPzD1qBmYptIn4a76ap1bzEZ++5SO7Zp64kyYqlRgKPY6JPxxWmAwb80Qd38Ph3j3V Bbg6wm5Q8tTNMmxg3svsrTo8ibp/tZDHJYEWY/eJvb/p7Xe5/D8rUsHIFNhnh2VPLWO1mA PY4U14oQQmH5qkgp9H5FgW3ZaQN9MyPcI+XmdZFrzZtwmoq3W+3E38pZNbvHXbpyPiaeF8 w8tNgl7ny9QnVq1OzHDHWyOfQjoWy9wB1+U5CORSHM4ukxknAK+1vMGyAjWaExvFQlffyB 4QooZelb9Y95EFedg/CQavPYRpAB3jRLP2rXJGCLqayymQ+5mq3zH6QIUPI+Uw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; 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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1717243622; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ZeddbkubAAYbPL3SxZvKsrA7ixIJaIXfUMdzGxGZ3Y8=; b=RcOZb0MCleCKQUxXWp7JBNpIeqYWgW68YMxB/IM581Xi3mwbA2NVa9pp+IbvQ11JgK0mhl oK7pZ5Otou5Kq/OuxGrrQEWX63bJIJy2wHjmoXZCs1DIl2GbdoXLiOa+kVZvg98+77JMqY QmdIsHfNoPzy55oKiTGbNfXS38ROL8ptt9ox4GWgE3lsrupBsxEiHuMTrGJdCJFueddYRv 6EURWkjq98ZpiKMDQL4aJUivkhkEdQTBtc8w7mDPW4GZNBD8+20JNlImUrzfaRhPRlP+I3 vR5PGViHwp7ziw9OFI/EJok1TwVsDIah7yFM2u2RUQ/14gNWzd4qpHWePBssyQ== 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 C4E261384A for ; Sat, 1 Jun 2024 14:07:01 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sDNUv-0001DD-Ds; Sat, 01 Jun 2024 08:06:09 -0400 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 1sDNUr-0001CS-MC for emacs-orgmode@gnu.org; Sat, 01 Jun 2024 08:06:07 -0400 Received: from k-7.ch ([185.31.100.96]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sDNUp-0005jQ-O4 for emacs-orgmode@gnu.org; Sat, 01 Jun 2024 08:06:05 -0400 Received: from van (_gateway [192.168.1.1]) (Authenticated sender: seb) by k-7.ch (Postfix) with ESMTPSA id 75D3EE810E; Sat, 1 Jun 2024 14:06:00 +0200 (CEST) From: =?utf-8?Q?S=C3=A9bastien_Gendre?= To: Bruno Barbier Cc: emacs-orgmode Subject: Re: Using Org-mode macros as LaTeX macros In-Reply-To: <665acf87.050a0220.dc593.f236@mx.google.com> (Bruno Barbier's message of "Sat, 01 Jun 2024 09:36:37 +0200") References: <87v82tkyc2.fsf@k-7.ch> <665acf87.050a0220.dc593.f236@mx.google.com> User-Agent: mu4e 1.12.1; emacs 29.3 Date: Sat, 01 Jun 2024 14:05:59 +0200 Message-ID: <87mso4lvfc.fsf@k-7.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=185.31.100.96; envelope-from=seb@k-7.ch; helo=k-7.ch X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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 X-Migadu-Queue-Id: C4E261384A X-Migadu-Scanner: mx12.migadu.com X-Migadu-Spam-Score: -6.34 X-Spam-Score: -6.34 X-TUID: Z3yf8KbR6sVn Thank you for your reply, Bruno. I need to have an Org document that could be used as easily as possible by anyone else. Sadly, having to define new Emacs function could be too much for what my school ask. Or I need to make it available publicly as an Emacs package. Bruno Barbier writes: > Hi S=C3=A9bastien, > > > S=C3=A9bastien Gendre writes: > >> TL;DR: How can I use the Org-mode macros as LaTeX macros inside an >> export LaTeX bloc=C2=A0? >> > > It looks like macros are not expanded in latex export blocks, indeed. > > You may define your own filter to ask Org to expand them. > > With the 2 functions below, and this configuration: > > (add-to-list 'org-export-filter-export-block-functions > 'my-latex-filter-export-block) > > > the following org document: > > #+MACRO: orga School Name > > #+begin_export latex > \begin{titlepage} > Some custom LaTeX here > This is my school: {{{orga}}} > \end{titlepage} > \newcommand{\orga}{{{{orga}}}} > #+end_export > > is exported like this: > > \begin{titlepage} > Some custom LaTeX here > This is my school: School Name > \end{titlepage} > \newcommand{\orga}{School Name} > > > Bruno.=20=20=20=20=20 > > > > > (cl-defun my-org-macro-expand-text (text &key templates) > "Expand TEMPLATES in TEXT. > Assume the current-buffer is an org mode buffer. > If TEMPLATES is nil, use 'org-macro-templates'." > (unless templates (setq templates org-macro-templates)) > (with-temp-buffer > (insert text) > (org-mode) > (goto-char (point-min)) > ;; Extracted from 'org-macro-replace-all' > (while (re-search-forward "{{{[-A-Za-z0-9_]" nil t) > (let ((macro (save-excursion > (goto-char (match-beginning 0)) > (org-element-macro-parser))) > value) > (when macro=20 > (let* ((value (org-macro-expand macro templates)) > (begin (org-element-begin macro))) > (delete-region > begin > (progn (goto-char (org-element-end macro)) > (skip-chars-backward " \t") > (point))) > (save-excursion (insert value)))))) > (buffer-substring (point-min) (point-max)))) > > (defun my-latex-filter-export-block (text backend info) > "Replace macros in LaTeX export blocks." > (when (org-export-derived-backend-p backend 'latex) > (my-org-macro-expand-text text))) <#secure method=3Dpgpmime mode=3Dsign>