From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id oFK6L8tCeGJqUQEAbAwnHQ (envelope-from ) for ; Mon, 09 May 2022 00:23:07 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id cMW9L8tCeGKPmwAA9RJhRA (envelope-from ) for ; Mon, 09 May 2022 00:23:07 +0200 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 7C52A38AA0 for ; Mon, 9 May 2022 00:23:07 +0200 (CEST) Received: from localhost ([::1]:56472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nnpIw-0002u8-Ae for larch@yhetil.org; Sun, 08 May 2022 18:23:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51376) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nnpIA-0002tz-4i for emacs-orgmode@gnu.org; Sun, 08 May 2022 18:22:18 -0400 Received: from mout01.posteo.de ([185.67.36.65]:50113) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nnpI8-0002nh-2Z for emacs-orgmode@gnu.org; Sun, 08 May 2022 18:22:17 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id CB9AC240026 for ; Mon, 9 May 2022 00:22:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1652048533; bh=9UhNf61VhKpBPjOzGyhu5mklb9fe8RBvA7Y42Q1b0Eg=; h=From:To:Subject:Date:From; b=ULM7eVtUEd317xUH/nWmcr+UcJvKH1GmbvaGc/A/LVp6pmbp6P3l2Krl7X0xSRwbk N1aLJrwUjMX29ORaHDvHQOZpbFrxv2p76EZnLlGYhQt+5E+IQJhMIhlc052Fk8Qq1Q jXbaE4EaoQomUQMQXm3CYxGeBEKevnXAMyH3WcI7yF2ybQ4AV8RKkWxyLzWc2d1XTm sN2hatkw9RCHkjoSoU4emnApcvBgFsx4imcle5BalUjLpQJfczcPoP0DMldJXCHzaa 8AkNXMxBn7vnrCwV14kLxR05S+KTwB5Pe/yT10lVXbvq4/dvAv9RM7RypUn8inyi81 SUJMyY/yeIkSw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4KxJh51zFPz6tmN for ; Mon, 9 May 2022 00:22:13 +0200 (CEST) From: =?utf-8?Q?Juan_Manuel_Mac=C3=ADas?= To: orgmode Subject: [tip] Insert arbitrary LaTeX code at the beginning of any float environment Date: Sun, 08 May 2022 22:22:16 +0000 Message-ID: <87o807r7fr.fsf@posteo.net> MIME-Version: 1.0 Content-Type: text/plain 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, 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" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1652048587; 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=3OkmeP6J4u6vVTv1l0ZITunrISytl3TWstYVNpE5zEg=; b=XBiH1pV5OC1erDtkDN11c0LxK75liPAfNyTQRMcVNS+fHgXjx0TimhTXr7PJfSz85Uryj/ STey3AZHFVKYUpVoR1KpBM0PAn5rK88t0KpTGW3esAoI/oaCu+JNj1wTjCkYJ5vAkmW3jo rOKPeb+cw1AqrLdPhLzio1GC7UxkmpfP0oEZTTPYPibH8rXuVYcyUo8dld7ftbQS8obc9U TdF19TyP0Wisewi2NIN0ntPyxnw0dZIPZ0fWku+WfTOoDu+WyTNWSdMLiJwQQ1VtWEevv1 b6ooAYBHRe5oTPPWa47zsOAmpGxXVyJpV9959MBDYgYIbX1U/1Nqdl+JBqJ04g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1652048587; a=rsa-sha256; cv=none; b=HPc0xn3xTJxFOuo/PghT4xdLBFf67hJNNOmWUfWIKMLYE/Hh6oXQkOtcHHSM8InW8erkSw osjjC09yEwL5EiQrIBd4tF9uyjpf2LR5zBj7F3a/lP90uLlM9I4qAO+1DCNo8GM3IyaQmh EYsX0J5ANIeI4/h5CcWrcr1X187hujPss6git4bh9QJ4Mib8STRsH/bMITDAoF1cUUQt8k Rp9AGI8nNtwP4NVRh1rGEtJl3wxntcx/9mcn7oAjj6l0fInabPKcBKPfajeM/5OH0goGOb wfvHhP3hitWAFvyD39DFReQ/7JorSvKqltc8tahXr1549RWzKv3ispG+zM/i+w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=ULM7eVtU; dmarc=pass (policy=none) header.from=posteo.net; 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-Spam-Score: -4.01 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=ULM7eVtU; dmarc=pass (policy=none) header.from=posteo.net; 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-Queue-Id: 7C52A38AA0 X-Spam-Score: -4.01 X-Migadu-Scanner: scn0.migadu.com X-TUID: cG7v4IWvCI3+ Hi all, If we want to introduce arbitrary LaTeX code at the very beginning of a float environment, apart from the usual tricks of putting the code in :caption or :placement, this solution I describe here is more from the LaTeX side. I thik its advantages are more control and consistency from the point of view of LaTeX, and the possibility of introducing code of a certain complexity. Well, you have to write some LaTeX code for the preamble, but it's really not much :) We have to define a global command \myenvcode{} (if we want to add the code to all document floats environments), and also a 'Myenvcode' environment, with the same argument. The etoolbox LaTeX package provides a number of hooks: \AtBeginEnvironment, \AtEndEnvironment, etc., but if we want our arbitrary code to be at the very beginning of the environment, it's safer to use the \@floatboxreset hook. So, the code that we would have to add to our preamble would be (I prefer to define the command and environment using the xparse syntax): #+NAME: preamble #+begin_src latex :exports none \usepackage{xparse} \makeatletter \def\my@envcode{} \NewDocumentCommand{\myenvcode}{+m}{% \def\my@envcode{#1}} \g@addto@macro\@floatboxreset{\my@envcode} \makeatother \NewDocumentEnvironment{Myenvcode}{+m}{% \IfNoValueF{#1}{\myenvcode{#1}}} {\par} #+end_src #+begin_src latex :noweb yes :results raw ,#+LaTeX_HEADER: <> #+end_src And here a few examples: #+ATTR_LaTeX: :options {\centering\fbox{Code before a image}\par\vspace{1ex}} #+begin_Myenvcode #+CAPTION: This is a image #+ATTR_LaTeX: :width .5\linewidth :placement [h] [[file:example-image-a.jpg]] #+end_Myenvcode #+ATTR_LaTeX: :options {\captionsetup{font={color=red}}} #+begin_Myenvcode #+CAPTION: This is a image #+ATTR_LaTeX: :width .5\linewidth :placement [h] [[file:example-image-b.jpg]] #+end_Myenvcode #+latex: \myenvcode{{\centering\fbox{Code before a table}\par\vspace{1ex}}} #+CAPTION: This is a table #+ATTR_LaTeX: :placement [h] :booktabs t | a | b | c | d | f | |---+---+---+---+---| | 1 | 2 | 3 | 4 | 5 | #+latex: \myenvcode{} Best regards, Juan Manuel