From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id kEXIJdXPWmYiVAAAqHPOHw:P1 (envelope-from ) for ; Sat, 01 Jun 2024 09:37:57 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id kEXIJdXPWmYiVAAAqHPOHw (envelope-from ) for ; Sat, 01 Jun 2024 09:37:57 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nGi2xoDp; 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"; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1717227476; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=TtkhhIm7mjDRNtI687YC9j9NfNJuOcfz64O8U2/JWgM=; b=oclNsJaNZxoxCjjSRgId7vzLm9YGcdmBQdtDwDefNQBbv0aiaUifCWMktzYKxpet3iCgos oOsRaNPxPkEh3YEuvk+hmniP4nZH482VtBDyrkeBQUBwfxJdNbBouN9m+zxtPE5csOz8+Z fZHzxWpeWJbyOmspyTTznS2HsoY8vaQd1lks9+A01z1S5amb2SCvJs/tiru062tGHnw59W 6jC32hQQbiiN0zrQ7K56Jz/RI1HfpObGmx/CtfSTVpJdtGpp+SOUoo4+76YCjnjemEHXzc EbGn6WhHaCjsyJJClo7VqJzmiHARbXit+aCO9FJrizKuBS3pZccrR3Gd1iQwxw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nGi2xoDp; 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"; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=key1; d=yhetil.org; t=1717227476; a=rsa-sha256; cv=none; b=Nki4NbrVpfiBBiBLz2XVlA+ggv+h5/syi4m3BEDC5iUDux/6/hJ4MQH7npGdITHnQThTtt GggnQ7Ea+m7zLFB6VVH6JWGMpqLWEz4ozZQEcTkhbP+8Il8aXtFC5foYKAwioIOZh5khyz 1cNG9e2a189I31pbb1UayxqLJbwO3ZrICbiKwzem32elAsaNyAnZZ+OnJZ/OjF7jkK5v4k InelNSCUWeVqf4UPg5njHDUnOeaJRUIYSjzuPWzoK0w8YOi/EHv/5Be5aOX8scC8m5bWYb Wc75w42ciFtPSjPwpA2ldKU/iEN/XvLF8MupHyA8h43gQOWikPsiv5K/IIGMig== 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 531AB76FAC for ; Sat, 1 Jun 2024 09:37:56 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sDJID-0002ai-JA; Sat, 01 Jun 2024 03:36:46 -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 1sDJIC-0002aI-0H for emacs-orgmode@gnu.org; Sat, 01 Jun 2024 03:36:44 -0400 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sDJIA-0004JD-5p for emacs-orgmode@gnu.org; Sat, 01 Jun 2024 03:36:43 -0400 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2e724bc466fso31000271fa.3 for ; Sat, 01 Jun 2024 00:36:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717227400; x=1717832200; darn=gnu.org; h=content-transfer-encoding:mime-version:date:references:in-reply-to :subject:to:from:message-id:from:to:cc:subject:date:message-id :reply-to; bh=TtkhhIm7mjDRNtI687YC9j9NfNJuOcfz64O8U2/JWgM=; b=nGi2xoDp4B80ABcYRcRIf5jqDD2Fy3UmCUTLn1+8+eJh3p07rbwQEM0yUw+5w5QWUQ 6i/Y49IZcZDjQvizuMnhw1PAlK2iDhyhgvrr2SdXKh3a+/sI9YUFJT4MqSXMnJd7izhU 9obW/H4qRiOC2rNP/dm75oPHj/vd3tJtgqKgwtL9DW4QZVccOIDoFqQ4xNTNnUhgZp2q wRYDjHVWWAWgfd20Ztp8zyr1iiUxAvCUGZQHJwvwZbjprxkFXDttuo9y2gt11pFTiYDY 5EFm89JtMjThtZjZ8etUBtbguJtw9uyzA0dJMUYKShwCIBDwmtg81Tx8QP+CiOQbv4/r HqNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717227400; x=1717832200; h=content-transfer-encoding:mime-version:date:references:in-reply-to :subject:to:from:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=TtkhhIm7mjDRNtI687YC9j9NfNJuOcfz64O8U2/JWgM=; b=YeEQqCwwsBuGTbRWnB/SDeWx83nSIYVdw0elienVBTfpvhWj3s2uiBOiE4MBkFifSK s9mBfryMSKlrwkZhAchXcg6FEzSha6Ouzljy2k3tpD2+XCpnCoNzto2T9V2+nyyxdXit ghpeJCGeJS+u88kpXpK5sSihoFPinlOM2boDkJ3UxdOLMPg9nilyiBbpFxX8S1nSZXvT CNU/IUlr5pO5qd9yZSaF5tD1vS59I1HRooisriJi8syvrB94t/JZcdltrJlXxn8gFJJA YNVthW8iqIthvnLnC2CZUcxvYgnyErQlRcZlXdO/L2JC7tHBEK5/jSpdXqM2NBsE5TU9 VfyA== X-Forwarded-Encrypted: i=1; AJvYcCVfrAv0Ju4lhLTQvtC7gQ5eszd6X43uEWQ7OvvkuUhIsZSN7/cg5XpbrGT4ubm1uuuRZfGuW59CKahoqwhRsu5qx90uWYo= X-Gm-Message-State: AOJu0Yz14jT5XcZPSSU5XCet5aKHaO5YCjHlwrm7461iXy+y2SMHd55+ NUh14qkC+WNzUsjzI2rD7jH0kB4n1m6S2m5UK4DYmUfXK7Y4WMBkuHqX8w== X-Google-Smtp-Source: AGHT+IE6QwzBer5KEQziiejC1N7a+Xu3+CiSoprSXO8RxHS74HaJwwD1KdVFvvR8rctMIQotQv2laA== X-Received: by 2002:ac2:4d8b:0:b0:524:34ad:ba7d with SMTP id 2adb3069b0e04-52b896bde57mr3116212e87.42.1717227399946; Sat, 01 Jun 2024 00:36:39 -0700 (PDT) Received: from keynux.home.arpa. ([2a01:e0a:505:3460:1c18:688d:ece4:372e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-421270aeb18sm76663845e9.48.2024.06.01.00.36.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jun 2024 00:36:39 -0700 (PDT) Message-ID: <665acf87.050a0220.dc593.f236@mx.google.com> Received: by keynux.home.arpa. (sSMTP sendmail emulation); Sat, 01 Jun 2024 09:36:38 +0200 From: Bruno Barbier To: =?utf-8?Q?S=C3=A9bastien?= Gendre , emacs-orgmode Subject: Re: Using Org-mode macros as LaTeX macros In-Reply-To: <87v82tkyc2.fsf@k-7.ch> References: <87v82tkyc2.fsf@k-7.ch> Date: Sat, 01 Jun 2024 09:36:37 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2a00:1450:4864:20::22c; envelope-from=brubar.cs@gmail.com; helo=mail-lj1-x22c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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-Spam-Score: -8.17 X-Migadu-Queue-Id: 531AB76FAC X-Migadu-Scanner: mx10.migadu.com X-Migadu-Spam-Score: -8.17 X-TUID: GiDXFTSjHdta 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)))